diff options
Diffstat (limited to 'GNUmakefile')
-rw-r--r-- | GNUmakefile | 205 |
1 files changed, 160 insertions, 45 deletions
diff --git a/GNUmakefile b/GNUmakefile index c58686c..1893378 100644 --- a/GNUmakefile +++ b/GNUmakefile | |||
@@ -9,6 +9,20 @@ GUARD_$(d) := 1 | |||
9 | 9 | ||
10 | all: # default target | 10 | all: # default target |
11 | 11 | ||
12 | # | ||
13 | # G N U M A K E F U N C T I O N S | ||
14 | # | ||
15 | KNOWN_APIS = 5.1 5.2 5.3 | ||
16 | |||
17 | # template for invoking luapath script | ||
18 | LUAPATH := $(d)/mk/luapath | ||
19 | LUAPATH_FN = $(shell env CC='$(subst ',\\',$(CC))' CPPFLAGS='$(subst ',\\',$(CPPFLAGS))' LDFLAGS='$(subst ',\\',$(LDFLAGS))' $(LUAPATH) -krxm3 -I '$(subst ',\\',$(DESTDIR)$(includedir))' -I/usr/include -I/usr/local/include -P '$(subst ',\\',$(DESTDIR)$(bindir))' -P '$(subst ',\\',$(bindir))' -L '$(subst ',\\',$(DESTDIR)$(libdir))' -L '$(subst ',\\',$(libdir))' -v$(1) $(2)) | ||
20 | |||
21 | # check whether luapath can locate Lua $(1) headers | ||
22 | HAVE_API_FN = $(and $(filter $(1),$(call LUAPATH_FN,$(1),version)),$(1)$(info enabling Lua $(1))) | ||
23 | |||
24 | # check whether $(1) in LUA_APIS or $(LUA$(1:.=)_CPPFLAGS) is non-empty | ||
25 | WITH_API_FN = $$(and $$(or $$(filter $(1),$$(LUA_APIS)),$$(LUA$(subst .,,$(1))_CPPFLAGS)),$(1)) | ||
12 | 26 | ||
13 | # | 27 | # |
14 | # E N V I R O N M E N T C O N F I G U R A T I O N | 28 | # E N V I R O N M E N T C O N F I G U R A T I O N |
@@ -30,47 +44,43 @@ lua53path ?= $(datadir)/lua/5.3 | |||
30 | AR ?= ar | 44 | AR ?= ar |
31 | RANLIB ?= ranlib | 45 | RANLIB ?= ranlib |
32 | M4 ?= m4 | 46 | M4 ?= m4 |
47 | MV ?= mv | ||
33 | RM ?= rm | 48 | RM ?= rm |
34 | CP ?= cp | 49 | CP ?= cp |
35 | LN ?= ln | ||
36 | LN_S ?= $(LN) -s | ||
37 | RMDIR ?= rmdir | 50 | RMDIR ?= rmdir |
38 | MKDIR ?= mkdir | 51 | MKDIR ?= mkdir |
39 | CHMOD ?= chmod | 52 | CHMOD ?= chmod |
40 | INSTALL ?= install | 53 | INSTALL ?= install |
41 | INSTALL_DATA ?= $(INSTALL) -m 644 | 54 | INSTALL_DATA ?= $(INSTALL) -m 644 |
55 | TOUCH ?= touch | ||
56 | TEE ?= tee | ||
57 | TEE_A ?= $(TEE) -a | ||
58 | |||
59 | # see Lua Autodetection, below | ||
42 | 60 | ||
43 | .PHONY: $(d)/config | 61 | .PHONY: $(d)/config |
44 | 62 | ||
63 | PRINT_$(d) = printf "%s = %s\n" '$(1)' '$(subst ',\\',$(2))' | $(TEE_A) '$(3)' | ||
64 | |||
65 | LAZY_$(d) = \ | ||
66 | prefix includedir libdir datadir bindir \ | ||
67 | lua51cpath lua51path lua52cpath lua52path lua53cpath lua53path \ | ||
68 | CC ALL_CPPFLAGS CPPFLAGS ALL_CFLAGS CFLAGS ALL_LDFLAGS LDFLAGS \ | ||
69 | ALL_SOFLAGS SOFLAGS ALL_LIB LIBS \ | ||
70 | $(foreach API,$(KNOWN_APIS),ALL_LUA$(subst .,,$(API))_CPPFLAGS) \ | ||
71 | AR RANLIB M4 MV RM CP RMDIR MKDIR CHMOD INSTALL INSTALL_DATA TOUCH \ | ||
72 | TEE TEE_A | ||
73 | |||
74 | NONLAZY_$(d) = \ | ||
75 | LUA_APIS \ | ||
76 | $(foreach API,$(KNOWN_APIS),LUAC$(subst .,,$(API))) \ | ||
77 | $(foreach API,$(KNOWN_APIS),$(and $(call WITH_API_FN,$(API)),LUA$(subst .,,$(API))_CPPFLAGS)) | ||
78 | |||
45 | $(d)/config: | 79 | $(d)/config: |
46 | printf 'prefix ?= $(value prefix)'"\n" >| $(@D)/.config | 80 | $(TOUCH) $(@D)/.config.tmp |
47 | printf 'includedir ?= $(value includedir)'"\n" >> $(@D)/.config | 81 | @$(foreach V,$(LAZY_$(@D)), $(call PRINT_$(@D),$(V),$(value $(V)),$(@D)/.config.tmp);) |
48 | printf 'libdir ?= $(value libdir)'"\n" >> $(@D)/.config | 82 | @$(foreach V,$(NONLAZY_$(@D)), $(call PRINT_$(@D),$(V),$($(V)),$(@D)/.config.tmp);) |
49 | printf 'datadir ?= $(value datadir)'"\n" >> $(@D)/.config | 83 | $(MV) $(@D)/.config.tmp $(@D)/.config |
50 | printf 'bindir ?= $(value bindir)'"\n" >> $(@D)/.config | ||
51 | printf 'lua51cpath ?= $(value lua51cpath)'"\n" >> $(@D)/.config | ||
52 | printf 'lua51path ?= $(value lua51path)'"\n" >> $(@D)/.config | ||
53 | printf 'lua52cpath ?= $(value lua52cpath)'"\n" >> $(@D)/.config | ||
54 | printf 'lua52path ?= $(value lua52path)'"\n" >> $(@D)/.config | ||
55 | printf 'lua53cpath ?= $(value lua53cpath)'"\n" >> $(@D)/.config | ||
56 | printf 'lua53path ?= $(value lua53path)'"\n" >> $(@D)/.config | ||
57 | printf 'CC ?= $(CC)'"\n" >> $(@D)/.config | ||
58 | printf 'CPPFLAGS ?= $(value CPPFLAGS)'"\n" >> $(@D)/.config | ||
59 | printf 'CFLAGS ?= $(value CFLAGS)'"\n" >> $(@D)/.config | ||
60 | printf 'LDFLAGS ?= $(value LDFLAGS)'"\n" >> $(@D)/.config | ||
61 | printf 'SOFLAGS ?= $(value SOFLAGS)'"\n" >> $(@D)/.config | ||
62 | printf 'AR ?= $(value AR)'"\n" >> $(@D)/.config | ||
63 | printf 'RANLIB ?= $(value RANLIB)'"\n" >> $(@D)/.config | ||
64 | printf 'M4 ?= $(value M4)'"\n" >> $(@D)/.config | ||
65 | printf 'RM ?= $(value RM)'"\n" >> $(@D)/.config | ||
66 | printf 'CP ?= $(value CP)'"\n" >> $(@D)/.config | ||
67 | printf 'LN ?= $(value LN)'"\n" >> $(@D)/.config | ||
68 | printf 'LN_S ?= $(value LN_S)'"\n" >> $(@D)/.config | ||
69 | printf 'RMDIR ?= $(value RMDIR)'"\n" >> $(@D)/.config | ||
70 | printf 'MKDIR ?= $(value MKDIR)'"\n" >> $(@D)/.config | ||
71 | printf 'CHMOD ?= $(value CHMOD)'"\n" >> $(@D)/.config | ||
72 | printf 'INSTALL ?= $(value INSTALL)'"\n" >> $(@D)/.config | ||
73 | printf 'INSTALL_DATA ?= $(value INSTALL_DATA)'"\n" >> $(@D)/.config | ||
74 | 84 | ||
75 | # add local targets if building from inside project tree | 85 | # add local targets if building from inside project tree |
76 | ifneq "$(filter $(abspath $(d)/..)/%, $(abspath $(firstword $(MAKEFILE_LIST))))" "" | 86 | ifneq "$(filter $(abspath $(d)/..)/%, $(abspath $(firstword $(MAKEFILE_LIST))))" "" |
@@ -81,7 +91,49 @@ endif | |||
81 | 91 | ||
82 | 92 | ||
83 | # | 93 | # |
84 | # S H A R E D C O M P I L A T I O N F L A G S | 94 | # L U A A U T O D E T E C T I O N |
95 | # | ||
96 | |||
97 | # set LUA_APIS if empty or "?" | ||
98 | ifeq ($(or $(strip $(LUA_APIS)),?),?) | ||
99 | override LUA_APIS := $(call HAVE_API_FN,5.1) $(call HAVE_API_FN,5.2) $(call HAVE_API_FN,5.3) | ||
100 | endif | ||
101 | |||
102 | define LUAXY_template | ||
103 | |||
104 | # set luaXYcpath if empty or "?" | ||
105 | ifeq ($$(or $$(strip $$(lua$(subst .,,$(1))cpath)),?),?) | ||
106 | override lua$(subst .,,$(1))cpath := $$(or $$(call LUAPATH_FN,$(1),cdir),$$(libdir)/lua/$(1)) | ||
107 | endif | ||
108 | |||
109 | # set luaXYpath if empty or "?" | ||
110 | ifeq ($$(or $$(strip $$(lua$(subst .,,$(1))path)),?),?) | ||
111 | override lua$(subst .,,$(1))path = $$(or $$(call LUAPATH_FN,$(1),ldir),$$(datadir)/lua/$(1)) | ||
112 | endif | ||
113 | |||
114 | # set LUAXY_CPPFLAGS if undefined or "?" (NB: can be empty if path already in $(CPPFLAGS)) | ||
115 | ifeq ($$(and $$(findstring undefined,$$(origin LUA$(subst .,,$(1))_CPPFLAGS)),?),?) | ||
116 | override LUA$(subst .,,$(1))_CPPFLAGS = $$(and $$(call WITH_API_FN,$(1)),$$(call LUAPATH_FN,$(1),cppflags)) | ||
117 | endif | ||
118 | |||
119 | # set ALL_LUAXY_CPPFLAGS if empty or "?" | ||
120 | ifeq ($$(or $$(strip $$(ALL_LUA$(subst .,,$(1))_CPPFLAGS)),?),?) | ||
121 | override ALL_LUA$(subst .,,$(1))_CPPFLAGS = $$(LUA$(subst .,,$(1))_CPPFLAGS) | ||
122 | endif | ||
123 | |||
124 | # set LUAXYC if empty or "?" | ||
125 | ifeq ($$(or $$(strip $$(LUAC$(subst .,,$(1)))),?),?) | ||
126 | override LUAC$(subst .,,$(1)) = $$(or $$(call LUAPATH_FN,$(1),luac),true) | ||
127 | endif | ||
128 | |||
129 | endef # LUAXY_template | ||
130 | |||
131 | $(eval $(call LUAXY_template,5.1)) | ||
132 | $(eval $(call LUAXY_template,5.2)) | ||
133 | $(eval $(call LUAXY_template,5.3)) | ||
134 | |||
135 | # | ||
136 | # A U T O D E T E C T C O M P I L A T I O N F L A G S | ||
85 | # | 137 | # |
86 | cc-option ?= $(shell if $(CC) $(1) -S -o /dev/null -xc /dev/null \ | 138 | cc-option ?= $(shell if $(CC) $(1) -S -o /dev/null -xc /dev/null \ |
87 | > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi;) | 139 | > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi;) |
@@ -89,44 +141,107 @@ cc-option ?= $(shell if $(CC) $(1) -S -o /dev/null -xc /dev/null \ | |||
89 | VENDOR_OS_$(d) := $(shell $(d)/mk/vendor.os) | 141 | VENDOR_OS_$(d) := $(shell $(d)/mk/vendor.os) |
90 | VENDOR_CC_$(d) := $(shell env CC="$(CC)" $(d)/mk/vendor.cc) | 142 | VENDOR_CC_$(d) := $(shell env CC="$(CC)" $(d)/mk/vendor.cc) |
91 | 143 | ||
144 | # | ||
145 | # ALL_CPPFLAGS | ||
146 | # | ||
147 | ifeq ($(origin ALL_CPPFLAGS), undefined) | ||
148 | |||
92 | ifneq ($(VENDOR_OS_$(d)), OpenBSD) | 149 | ifneq ($(VENDOR_OS_$(d)), OpenBSD) |
93 | CPPFLAGS_$(d) += -D_REENTRANT -D_THREAD_SAFE -D_GNU_SOURCE | 150 | ALL_CPPFLAGS += -D_REENTRANT -D_THREAD_SAFE -D_GNU_SOURCE |
94 | endif | 151 | endif |
95 | 152 | ||
96 | ifeq ($(VENDOR_OS_$(d)), SunOS) | 153 | ifeq ($(VENDOR_OS_$(d)), SunOS) |
97 | CPPFLAGS_$(d) += -Usun -D_XPG4_2 -D__EXTENSIONS__ | 154 | ALL_CPPFLAGS += -Usun -D_XPG4_2 -D__EXTENSIONS__ |
98 | endif | 155 | endif |
99 | 156 | ||
157 | ALL_CPPFLAGS += $(CPPFLAGS) | ||
158 | |||
159 | endif # ALL_CPPFLAGS | ||
160 | |||
161 | # | ||
162 | # ALL_CFLAGS | ||
163 | # | ||
164 | ifeq ($(origin ALL_CFLAGS), undefined) | ||
165 | |||
100 | ifeq ($(VENDOR_CC_$(d)), gcc) | 166 | ifeq ($(VENDOR_CC_$(d)), gcc) |
101 | CFLAGS_$(d) += -O2 -std=gnu99 -fPIC | 167 | ALL_CFLAGS += -O2 -std=gnu99 -fPIC |
102 | CFLAGS_$(d) += -g -Wall -Wextra $(call cc-option, -Wno-missing-field-initializers) $(call cc-option, -Wno-override-init) -Wno-unused | 168 | ALL_CFLAGS += -g -Wall -Wextra $(call cc-option, -Wno-missing-field-initializers) $(call cc-option, -Wno-override-init) -Wno-unused |
103 | endif | 169 | endif |
104 | 170 | ||
105 | ifeq ($(VENDOR_CC_$(d)), clang) | 171 | ifeq ($(VENDOR_CC_$(d)), clang) |
106 | CFLAGS_$(d) += -O2 -std=gnu99 -fPIC | 172 | ALL_CFLAGS += -O2 -std=gnu99 -fPIC |
107 | CFLAGS_$(d) += -g -Wall -Wextra -Wno-missing-field-initializers -Wno-initializer-overrides -Wno-unused | 173 | ALL_CFLAGS += -g -Wall -Wextra -Wno-missing-field-initializers -Wno-initializer-overrides -Wno-unused -Wno-dollar-in-identifier-extension |
108 | endif | 174 | endif |
109 | 175 | ||
110 | ifeq ($(VENDOR_CC_$(d)), sunpro) | 176 | ifeq ($(VENDOR_CC_$(d)), sunpro) |
111 | CFLAGS_$(d) += -xcode=pic13 | 177 | ALL_CFLAGS += -xcode=pic13 |
112 | CFLAGS_$(d) += -g | 178 | ALL_CFLAGS += -g |
113 | # | 179 | # |
114 | # Solaris Studio has a brain-dead function call analyzer which counts | 180 | # Solaris Studio supports anonymous unions just fine; but it complains |
115 | # arguments before preprocessor expansion. | 181 | # incessantly about them. |
116 | # | 182 | # |
117 | CFLAGS_$(d) += -erroff=E_ARGUEMENT_MISMATCH | 183 | ALL_CFLAGS += -erroff=E_ANONYMOUS_UNION_DECL |
118 | endif | 184 | endif |
119 | 185 | ||
120 | ifeq ($(VENDOR_OS_$(d)), Darwin) | 186 | ifeq ($(VENDOR_OS_$(d)), Darwin) |
121 | CFLAGS_$(d) += -Wno-deprecated-declarations | 187 | ALL_CFLAGS += -Wno-deprecated-declarations |
122 | endif | 188 | endif |
123 | 189 | ||
190 | ALL_CFLAGS += $(CFLAGS) | ||
191 | |||
192 | endif # ALL_CFLAGS | ||
193 | |||
194 | # | ||
195 | # ALL_SOFLAGS | ||
196 | # | ||
197 | ifeq ($(origin ALL_SOFLAGS), undefined) | ||
198 | |||
124 | ifeq ($(VENDOR_OS_$(d)), Darwin) | 199 | ifeq ($(VENDOR_OS_$(d)), Darwin) |
125 | SOFLAGS_$(d) += -bundle -undefined dynamic_lookup | 200 | ALL_SOFLAGS += -bundle -undefined dynamic_lookup |
126 | else | 201 | else |
127 | SOFLAGS_$(d) += -shared | 202 | ALL_SOFLAGS += -shared |
203 | endif | ||
204 | |||
205 | ALL_SOFLAGS += $(SOFLAGS) | ||
206 | |||
207 | endif # ALL_SOFLAGS | ||
208 | |||
209 | # | ||
210 | # ALL_LDFLAGS | ||
211 | # | ||
212 | ifeq ($(origin ALL_LDFLAGS), undefined) | ||
213 | |||
214 | ALL_LDFLAGS += -L$(DESTDIR)$(libdir) -L$(libdir) | ||
215 | ALL_LDFLAGS += $(LDFLAGS) | ||
216 | |||
217 | endif # ALL_LDFLAGS | ||
218 | |||
219 | # | ||
220 | # ALL_LIBS | ||
221 | # | ||
222 | ifeq ($(origin ALL_LIBS), undefined) | ||
223 | |||
224 | # put $(LIBS) first as they're more likely to be higher-level dependencies | ||
225 | ALL_LIBS += $(LIBS) | ||
226 | ALL_LIBS += -lssl -lcrypto -lpthread | ||
227 | |||
228 | # NetBSD, FreeBSD, OpenBSD (and presumably descendants) lack any libdl; | ||
229 | # dlopen, et al are part of libc. | ||
230 | ifneq ($(patsubst %BSD,BSD,$(VENDOR_OS_$(d))), BSD) | ||
231 | ALL_LIBS += -ldl | ||
128 | endif | 232 | endif |
129 | 233 | ||
234 | # This only seems to be necessary on Linux. Darwin and OpenBSD lack a librt. | ||
235 | # On OpenBSD clock_gettime is part of libc. Others have librt, but linking | ||
236 | # it in is unnecessary. | ||
237 | ifeq ($(VENDOR_OS_$(d)), Linux) | ||
238 | ALL_LIBS += -lrt | ||
239 | endif | ||
240 | |||
241 | ALL_LIBS += -lm | ||
242 | |||
243 | endif # ALL_LIBS | ||
244 | |||
130 | 245 | ||
131 | # | 246 | # |
132 | # P R O J E C T R U L E S | 247 | # P R O J E C T R U L E S |