summaryrefslogtreecommitdiff
path: root/GNUmakefile
diff options
context:
space:
mode:
Diffstat (limited to 'GNUmakefile')
-rw-r--r--GNUmakefile193
1 files changed, 193 insertions, 0 deletions
diff --git a/GNUmakefile b/GNUmakefile
new file mode 100644
index 0000000..33903f8
--- /dev/null
+++ b/GNUmakefile
@@ -0,0 +1,193 @@
1# non-recursive prologue
2sp := $(sp).x
3dirstack_$(sp) := $(d)
4d := $(abspath $(lastword $(MAKEFILE_LIST))/..)
5
6ifeq ($(origin GUARD_$(d)), undefined)
7GUARD_$(d) := 1
8
9
10all: # default target
11
12
13#
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
15#
16-include $(d)/.config
17
18prefix ?= /usr/local
19includedir ?= $(prefix)/include
20libdir ?= $(prefix)/lib
21datadir ?= $(prefix)/share
22bindir ?= $(prefix)/bin
23lua51cpath ?= $(libdir)/lua/5.1
24lua51path ?= $(datadir)/lua/5.1
25lua52cpath ?= $(libdir)/lua/5.2
26lua52path ?= $(datadir)/lua/5.2
27
28AR ?= ar
29RANLIB ?= ranlib
30M4 ?= m4
31RM ?= rm
32CP ?= cp
33RMDIR ?= rmdir
34MKDIR ?= mkdir
35CHMOD ?= chmod
36INSTALL ?= install
37INSTALL_DATA ?= $(INSTALL) -m 644
38
39.PHONY: $(d)/config
40
41$(d)/config:
42 printf 'prefix ?= $(value prefix)'"\n" >| $(@D)/.config
43 printf 'includedir ?= $(value includedir)'"\n" >> $(@D)/.config
44 printf 'libdir ?= $(value libdir)'"\n" >> $(@D)/.config
45 printf 'datadir ?= $(value datadir)'"\n" >> $(@D)/.config
46 printf 'bindir ?= $(value bindir)'"\n" >> $(@D)/.config
47 printf 'lua51cpath ?= $(value lua51cpath)'"\n" >> $(@D)/.config
48 printf 'lua51path ?= $(value lua51path)'"\n" >> $(@D)/.config
49 printf 'lua52cpath ?= $(value lua52cpath)'"\n" >> $(@D)/.config
50 printf 'lua52path ?= $(value lua52path)'"\n" >> $(@D)/.config
51 printf 'CC ?= $(CC)'"\n" >> $(@D)/.config
52 printf 'CPPFLAGS ?= $(value CPPFLAGS)'"\n" >> $(@D)/.config
53 printf 'CFLAGS ?= $(value CFLAGS)'"\n" >> $(@D)/.config
54 printf 'LDFLAGS ?= $(value LDFLAGS)'"\n" >> $(@D)/.config
55 printf 'SOFLAGS ?= $(value SOFLAGS)'"\n" >> $(@D)/.config
56 printf 'AR ?= $(value AR)'"\n" >> $(@D)/.config
57 printf 'RANLIB ?= $(value RANLIB)'"\n" >> $(@D)/.config
58 printf 'M4 ?= $(value M4)'"\n" >> $(@D)/.config
59 printf 'RM ?= $(value RM)'"\n" >> $(@D)/.config
60 printf 'CP ?= $(value CP)'"\n" >> $(@D)/.config
61 printf 'RMDIR ?= $(value RMDIR)'"\n" >> $(@D)/.config
62 printf 'MKDIR ?= $(value MKDIR)'"\n" >> $(@D)/.config
63 printf 'CHMOD ?= $(value CHMOD)'"\n" >> $(@D)/.config
64 printf 'INSTALL ?= $(value INSTALL)'"\n" >> $(@D)/.config
65 printf 'INSTALL_DATA ?= $(value INSTALL_DATA)'"\n" >> $(@D)/.config
66
67# add local targets if building from inside project tree
68ifneq "$(filter $(abspath $(d)/..)/%, $(abspath $(firstword $(MAKEFILE_LIST))))" ""
69.PHONY: config configure
70
71config configure: $(d)/config
72endif
73
74
75#
76# S H A R E D C O M P I L A T I O N F L A G S
77#
78cc-option ?= $(shell if $(CC) $(1) -S -o /dev/null -xc /dev/null \
79 > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi;)
80
81VENDOR_OS_$(d) := $(shell $(d)/mk/vendor.os)
82VENDOR_CC_$(d) := $(shell env CC="$(CC)" $(d)/mk/vendor.cc)
83
84ifneq ($(VENDOR_OS_$(d)), OpenBSD)
85CPPFLAGS_$(d) += -D_REENTRANT -D_THREAD_SAFE -D_GNU_SOURCE
86endif
87
88ifeq ($(VENDOR_OS_$(d)), SunOS)
89CPPFLAGS_$(d) += -Usun -D_XPG4_2 -D__EXTENSIONS__
90endif
91
92ifeq ($(VENDOR_CC_$(d)), gcc)
93CFLAGS_$(d) += -O2 -std=gnu99 -fPIC
94CFLAGS_$(d) += -g -Wall -Wextra $(call cc-option, -Wno-missing-field-initializers) $(call cc-option, -Wno-override-init) -Wno-unused
95endif
96
97ifeq ($(VENDOR_CC_$(d)), clang)
98CFLAGS_$(d) += -O2 -std=gnu99 -fPIC
99CFLAGS_$(d) += -g -Wall -Wextra -Wno-missing-field-initializers -Wno-initializer-overrides -Wno-unused
100endif
101
102ifeq ($(VENDOR_CC_$(d)), sunpro)
103CFLAGS_$(d) += -xcode=pic13
104CFLAGS_$(d) += -g
105endif
106
107ifeq ($(VENDOR_OS_$(d)), Darwin)
108CFLAGS_$(d) += -Wno-deprecated-declarations
109endif
110
111ifeq ($(VENDOR_OS_$(d)), Darwin)
112SOFLAGS_$(d) += -bundle -undefined dynamic_lookup
113else
114SOFLAGS_$(d) += -shared
115endif
116
117
118#
119# P R O J E C T R U L E S
120#
121include $(d)/src/GNUmakefile
122
123
124#
125# C L E A N R U L E S
126#
127.PHONY: $(d)/clean~ clean~
128
129$(d)/clean~:
130 $(RM) -f $(@D)/*~
131
132clean~: $(d)/clean~
133
134
135#
136# D E B I A N R U L E S
137#
138ifneq "$(filter $(abspath $(d))/%, $(abspath $(firstword $(MAKEFILE_LIST))))" ""
139
140DPKG_BUILDPACKAGE ?= dpkg-buildpackage
141FAKEROOT ?= fakeroot
142DPKG_BUILDPACKAGE_OPTIONS ?= -b -uc -us
143
144.PHONY: $(d)/debian $(d)/debian-clean debian deb debian-clean deb-clean
145
146$(d)/debian:
147 cd $(@D) && $(DPKG_BUILDPACKAGE) -rfakeroot $(DPKG_BUILDPACKAGE_OPTIONS)
148
149$(d)/debian-clean:
150 cd $(@D) && $(FAKEROOT) ./debian/rules clean
151
152debian deb: $(d)/debian
153
154debian-clean deb-clean: $(d)/debian-clean
155
156endif # debian guard
157
158
159#
160# R E D H A T R U L E S
161#
162ifneq "$(filter $(abspath $(d))/%, $(abspath $(firstword $(MAKEFILE_LIST))))" ""
163.PHONY: $(d)/redhat $(d)/redhat-clean redhat rpm redhat-clean rpm-clean
164
165redhat rpm: $(d)/redhat
166
167redhat-clean rpm-clean: $(d)/redhat-clean
168
169endif # redhat guard
170
171
172#
173# R E L E A S E T A R B A L L R U L E S
174#
175ifneq "$(filter $(abspath $(d))/%, $(abspath $(firstword $(MAKEFILE_LIST))))" ""
176
177LUAOSSL_VERSION := $(shell $(d)/mk/changelog version)
178
179.PHONY: $(d)/luaossl-$(LUAOSSL_VERSION).tgz release
180
181$(d)/luaossl-$(LUAOSSL_VERSION).tgz:
182 cd $(@D) && git archive --format=tar --prefix=$(basename $(@F))/ HEAD | gzip -c > $@
183
184release: $(d)/luaossl-$(LUAOSSL_VERSION).tgz
185
186endif # release guard
187
188
189endif # include guard
190
191# non-recursive epilogue
192d := $(dirstack_$(sp))
193sp := $(basename $(sp))