import os, re sources = [] headers = [] make1="\ #------------------------------------------------------\n\ # ClusterWize regression\n\ #------------------------------------------------------\n\ SRCS=" make2="\n\ OBJS=$(patsubst %.cpp, %.o, $(SRCS))\n\ EXEC=cluster.exe\n\ #------------------------------------------------------\n\ #Compilateur et option\n\ CC=g++\n\ AR=ar\n\ CFLAGS=-Wall -pedantic -Os -std=c++98 -g\n\ LFLAGS= -lm\n\ #------------------------------------------------------\n\ #------------------------------------------------------\n\ %.o : %.cpp\n\ $(CC) -c $(CFLAGS) $*.cpp -o $@\n\ \n\ $(EXEC) : $(OBJS)\n\ $(CC) -o $(EXEC) -g $(OBJS) $(LFLAGS)\n\ \n\ clean:\n\ rm -f $(OBJS) $(EXEC)\n" def get_files(dirname, st): # listes les .cpp et .h global headers, sources all = {}; all = [f for f in os.listdir(dirname) if os.path.isfile(os.path.join(dirname, f)) or os.path.isdir(os.path.join(dirname, f))] # print all # construire l'expression reguliere permettant d'avoir les .cpp et .h cpp = re.compile("(.+).cpp$") h = re.compile("(.+).h$|(.+).cxx$") for f in all: if cpp.match(f,re.IGNORECASE): if not f == "main.cpp": sources.append(dirname + '/' + f) else: if st: sources.append(f) elif h.match(f,re.IGNORECASE): headers.append(dirname + '/' + f) elif os.path.isdir(f): get_files(f, False) dirname = os.getcwd() get_files(dirname, True) print sources print headers # write makefile makefile = open("Makefile", "w") makefile.write(make1) for s in sources: makefile.write(s + " ") makefile.write("\n") makefile.write(make2) makefile.close()