-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaker
executable file
·50 lines (49 loc) · 2.06 KB
/
maker
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
#!/usr/bin/python3.6
import os
import re
import sys
import glob
import pwd
import time
import getpass
def maker():
if len(sys.argv) != 2:
print("maker [NOM DU BINAIRE]")
exit
path_file = []
for dossier, sous_dossiers, fichiers in os.walk("."):
for fichier in fichiers:
if fichier.endswith(".c"):
path_file.append(os.path.join(dossier, fichier))
makefile = open("Makefile", "w")
makefile.write("NAME\t= " + sys.argv[1] + "\n\nCC\t= gcc\n\nRM\t= rm -rf\n")
makefile.write("\nTODO\t= -@fgrep --color --exclude=.git --exclude=*.o")
makefile.write(" --exclude=Makefile --exclude=tags --exclude=cscope*")
makefile.write("-H -e TODO -e FIXME -r $(CURDIR) || true\n\n")
makefile.write("SRCS = ")
for i in path_file:
if i.startswith('./src'):
makefile.write('\t'+ i[2:] + "\t\\\n")
makefile.write("\n\nLIBS = ")
for i in path_file:
if i.startswith('./lib'):
makefile.write('\t'+ i[2:] + "\t\\\n")
makefile.write("\nOBJS = $(SRCS:.c=.o)\n\nOBJ_LIBS = $(LIBS:.c=.o\n\n")
makefile.write("CFLAGS = -I./include/\nCFLAGS += -W -Wall -Wextra")
makefile.write("\nLDLIBS = -Llib/my -lmy\n\nall: $(NAME)\n\n")
makefile.write("$(NAME): $(OBJS) $(LIBS)\n\t")
makefile.write("@ar rc lib/my/libmy.a $(LIBS)\n\t")
makefile.write("@$(CC) $(CFLAGS) -o $(NAME) $(OBJS) $(LDLIBS)\n\t@$(TODO)")
#color
makefile.write("\n\nclean:\n\t@#@echo \"clean OK\"\n\t")
makefile.write("@echo -e \"\e[1;46m clean OK \e[0m\"\n\t")
makefile.write("@$(RM) $(OBJS)\n\t@$(RM) $(LIBS)\n\t@$(RM) ./libmy.a")
#color
makefile.write("\n\fclean:\n\t@#@echo \"fclean OK\"\n\t")
makefile.write("@echo -e \"\e[1;46m fclean OK \e[0m\"\n\t")
makefile.write("@$(RM) $(OBJS)\n\t@$(RM) $(LIBS)\n\t@$(RM) $(NAME)\n\t@$(RM) ./libmy.a")
makefile.write("\n\nre: fclean all\n\n%.o: %.c\n\t@gcc -c -o $@ $(CFLAGS) $<\n\t")
makefile.write("@echo -e \"[\e[0;32m OK \e[0m] built '$@'\"")
makefile.write("\n\n.PHONY: all clean fclean re")
makefile.close()
maker()