makefile 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #
  2. # CONFIGURATION GENERALE
  3. #
  4. EXEC = mysh
  5. OBJETS = str.o parser.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 = $(CCFLAGS_STD)
  23. CCLIBS =
  24. #
  25. # REGLES
  26. #
  27. all: msg $(OBJETS) $(EXEC_O)
  28. @echo "Creation des executables..."
  29. @for i in $(EXEC); do \
  30. $(CC) -o $$i $$i.o $(OBJETS) $(CCLIBS); \
  31. done
  32. @echo "Termine."
  33. msg:
  34. @echo "Creation des objets..."
  35. debug: CCFLAGS = $(CCFLAGS_STD) $(CCFLAGS_DEBUG)
  36. debug: all
  37. #
  38. # REGLES PAR DEFAUT
  39. #
  40. .c.o: .h
  41. @cd $(dir $<) && ${CC} ${CCFLAGS} -c $(notdir $<) -o $(notdir $@)
  42. #
  43. # REGLES GENERALES
  44. #
  45. clean:
  46. @echo "Suppresion des objets, des fichiers temporaires..."
  47. @rm -f $(OBJETS) $(EXEC_O)
  48. @rm -f *~ *#
  49. @rm -f $(EXEC)
  50. @rm -f dependances
  51. @echo "Termine."
  52. depend:
  53. @echo "Creation des dependances..."
  54. @sed -e "/^# DEPENDANCES/,$$ d" makefile > dependances
  55. @echo "# DEPENDANCES" >> dependances
  56. @for i in $(OBJETS_O); do \
  57. $(CC) -MM -MT $$i $(CCFLAGS) `echo $$i | sed "s/\(.*\)\\.o$$/\1.c/"` >> dependances; \
  58. done
  59. @cat dependances > makefile
  60. @rm dependances
  61. @echo "Termine."
  62. #
  63. # CREATION ARCHIVE
  64. #
  65. ARCHIVE_FILES = *
  66. archive: clean
  67. @echo "Creation de l'archive $(NOM_PROJET)$(shell date '+%y%m%d.tar.gz')..."
  68. @REP=`basename "$$PWD"`; cd .. && tar zcf $(NOM_PROJET)$(shell date '+%y%m%d.tar.gz') $(addprefix "$$REP"/,$(ARCHIVE_FILES))
  69. @echo "Termine."
  70. # DEPENDANCES
  71. str.o: str.c str.h
  72. parser.o: parser.c parser.h constante.h str.h
  73. mysh.o: mysh.c parser.h constante.h str.h mysh.h