makefile 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #
  2. # CONFIGURATION GENERALE
  3. #
  4. EXEC = mysh
  5. OBJETS = error.o str.o parser.o wildcard.o command.o execute.o sem.o shm.o subdiv.o ipc.o expreg.o variable.o
  6. NOM_PROJET = mini-shell
  7. #
  8. # SUFFIXES
  9. #
  10. .SUFFIXES: .c .o
  11. #
  12. # OBJETS
  13. #
  14. EXEC_O = $(EXEC:=.o)
  15. OBJETS_O = $(OBJETS) $(EXEC_O)
  16. #
  17. # ARGUMENTS ET COMPILATEUR
  18. #
  19. CC = gcc
  20. CCFLAGS_STD = -Wall -O3 -Werror -ansi -pedantic -std=c11
  21. CCFLAGS_DEBUG = -D _DEBUG_
  22. CCFLAGS_VALGRIND = -Wall -O0 -ansi -pedantic -std=c11 -g
  23. CCFLAGS = $(CCFLAGS_STD)
  24. CCLIBS =
  25. #
  26. # REGLES
  27. #
  28. all: msg $(OBJETS) $(EXEC_O)
  29. @echo "Creation des executables..."
  30. @for i in $(EXEC); do \
  31. $(CC) -o $$i $$i.o $(OBJETS) $(CCLIBS); \
  32. done
  33. @echo "Termine."
  34. msg:
  35. @echo "Creation des objets..."
  36. debug: CCFLAGS = $(CCFLAGS_STD) $(CCFLAGS_DEBUG)
  37. debug: all
  38. valgrind: CCFLAGS = $(CCFLAGS_VALGRIND)
  39. valgrind: all
  40. #
  41. # REGLES PAR DEFAUT
  42. #
  43. .c.o: .h
  44. @cd $(dir $<) && ${CC} ${CCFLAGS} -c $(notdir $<) -o $(notdir $@)
  45. #
  46. # REGLES GENERALES
  47. #
  48. clean:
  49. @echo "Suppresion des objets, des fichiers temporaires..."
  50. @rm -f $(OBJETS) $(EXEC_O)
  51. @rm -f *~ *#
  52. @rm -f $(EXEC)
  53. @rm -f dependances
  54. @rm -f *.log
  55. @echo "Termine."
  56. depend:
  57. @echo "Creation des dependances..."
  58. @sed -e "/^# DEPENDANCES/,$$ d" makefile > dependances
  59. @echo "# DEPENDANCES" >> dependances
  60. @for i in $(OBJETS_O); do \
  61. $(CC) -MM -MT $$i $(CCFLAGS) `echo $$i | sed "s/\(.*\)\\.o$$/\1.c/"` >> dependances; \
  62. done
  63. @cat dependances > makefile
  64. @rm dependances
  65. @echo "Termine."
  66. rm-log:
  67. @echo "Suppression log..."
  68. @rm -f *.log
  69. @echo "Termine."
  70. #
  71. # CREATION ARCHIVE
  72. #
  73. ARCHIVE_FILES = *
  74. archive: clean
  75. @echo "Creation de l'archive $(NOM_PROJET)$(shell date '+%y%m%d.tar.gz')..."
  76. @REP=`basename "$$PWD"`; cd .. && tar zcf $(NOM_PROJET)$(shell date '+%y%m%d.tar.gz') $(addprefix "$$REP"/,$(ARCHIVE_FILES))
  77. @echo "Termine."
  78. # DEPENDANCES
  79. error.o: error.c str.h error.h
  80. str.o: str.c str.h
  81. parser.o: parser.c error.h str.h wildcard.h constante.h ipc.h sem.h shm.h \
  82. subdiv.h variable.h parser.h
  83. wildcard.o: wildcard.c error.h wildcard.h constante.h
  84. command.o: command.c error.h str.h parser.h constante.h execute.h ipc.h \
  85. sem.h shm.h subdiv.h variable.h command.h mysh.h
  86. execute.o: execute.c error.h execute.h constante.h
  87. sem.o: sem.c error.h sem.h constante.h
  88. shm.o: shm.c error.h shm.h constante.h
  89. subdiv.o: subdiv.c subdiv.h constante.h
  90. ipc.o: ipc.c ipc.h constante.h sem.h shm.h subdiv.h variable.h
  91. expreg.o: expreg.c expreg.h constante.h
  92. variable.o: variable.c str.h expreg.h constante.h variable.h subdiv.h
  93. mysh.o: mysh.c error.h str.h parser.h constante.h command.h execute.h \
  94. ipc.h sem.h shm.h subdiv.h mysh.h