summaryrefslogtreecommitdiff
path: root/GNUmakefile
diff options
context:
space:
mode:
Diffstat (limited to 'GNUmakefile')
-rw-r--r--GNUmakefile205
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
10all: # default target 10all: # default target
11 11
12#
13# G N U M A K E F U N C T I O N S
14#
15KNOWN_APIS = 5.1 5.2 5.3
16
17# template for invoking luapath script
18LUAPATH := $(d)/mk/luapath
19LUAPATH_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
22HAVE_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
25WITH_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
30AR ?= ar 44AR ?= ar
31RANLIB ?= ranlib 45RANLIB ?= ranlib
32M4 ?= m4 46M4 ?= m4
47MV ?= mv
33RM ?= rm 48RM ?= rm
34CP ?= cp 49CP ?= cp
35LN ?= ln
36LN_S ?= $(LN) -s
37RMDIR ?= rmdir 50RMDIR ?= rmdir
38MKDIR ?= mkdir 51MKDIR ?= mkdir
39CHMOD ?= chmod 52CHMOD ?= chmod
40INSTALL ?= install 53INSTALL ?= install
41INSTALL_DATA ?= $(INSTALL) -m 644 54INSTALL_DATA ?= $(INSTALL) -m 644
55TOUCH ?= touch
56TEE ?= tee
57TEE_A ?= $(TEE) -a
58
59# see Lua Autodetection, below
42 60
43.PHONY: $(d)/config 61.PHONY: $(d)/config
44 62
63PRINT_$(d) = printf "%s = %s\n" '$(1)' '$(subst ',\\',$(2))' | $(TEE_A) '$(3)'
64
65LAZY_$(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
74NONLAZY_$(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
76ifneq "$(filter $(abspath $(d)/..)/%, $(abspath $(firstword $(MAKEFILE_LIST))))" "" 86ifneq "$(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 "?"
98ifeq ($(or $(strip $(LUA_APIS)),?),?)
99override LUA_APIS := $(call HAVE_API_FN,5.1) $(call HAVE_API_FN,5.2) $(call HAVE_API_FN,5.3)
100endif
101
102define LUAXY_template
103
104# set luaXYcpath if empty or "?"
105ifeq ($$(or $$(strip $$(lua$(subst .,,$(1))cpath)),?),?)
106override lua$(subst .,,$(1))cpath := $$(or $$(call LUAPATH_FN,$(1),cdir),$$(libdir)/lua/$(1))
107endif
108
109# set luaXYpath if empty or "?"
110ifeq ($$(or $$(strip $$(lua$(subst .,,$(1))path)),?),?)
111override lua$(subst .,,$(1))path = $$(or $$(call LUAPATH_FN,$(1),ldir),$$(datadir)/lua/$(1))
112endif
113
114# set LUAXY_CPPFLAGS if undefined or "?" (NB: can be empty if path already in $(CPPFLAGS))
115ifeq ($$(and $$(findstring undefined,$$(origin LUA$(subst .,,$(1))_CPPFLAGS)),?),?)
116override LUA$(subst .,,$(1))_CPPFLAGS = $$(and $$(call WITH_API_FN,$(1)),$$(call LUAPATH_FN,$(1),cppflags))
117endif
118
119# set ALL_LUAXY_CPPFLAGS if empty or "?"
120ifeq ($$(or $$(strip $$(ALL_LUA$(subst .,,$(1))_CPPFLAGS)),?),?)
121override ALL_LUA$(subst .,,$(1))_CPPFLAGS = $$(LUA$(subst .,,$(1))_CPPFLAGS)
122endif
123
124# set LUAXYC if empty or "?"
125ifeq ($$(or $$(strip $$(LUAC$(subst .,,$(1)))),?),?)
126override LUAC$(subst .,,$(1)) = $$(or $$(call LUAPATH_FN,$(1),luac),true)
127endif
128
129endef # 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#
86cc-option ?= $(shell if $(CC) $(1) -S -o /dev/null -xc /dev/null \ 138cc-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 \
89VENDOR_OS_$(d) := $(shell $(d)/mk/vendor.os) 141VENDOR_OS_$(d) := $(shell $(d)/mk/vendor.os)
90VENDOR_CC_$(d) := $(shell env CC="$(CC)" $(d)/mk/vendor.cc) 142VENDOR_CC_$(d) := $(shell env CC="$(CC)" $(d)/mk/vendor.cc)
91 143
144#
145# ALL_CPPFLAGS
146#
147ifeq ($(origin ALL_CPPFLAGS), undefined)
148
92ifneq ($(VENDOR_OS_$(d)), OpenBSD) 149ifneq ($(VENDOR_OS_$(d)), OpenBSD)
93CPPFLAGS_$(d) += -D_REENTRANT -D_THREAD_SAFE -D_GNU_SOURCE 150ALL_CPPFLAGS += -D_REENTRANT -D_THREAD_SAFE -D_GNU_SOURCE
94endif 151endif
95 152
96ifeq ($(VENDOR_OS_$(d)), SunOS) 153ifeq ($(VENDOR_OS_$(d)), SunOS)
97CPPFLAGS_$(d) += -Usun -D_XPG4_2 -D__EXTENSIONS__ 154ALL_CPPFLAGS += -Usun -D_XPG4_2 -D__EXTENSIONS__
98endif 155endif
99 156
157ALL_CPPFLAGS += $(CPPFLAGS)
158
159endif # ALL_CPPFLAGS
160
161#
162# ALL_CFLAGS
163#
164ifeq ($(origin ALL_CFLAGS), undefined)
165
100ifeq ($(VENDOR_CC_$(d)), gcc) 166ifeq ($(VENDOR_CC_$(d)), gcc)
101CFLAGS_$(d) += -O2 -std=gnu99 -fPIC 167ALL_CFLAGS += -O2 -std=gnu99 -fPIC
102CFLAGS_$(d) += -g -Wall -Wextra $(call cc-option, -Wno-missing-field-initializers) $(call cc-option, -Wno-override-init) -Wno-unused 168ALL_CFLAGS += -g -Wall -Wextra $(call cc-option, -Wno-missing-field-initializers) $(call cc-option, -Wno-override-init) -Wno-unused
103endif 169endif
104 170
105ifeq ($(VENDOR_CC_$(d)), clang) 171ifeq ($(VENDOR_CC_$(d)), clang)
106CFLAGS_$(d) += -O2 -std=gnu99 -fPIC 172ALL_CFLAGS += -O2 -std=gnu99 -fPIC
107CFLAGS_$(d) += -g -Wall -Wextra -Wno-missing-field-initializers -Wno-initializer-overrides -Wno-unused 173ALL_CFLAGS += -g -Wall -Wextra -Wno-missing-field-initializers -Wno-initializer-overrides -Wno-unused -Wno-dollar-in-identifier-extension
108endif 174endif
109 175
110ifeq ($(VENDOR_CC_$(d)), sunpro) 176ifeq ($(VENDOR_CC_$(d)), sunpro)
111CFLAGS_$(d) += -xcode=pic13 177ALL_CFLAGS += -xcode=pic13
112CFLAGS_$(d) += -g 178ALL_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#
117CFLAGS_$(d) += -erroff=E_ARGUEMENT_MISMATCH 183ALL_CFLAGS += -erroff=E_ANONYMOUS_UNION_DECL
118endif 184endif
119 185
120ifeq ($(VENDOR_OS_$(d)), Darwin) 186ifeq ($(VENDOR_OS_$(d)), Darwin)
121CFLAGS_$(d) += -Wno-deprecated-declarations 187ALL_CFLAGS += -Wno-deprecated-declarations
122endif 188endif
123 189
190ALL_CFLAGS += $(CFLAGS)
191
192endif # ALL_CFLAGS
193
194#
195# ALL_SOFLAGS
196#
197ifeq ($(origin ALL_SOFLAGS), undefined)
198
124ifeq ($(VENDOR_OS_$(d)), Darwin) 199ifeq ($(VENDOR_OS_$(d)), Darwin)
125SOFLAGS_$(d) += -bundle -undefined dynamic_lookup 200ALL_SOFLAGS += -bundle -undefined dynamic_lookup
126else 201else
127SOFLAGS_$(d) += -shared 202ALL_SOFLAGS += -shared
203endif
204
205ALL_SOFLAGS += $(SOFLAGS)
206
207endif # ALL_SOFLAGS
208
209#
210# ALL_LDFLAGS
211#
212ifeq ($(origin ALL_LDFLAGS), undefined)
213
214ALL_LDFLAGS += -L$(DESTDIR)$(libdir) -L$(libdir)
215ALL_LDFLAGS += $(LDFLAGS)
216
217endif # ALL_LDFLAGS
218
219#
220# ALL_LIBS
221#
222ifeq ($(origin ALL_LIBS), undefined)
223
224# put $(LIBS) first as they're more likely to be higher-level dependencies
225ALL_LIBS += $(LIBS)
226ALL_LIBS += -lssl -lcrypto -lpthread
227
228# NetBSD, FreeBSD, OpenBSD (and presumably descendants) lack any libdl;
229# dlopen, et al are part of libc.
230ifneq ($(patsubst %BSD,BSD,$(VENDOR_OS_$(d))), BSD)
231ALL_LIBS += -ldl
128endif 232endif
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.
237ifeq ($(VENDOR_OS_$(d)), Linux)
238ALL_LIBS += -lrt
239endif
240
241ALL_LIBS += -lm
242
243endif # 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