-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_Makefile.py
141 lines (113 loc) · 5.25 KB
/
create_Makefile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import os
import argparse
parser = argparse.ArgumentParser(
description="Create A Makefile for your c++ program to easy compile your source code")
def setParser():
parser.add_argument(
"-path", default=os.path.dirname(os.path.abspath(__file__))+"/")
parser.add_argument(
"-src", default=os.path.dirname(os.path.abspath(__file__))+"/src/")
parser.add_argument(
"-include", default=os.path.dirname(os.path.abspath(__file__))+"/include/")
parser.add_argument("-filename", default="main")
parser.add_argument("-i", nargs="+", default=["include/"]) # include path
parser.add_argument("-flags", nargs="+",
default=["-Wall", "-pthread"]) # add flags
parser.add_argument("-d", action='count') # debug mode
parser.add_argument("-wx", action='count'
) # wxWidgets compiler
parser.add_argument("-opengl", action='count'
) # openGL glad glfw glm
parser.add_argument("-pch", action="count") # Enable precompiled header
setParser()
src = vars(parser.parse_args()).get("src")
path = vars(parser.parse_args()).get("path")
include = vars(parser.parse_args()).get("include")
filepath = []
whitelistFormat = [".cpp", ".hpp", ".c", ".h"]
for (dirname, subdirname, filenames) in os.walk(path):
for name in filenames:
if(any(substring in name for substring in whitelistFormat) and name.find("pch") == -1):
if(dirname[len(dirname) - 1] == "/"):
filepath.append((dirname + name).replace(path, ""))
else:
filepath.append((dirname + "/" + name).replace(path, ""))
namefile = vars(parser.parse_args()).get("filename")
def writeVariable(vFile):
f.write("TARGET=" +
namefile + "\n" + "INCLUDE_DIR= ")
f.write("-I./ ")
f.write("-I./usr/include/ ")
for dir in vars(parser.parse_args()).get("i"):
f.write("-I" + dir + " ")
if(vars(parser.parse_args()).get("wx") != None):
f.write("-I/usr/include/wx-3.0/")
if(vars(parser.parse_args()).get("opengl") != None):
f.write(
" -I/usr/include/glad/ -I/usr/include/glm/ -I/usr/local/include/GLFW/")
f.write("\nSRC_DIR = -Isrc/")
f.write("\n")
f.write("FLAGS= ")
for flags in vars(parser.parse_args()).get("flags"):
f.write(flags + " ")
if(vars(parser.parse_args()).get("pch") != None):
f.write(" -include pch.h ")
if(vars(parser.parse_args()).get("d") != None):
f.write("-ggdb -g3 ")
f.write("-D DEBUG ")
else:
f.write("-O3 ")
if(vars(parser.parse_args()).get("wx") != None):
f.write("`wx-config --cxxflags --libs` ")
if(vars(parser.parse_args()).get("opengl") != None):
f.write("-ldl `pkg-config --static --libs x11 xrandr xi xxf86vm glfw3` -lpng")
f.write("\nLINKER= " + " \n")
f.write("OBJECTS= ")
for filename in filepath:
index = filename.rfind("/")
indexpoint = filename.rfind(".")
if(any(substring in filename for substring in [".cpp", ".c"])):
if(index != - 1):
f.write("$(OBJECT_DIR)"+filename[index + 1: indexpoint] + ".o ")
else:
f.write(filename[:indexpoint] + ".o ")
if(vars(parser.parse_args()).get("opengl") != None):
f.write("$(OBJECT_DIR)glad.o")
f.write("\nFILE_SRC= ")
for filename in filepath:
if(any(substring in filename for substring in [".cpp", ".c"])):
index = filename.rfind("/")
f.write(filename[index + 1:] + " ")
f.write("\nFILE_INCLUDE= ")
for filename in filepath:
if(any(substring in filename for substring in [".hpp", ".h"])):
index = filename.rfind("/")
f.write(filename[index + 1:] + " ")
f.write("\n")
f.write("BUILD_DIR= build/\n" )
f.write("OBJECT_DIR= build/object/" + "\n\n\n")
def writeCompiler(vFile):
f.write("default : $(BUILD_DIR)$(TARGET)\n")
f.write("$(BUILD_DIR)$(TARGET) : $(OBJECTS)" + " \n")
f.write("\tg++ $(OBJECTS) $(FLAGS) $(LINKER) -o $(BUILD_DIR)$(TARGET)" + "\n\n")
if(vars(parser.parse_args()).get("opengl") != None):
f.write("$(OBJECT_DIR)glad.o: /usr/local/src/glad.c \n\tg++ $(FLAGS) $(SRC_DIR) $(INCLUDE_DIR) -c /usr/local/src/glad.c -o $(OBJECT_DIR)glad.o\n\n")
if(vars(parser.parse_args()).get("pch") != None):
f.write("pch.h.gch : pch.h \n\t g++ -c pch.h $(FLAGS) -o pch.h.gch \n\n")
f.write("$(FILE_SRC) $(FILE_INCLUDE): pch.h.gch \n\n\n")
for filename in filepath:
if(not any(substring in filename for substring in [".hpp", ".h"])):
index = filename.rfind(".")
indexf = filename.rfind("/")
if(indexf != -1):
f.write("$(OBJECT_DIR)"+(filename[indexf + 1:index] + ".o").replace("src/", "") +
": " + filename + "\n")
else:
f.write("$(OBJECT_DIR)"+(filename[:index] + ".o").replace("src/", "") +
": " + filename + "\n")
f.write("\tg++ $(FLAGS) $(SRC_DIR) $(INCLUDE_DIR) -c " +
filename + " -o $(OBJECT_DIR)" + (filename[indexf+1:index] + ".o") + "\n\n")
f.write("clean : \n\t rm -f $(OBJECT_DIR)*.o")
with open("Makefile", "w+") as f:
writeVariable(f)
writeCompiler(f)