Makefile 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. ###############################################
  2. #!file Makefile
  3. #!author TooOld2Rock'nRoll (toooldtorock-n-roll@riseup.net)
  4. #!date 2022
  5. #!remark Last modified in 2023/oct
  6. #!brief Makefile for the Arcade Fighter Demo.
  7. #!see - Mecklenburg, R. - 2009 - Managing Projects with GNU Make (Nutshell Handbooks)
  8. ###############################################
  9. SHELL := /bin/bash # Use bash syntax
  10. #executable name will only be set if not yet thru the command line
  11. name ?= arcade_fighter_demo
  12. #the project structure
  13. srcdir := src
  14. incdir := inc
  15. objdir := .obj
  16. create_dirs := $(objdir)
  17. #local library
  18. afdir := lib/ArcadeFighter
  19. aflib := -lArcadeFighter
  20. #flags for the compiler
  21. override CFLAGS += -g -Wall -pthread -MP -MD
  22. override CXXFLAGS += $(CFLAGS)
  23. #where to look for header files
  24. CPPFLAGS := -I$(incdir) -I$(afdir)/inc
  25. #where to look for pre compiled libraries
  26. LDFLAGS := -L$(afdir)
  27. #list of libraries to link, -ldl should be the last one...
  28. LDLIBS := $(aflib) -lfmt -lSDL2 -lSDL2_mixer -lGL -ldl
  29. #********************************
  30. #list all source files
  31. vpath %.c $(srcdir)
  32. vpath %.cpp $(srcdir)
  33. c_files := $(wildcard $(srcdir)/*.c)
  34. cpp_files := $(wildcard $(srcdir)/*.cpp)
  35. #change path of .o files to the objdir target.
  36. c_objs := $(patsubst $(srcdir)/%.c,$(objdir)/%.o,$(c_files))
  37. cpp_objs := $(patsubst $(srcdir)/%.cpp,$(objdir)/%.o,$(cpp_files))
  38. #create necessary directories if not created yet
  39. create-output-directories := \
  40. $(shell for d in $(create_dirs); \
  41. do [[ -d $$d ]] || mkdir -p $$d; \
  42. done)
  43. #if you need to debug something....
  44. #$(info SRC_LIST: $(c_files) $(cpp_files))
  45. #$(info OBJ_LIST: $(c_objs) $(cpp_objs))
  46. #*******************************
  47. #********build targets**********
  48. #*******************************
  49. .PHONY: all mem_profiling clean $(afdir)
  50. # help - The default goal
  51. #TODO make a proper help!!!
  52. #.DEFAULT:
  53. #@$(MAKE) --print-data-base --question no-such-target /
  54. #$(GREP) -v -e '^no-such-target' -e '^makefile' /
  55. #$(AWK) '/^[^.%][-A-Za-z0-9_]*: { print substr($$1, 1, length($$1)-1) }' /
  56. #$(SORT) /
  57. #$(PR) --omit-pagination --width=80 --columns=4
  58. all: $(name)
  59. #change flags depending on target!
  60. mem_profiling: RULE_FORWARD := mem_profiling
  61. mem_profiling: CFLAGS += -fsanitize=address -fno-omit-frame-pointer
  62. #mem_profiling: LDLIBS +=
  63. mem_profiling: all
  64. $(name): $(afdir) $(c_objs) $(cpp_objs)
  65. $(LINK.cpp) -o $@ $(c_objs) $(cpp_objs) $(LDLIBS)
  66. #make .o into .d files and set as dependency (to recompile on header files changes)
  67. #clean does not need to generate a list of dependencies!
  68. ifneq "$(MAKECMDGOALS)" "clean"
  69. -include $(c_objs:.o=.d) $(cpp_objs:.o=.d)
  70. endif
  71. #compile .c files
  72. $(c_objs): $(create_dirs)
  73. $(COMPILE.c) $(OUTPUT_OPTION) $(patsubst $(objdir)/%.o,$(srcdir)/%.c,$@)
  74. #compile .cpp files
  75. $(cpp_objs): $(create_dirs)
  76. $(COMPILE.cc) $(OUTPUT_OPTION) $(patsubst $(objdir)/%.o,$(srcdir)/%.cpp,$@)
  77. #compile the ArcadeFighter lib
  78. $(afdir):
  79. $(MAKE) --directory=$(afdir) $(MAKEFLAGS) $(RULE_FORWARD)
  80. #remove all files generated by make
  81. clean:
  82. $(MAKE) --directory=$(afdir) clean
  83. rm -rf $(objdir)/*
  84. rm -f $(name)