annotate Makefile.gen @ 100:8059aad101d1

Improve build system.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 25 Feb 2022 15:29:13 +0200
parents 22774e3f2a89
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
77
cc1c35357e39 Build system cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
1 ###
cc1c35357e39 Build system cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
2 ### Compiler flags
cc1c35357e39 Build system cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
3 ###
86
cc7fcaf139ef Add ASAN build flag.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
4 ifneq ($(ASAN),)
cc7fcaf139ef Add ASAN build flag.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
5 CXXFLAGS += -fsanitize=address
cc7fcaf139ef Add ASAN build flag.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
6 LDFLAGS += -lasan
cc7fcaf139ef Add ASAN build flag.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
7 else
99
22774e3f2a89 Add TSAN compile-time support via make parameter TSAN.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
8 ifneq ($(TSAN),)
22774e3f2a89 Add TSAN compile-time support via make parameter TSAN.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
9 CXXFLAGS += -fsanitize=thread
22774e3f2a89 Add TSAN compile-time support via make parameter TSAN.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
10 LDFLAGS += -ltsan
22774e3f2a89 Add TSAN compile-time support via make parameter TSAN.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
11 else
86
cc7fcaf139ef Add ASAN build flag.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
12 CXXFLAGS += -O3
42
3c7e1d3fa5a2 Implement OpengL extension handling through new header file dmglexts.h to
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
13 LDFLAGS +=
86
cc7fcaf139ef Add ASAN build flag.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
14 endif
99
22774e3f2a89 Add TSAN compile-time support via make parameter TSAN.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
15 endif
86
cc7fcaf139ef Add ASAN build flag.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
16
cc7fcaf139ef Add ASAN build flag.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
17 CXXFLAGS += -g -W -Wall -std=c++11
40
6905d02bca2d Build system improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
18 CXXFLAGS += $(SDL_CFLAGS) $(GL_CFLAGS)
6905d02bca2d Build system improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
19
77
cc1c35357e39 Build system cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
20
cc1c35357e39 Build system cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
21 ###
cc1c35357e39 Build system cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
22 ### Tools, paths and directories
cc1c35357e39 Build system cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
23 ###
40
6905d02bca2d Build system improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
24 MKDIR ?= mkdir
6905d02bca2d Build system improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
25 MKDIR_P ?= $(MKDIR) -p
6905d02bca2d Build system improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
26 BINPATH ?= ./
34
c0b85b0615d2 Improve the makefiles.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27
c0b85b0615d2 Improve the makefiles.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28
77
cc1c35357e39 Build system cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
29 ###
cc1c35357e39 Build system cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
30 ### Main targets and objects
cc1c35357e39 Build system cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
31 ###
41
eaa3e8575c12 Build system cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
32 BINARIES = gldragon ply2bin
eaa3e8575c12 Build system cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
33
eaa3e8575c12 Build system cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
34 TARGETS += \
eaa3e8575c12 Build system cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
35 $(addprefix $(BINPATH),$(addsuffix $(BINEXT),$(BINARIES)))
eaa3e8575c12 Build system cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
36
eaa3e8575c12 Build system cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
37 NOBUILD_TARGETS +=
eaa3e8575c12 Build system cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
38 NOINST_TARGETS +=
eaa3e8575c12 Build system cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
39 CLEAN_TARGETS +=
eaa3e8575c12 Build system cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
40 DISTCLEAN_TARGETS +=
eaa3e8575c12 Build system cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
41
34
c0b85b0615d2 Improve the makefiles.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42
40
6905d02bca2d Build system improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
43 ###
77
cc1c35357e39 Build system cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
44 ### Functions and compilation/link commands
cc1c35357e39 Build system cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
45 ###
cc1c35357e39 Build system cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
46 ifneq ($(V),1)
cc1c35357e39 Build system cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
47 DO_CMD=/bin/echo -E " $(1) $(2)" && $(3)
cc1c35357e39 Build system cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
48 else
cc1c35357e39 Build system cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
49 DO_CMD=/bin/echo -E $(3) && $(3)
cc1c35357e39 Build system cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
50 endif
78
159cc5f14092 Check for empty target directory in DO_MKDIR Makefile macro.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
51 DO_MKDIR=if test ! -z "$(1)" -a ! -d "$(1)"; then /bin/echo -E " MKDIR $(1)"; mkdir -p "$(1)"; fi
77
cc1c35357e39 Build system cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
52
cc1c35357e39 Build system cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
53
cc1c35357e39 Build system cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
54 COMPILE_C_OBJ = \
cc1c35357e39 Build system cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
55 @$(call DO_MKDIR,$(OBJPATH)) ; \
cc1c35357e39 Build system cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
56 $(call DO_CMD,CC,$<,$(CC) $(CFLAGS) $(DM_CFLAGS) -c -o $@ $< $(1))
cc1c35357e39 Build system cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
57
cc1c35357e39 Build system cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
58 LINK_C_BIN = \
cc1c35357e39 Build system cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
59 @$(call DO_MKDIR,$(BINPATH)) ; \
cc1c35357e39 Build system cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
60 $(call DO_CMD,LINK,$@,$(CC) -o $@ $(filter %.o %.a,$+) $(LDFLAGS) $(1))
cc1c35357e39 Build system cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
61
cc1c35357e39 Build system cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
62 COMPILE_CXX_OBJ = \
cc1c35357e39 Build system cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
63 @$(call DO_MKDIR,$(OBJPATH)) ; \
cc1c35357e39 Build system cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
64 $(call DO_CMD,CXX,$<,$(CXX) $(CXXFLAGS) $(DM_CFLAGS) -c -o $@ $< $(1))
cc1c35357e39 Build system cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
65
cc1c35357e39 Build system cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
66 LINK_CXX_BIN = \
cc1c35357e39 Build system cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
67 @$(call DO_MKDIR,$(BINPATH)) ; \
cc1c35357e39 Build system cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
68 $(call DO_CMD,LINK,$@,$(CXX) -o $@ $(filter %.o %.a,$+) $(LDFLAGS) $(1))
cc1c35357e39 Build system cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
69
cc1c35357e39 Build system cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
70 LINK_STATIC_LIB = \
cc1c35357e39 Build system cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
71 @$(call DO_MKDIR,$(OBJPATH)) ; \
cc1c35357e39 Build system cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
72 $(call DO_CMD,AR,$@ $(filter %.o,$+),$(AR) cru $@ $(filter %.o,$+)) ; \
cc1c35357e39 Build system cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
73 $(call DO_CMD,RANLIB,$@,$(RANLIB) $@)
cc1c35357e39 Build system cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
74
cc1c35357e39 Build system cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
75
cc1c35357e39 Build system cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
76 ###
cc1c35357e39 Build system cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
77 ### Generic target rules
40
6905d02bca2d Build system improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
78 ###
6905d02bca2d Build system improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
79 all: $(NOBUILD_TARGETS) $(NOINST_TARGETS) $(TARGETS)
6905d02bca2d Build system improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
80
6905d02bca2d Build system improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
81
79
8a56cb177711 Add dmglexts.h as depency to dmglrender.o
Matti Hamalainen <ccr@tnsp.org>
parents: 78
diff changeset
82 $(OBJPATH)dmglrender.o: dmglrender.cpp dmglrender.h dmglexts.h
100
8059aad101d1 Improve build system.
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
83 $(call COMPILE_CXX_OBJ,)
79
8a56cb177711 Add dmglexts.h as depency to dmglrender.o
Matti Hamalainen <ccr@tnsp.org>
parents: 78
diff changeset
84
40
6905d02bca2d Build system improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
85 $(OBJPATH)%.o: %.cpp %.h
100
8059aad101d1 Improve build system.
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
86 $(call COMPILE_CXX_OBJ,)
40
6905d02bca2d Build system improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
87
6905d02bca2d Build system improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
88 $(OBJPATH)%.o: %.cpp
100
8059aad101d1 Improve build system.
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
89 $(call COMPILE_CXX_OBJ,)
40
6905d02bca2d Build system improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
90
34
c0b85b0615d2 Improve the makefiles.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91
70
03aa729a9e90 Refactor PLY file parsing from dmscene.* to dmply.* and some helper functions into dmutil.h
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
92 $(BINPATH)gldragon$(BINEXT): $(addprefix $(OBJPATH), gldragon.o dmglrender.o dmscene.o dmply.o dmutil.o)
100
8059aad101d1 Improve build system.
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
93 $(call LINK_CXX_BIN, $(LDFLAGS) $(SDL_LDFLAGS) $(GL_LDFLAGS))
40
6905d02bca2d Build system improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
94
70
03aa729a9e90 Refactor PLY file parsing from dmscene.* to dmply.* and some helper functions into dmutil.h
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
95 $(BINPATH)ply2bin$(BINEXT): $(addprefix $(OBJPATH), ply2bin.o dmscene.o dmply.o dmutil.o)
100
8059aad101d1 Improve build system.
Matti Hamalainen <ccr@tnsp.org>
parents: 99
diff changeset
96 $(call LINK_CXX_BIN, $(LDFLAGS) $(TOOL_LDFLAGS))
40
6905d02bca2d Build system improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
97
34
c0b85b0615d2 Improve the makefiles.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98
40
6905d02bca2d Build system improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
99 ###
6905d02bca2d Build system improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
100 ### Special targets
6905d02bca2d Build system improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
101 ###
34
c0b85b0615d2 Improve the makefiles.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102 clean:
40
6905d02bca2d Build system improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
103 -$(RM) $(TARGETS) $(NOINST_TARGETS) $(CLEAN_TARGETS) $(OBJPATH)*.o
6905d02bca2d Build system improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
104
6905d02bca2d Build system improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
105 distclean: clean
6905d02bca2d Build system improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
106 -$(RM) $(DISTCLEAN_TARGETS) *~ core *.core
6905d02bca2d Build system improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
107
6905d02bca2d Build system improvements.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
108 .PHONY: clean distclean all