You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
3.0 KiB

  1. ##
  2. ## Template makefile for Standard, Profile, Debug, Release, and Release-static versions
  3. ##
  4. ## eg: "make rs" for a statically linked release version.
  5. ## "make d" for a debug version (no optimizations).
  6. ## "make" for the standard version (optimized, but with debug information and assertions active)
  7. PWD = $(shell pwd)
  8. EXEC ?= $(notdir $(PWD))
  9. CSRCS = $(wildcard $(PWD)/*.cc)
  10. DSRCS = $(foreach dir, $(DEPDIR), $(filter-out $(MROOT)/$(dir)/Main.cc, $(wildcard $(MROOT)/$(dir)/*.cc)))
  11. CHDRS = $(wildcard $(PWD)/*.h)
  12. COBJS = $(CSRCS:.cc=.o) $(DSRCS:.cc=.o)
  13. PCOBJS = $(addsuffix p, $(COBJS))
  14. DCOBJS = $(addsuffix d, $(COBJS))
  15. RCOBJS = $(addsuffix r, $(COBJS))
  16. CXX ?= g++
  17. CFLAGS ?= -Wall -Wno-parentheses
  18. LFLAGS ?= -Wall
  19. COPTIMIZE ?= -O3
  20. CFLAGS += -I$(MROOT) -D __STDC_LIMIT_MACROS -D __STDC_FORMAT_MACROS
  21. LFLAGS += -lz
  22. .PHONY : s p d r rs clean
  23. s: $(EXEC)
  24. p: $(EXEC)_profile
  25. d: $(EXEC)_debug
  26. r: $(EXEC)_release
  27. rs: $(EXEC)_static
  28. libs: lib$(LIB)_standard.a
  29. libp: lib$(LIB)_profile.a
  30. libd: lib$(LIB)_debug.a
  31. libr: lib$(LIB)_release.a
  32. ## Compile options
  33. %.o: CFLAGS +=$(COPTIMIZE) -g -D DEBUG
  34. %.op: CFLAGS +=$(COPTIMIZE) -pg -g -D NDEBUG
  35. %.od: CFLAGS +=-O0 -g -D DEBUG
  36. %.or: CFLAGS +=$(COPTIMIZE) -g -D NDEBUG
  37. ## Link options
  38. $(EXEC): LFLAGS += -g
  39. $(EXEC)_profile: LFLAGS += -g -pg
  40. $(EXEC)_debug: LFLAGS += -g
  41. #$(EXEC)_release: LFLAGS += ...
  42. $(EXEC)_static: LFLAGS += --static
  43. ## Dependencies
  44. $(EXEC): $(COBJS)
  45. $(EXEC)_profile: $(PCOBJS)
  46. $(EXEC)_debug: $(DCOBJS)
  47. $(EXEC)_release: $(RCOBJS)
  48. $(EXEC)_static: $(RCOBJS)
  49. lib$(LIB)_standard.a: $(filter-out */Main.o, $(COBJS))
  50. lib$(LIB)_profile.a: $(filter-out */Main.op, $(PCOBJS))
  51. lib$(LIB)_debug.a: $(filter-out */Main.od, $(DCOBJS))
  52. lib$(LIB)_release.a: $(filter-out */Main.or, $(RCOBJS))
  53. ## Build rule
  54. %.o %.op %.od %.or: %.cc
  55. @echo Compiling: $(subst $(MROOT)/,,$@)
  56. @$(CXX) $(CFLAGS) -c -o $@ $<
  57. ## Linking rules (standard/profile/debug/release)
  58. $(EXEC) $(EXEC)_profile $(EXEC)_debug $(EXEC)_release $(EXEC)_static:
  59. @echo Linking: "$@ ( $(foreach f,$^,$(subst $(MROOT)/,,$f)) )"
  60. @$(CXX) $^ $(LFLAGS) -o $@
  61. ## Library rules (standard/profile/debug/release)
  62. lib$(LIB)_standard.a lib$(LIB)_profile.a lib$(LIB)_release.a lib$(LIB)_debug.a:
  63. @echo Making library: "$@ ( $(foreach f,$^,$(subst $(MROOT)/,,$f)) )"
  64. @$(AR) -rcsv $@ $^
  65. ## Library Soft Link rule:
  66. libs libp libd libr:
  67. @echo "Making Soft Link: $^ -> lib$(LIB).a"
  68. @ln -sf $^ lib$(LIB).a
  69. ## Clean rule
  70. clean:
  71. @rm -f $(EXEC) $(EXEC)_profile $(EXEC)_debug $(EXEC)_release $(EXEC)_static \
  72. $(COBJS) $(PCOBJS) $(DCOBJS) $(RCOBJS) *.core depend.mk
  73. ## Make dependencies
  74. depend.mk: $(CSRCS) $(CHDRS)
  75. @echo Making dependencies
  76. @$(CXX) $(CFLAGS) -I$(MROOT) \
  77. $(CSRCS) -MM | sed 's|\(.*\):|$(PWD)/\1 $(PWD)/\1r $(PWD)/\1d $(PWD)/\1p:|' > depend.mk
  78. @for dir in $(DEPDIR); do \
  79. if [ -r $(MROOT)/$${dir}/depend.mk ]; then \
  80. echo Depends on: $${dir}; \
  81. cat $(MROOT)/$${dir}/depend.mk >> depend.mk; \
  82. fi; \
  83. done
  84. -include $(MROOT)/mtl/config.mk
  85. -include depend.mk