-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaker
More file actions
executable file
·113 lines (97 loc) · 3.13 KB
/
Maker
File metadata and controls
executable file
·113 lines (97 loc) · 3.13 KB
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
#!/bin/python3
import os
title = input("create program name : ")
dic = input("work directory :")
if dic == "" :
dic = "./"
is_bonus = input("there bonus? [y/N] : ")
if is_bonus == "Y" or is_bonus == "y" :
is_bonus = 1
else :
is_bonus = 0
link_flags = input("LFLAGS : ")
include = input("INCLUDE : ")
tab = '\t'
src_list = []
mandatory_list = []
bonus_list = []
files = os.listdir(dic)
# files = os.listdir("./")
for file in files :
# if os.path.isdir(file) and file != ".git" and file != ".vscode" and file != "build" :
# print(file)
if ".c" in file :
src_list.append(file)
if ".c" in file and "bonus" not in file :
mandatory_list.append(file)
elif ".c" in file and "bonus" in file :
bonus_list.append(file)
max_length = max(len(file) for file in src_list)
max_length = max_length + 4 - max_length % 4
makefile = open(f"{dic}/Makefile", "w")
makefile.write("CC = cc\n")
makefile.write("CFLAGS = -Wall -Wextra -Werror\n")
makefile.write(f"LFLAGS = {link_flags}\n")
makefile.write(f"INCLUDE = {include}\n")
makefile.write(f"NAME = {title}\n\n")
makefile.write("MANDATORY_SRCS = \\\n")
for i, src in enumerate(mandatory_list) :
needtap = int((max_length - len(src) + len(src) % 4) / 4)
makefile.write(f"\t{src}{tab * needtap}")
if (i == len(mandatory_list) - 1) :
makefile.write("\n\n")
else :
makefile.write("\\\n")
if is_bonus :
makefile.write("BONUS_SRCS = \\\n")
for i, src in enumerate(bonus_list) :
needtap = int((max_length - len(src) + len(src) % 4) / 4)
makefile.write(f"\t{src}{tab * needtap}")
if (i == len(bonus_list) - 1) :
makefile.write("\n\n")
else :
makefile.write("\\\n")
makefile.write("MANDATORY_OBJS = $(patsubst %.c,%.o,$(MANDATORY_SRCS))\n")
if is_bonus :
makefile.write("BONUS_OBJS = $(patsubst %.c,%.o,$(BONUS_SRCS))\n")
makefile.write("\n")
if is_bonus :
makefile.write("ifdef WITH_BONUS\n")
makefile.write("\tSRCS = $(BONUS_SRCS)\n")
makefile.write("\tOBJS = $(BONUS_OBJS)\t\n")
makefile.write("else\n")
makefile.write("\tSRCS = $(MANDATORY_SRCS)\n")
makefile.write("\tOBJS = $(MANDATORY_OBJS)\n")
makefile.write("endif\n\n")
else :
makefile.write("SRCS = $(MANDATORY_SRCS)\n")
makefile.write("OBJS = $(MANDATORY_OBJS)\n")
makefile.write("\n")
makefile.write("all : $(NAME)\n")
makefile.write("\n")
if is_bonus :
makefile.write("bonus:\n")
makefile.write("\tmake WITH_BONUS=1 all\n")
makefile.write("\n")
makefile.write("$(NAME) : $(OBJS)\n")
makefile.write("\t$(CC) $(CFLAGS) $(OBJS) $(LFLAGS) $(INCLUDE) -o $(NAME)\n")
makefile.write("\n")
makefile.write("%.o : %.c\n")
makefile.write("\t$(CC) $(CFLAGS) -c $(INCLUDE) $< -o $@\n")
makefile.write("\n")
makefile.write("clean:\n")
makefile.write(f"\trm -rf {'$(BONUS_OBJS)' if is_bonus else ''} $(MANDATORY_OBJS)\n")
makefile.write("\n")
makefile.write("fclean: clean\n")
makefile.write("\trm -rf $(NAME)\n")
makefile.write("\n")
makefile.write("re:\n")
makefile.write("\t@make fclean\n")
makefile.write("\t@make all\n")
if is_bonus :
makefile.write("\n")
makefile.write("re_bonus :\n")
makefile.write("\t@make fclean\n")
makefile.write("\t@make bonus\n")
makefile.write("\n")
makefile.write(f".PHONY: all {'bonus re_bonus' if is_bonus else ''}clean fclean re\n")