aboutsummaryrefslogtreecommitdiffstats
path: root/GNUmakefile
blob: 33903f83582d2401288e032f6ac65cb3f94e144f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# non-recursive prologue
sp := $(sp).x
dirstack_$(sp) := $(d)
d := $(abspath $(lastword $(MAKEFILE_LIST))/..)

ifeq ($(origin GUARD_$(d)), undefined)
GUARD_$(d) := 1


all: # default target


#
# E N V I R O N M E N T  C O N F I G U R A T I O N
#
-include $(d)/.config

prefix ?= /usr/local
includedir ?= $(prefix)/include
libdir ?= $(prefix)/lib
datadir ?= $(prefix)/share
bindir ?= $(prefix)/bin
lua51cpath ?= $(libdir)/lua/5.1
lua51path ?= $(datadir)/lua/5.1
lua52cpath ?= $(libdir)/lua/5.2
lua52path ?= $(datadir)/lua/5.2

AR ?= ar
RANLIB ?= ranlib
M4 ?= m4
RM ?= rm
CP ?= cp
RMDIR ?= rmdir
MKDIR ?= mkdir
CHMOD ?= chmod
INSTALL ?= install
INSTALL_DATA ?= $(INSTALL) -m 644

.PHONY: $(d)/config

$(d)/config:
	printf 'prefix ?= $(value prefix)'"\n" >| $(@D)/.config
	printf 'includedir ?= $(value includedir)'"\n" >> $(@D)/.config
	printf 'libdir ?= $(value libdir)'"\n" >> $(@D)/.config
	printf 'datadir ?= $(value datadir)'"\n" >> $(@D)/.config
	printf 'bindir ?= $(value bindir)'"\n" >> $(@D)/.config
	printf 'lua51cpath ?= $(value lua51cpath)'"\n" >> $(@D)/.config
	printf 'lua51path ?= $(value lua51path)'"\n" >> $(@D)/.config
	printf 'lua52cpath ?= $(value lua52cpath)'"\n" >> $(@D)/.config
	printf 'lua52path ?= $(value lua52path)'"\n" >> $(@D)/.config
	printf 'CC ?= $(CC)'"\n" >> $(@D)/.config
	printf 'CPPFLAGS ?= $(value CPPFLAGS)'"\n" >> $(@D)/.config
	printf 'CFLAGS ?= $(value CFLAGS)'"\n" >> $(@D)/.config
	printf 'LDFLAGS ?= $(value LDFLAGS)'"\n" >> $(@D)/.config
	printf 'SOFLAGS ?= $(value SOFLAGS)'"\n" >> $(@D)/.config
	printf 'AR ?= $(value AR)'"\n" >> $(@D)/.config
	printf 'RANLIB ?= $(value RANLIB)'"\n" >> $(@D)/.config
	printf 'M4 ?= $(value M4)'"\n" >> $(@D)/.config
	printf 'RM ?= $(value RM)'"\n" >> $(@D)/.config
	printf 'CP ?= $(value CP)'"\n" >> $(@D)/.config
	printf 'RMDIR ?= $(value RMDIR)'"\n" >> $(@D)/.config
	printf 'MKDIR ?= $(value MKDIR)'"\n" >> $(@D)/.config
	printf 'CHMOD ?= $(value CHMOD)'"\n" >> $(@D)/.config
	printf 'INSTALL ?= $(value INSTALL)'"\n" >> $(@D)/.config
	printf 'INSTALL_DATA ?= $(value INSTALL_DATA)'"\n" >> $(@D)/.config

# add local targets if building from inside project tree
ifneq "$(filter $(abspath $(d)/..)/%, $(abspath $(firstword $(MAKEFILE_LIST))))" ""
.PHONY: config configure

config configure: $(d)/config
endif


#
# S H A R E D  C O M P I L A T I O N  F L A G S
#
cc-option ?= $(shell if $(CC) $(1) -S -o /dev/null -xc /dev/null \
             > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi;)

VENDOR_OS_$(d) := $(shell $(d)/mk/vendor.os)
VENDOR_CC_$(d) := $(shell env CC="$(CC)" $(d)/mk/vendor.cc)

ifneq ($(VENDOR_OS_$(d)), OpenBSD)
CPPFLAGS_$(d) += -D_REENTRANT -D_THREAD_SAFE -D_GNU_SOURCE
endif

ifeq ($(VENDOR_OS_$(d)), SunOS)
CPPFLAGS_$(d) += -Usun -D_XPG4_2 -D__EXTENSIONS__
endif

ifeq ($(VENDOR_CC_$(d)), gcc)
CFLAGS_$(d) += -O2 -std=gnu99 -fPIC
CFLAGS_$(d) += -g -Wall -Wextra $(call cc-option, -Wno-missing-field-initializers) $(call cc-option, -Wno-override-init) -Wno-unused
endif

ifeq ($(VENDOR_CC_$(d)), clang)
CFLAGS_$(d) += -O2 -std=gnu99 -fPIC
CFLAGS_$(d) += -g -Wall -Wextra -Wno-missing-field-initializers -Wno-initializer-overrides -Wno-unused
endif

ifeq ($(VENDOR_CC_$(d)), sunpro)
CFLAGS_$(d) += -xcode=pic13
CFLAGS_$(d) += -g
endif

ifeq ($(VENDOR_OS_$(d)), Darwin)
CFLAGS_$(d) += -Wno-deprecated-declarations
endif

ifeq ($(VENDOR_OS_$(d)), Darwin)
SOFLAGS_$(d) += -bundle -undefined dynamic_lookup
else
SOFLAGS_$(d) += -shared
endif


#
# P R O J E C T  R U L E S
#
include $(d)/src/GNUmakefile


#
# C L E A N  R U L E S
#
.PHONY: $(d)/clean~ clean~

$(d)/clean~:
	$(RM) -f $(@D)/*~

clean~: $(d)/clean~


#
# D E B I A N  R U L E S
#
ifneq "$(filter $(abspath $(d))/%, $(abspath $(firstword $(MAKEFILE_LIST))))" ""

DPKG_BUILDPACKAGE ?= dpkg-buildpackage
FAKEROOT ?= fakeroot
DPKG_BUILDPACKAGE_OPTIONS ?= -b -uc -us

.PHONY: $(d)/debian $(d)/debian-clean debian deb debian-clean deb-clean

$(d)/debian:
	cd $(@D) && $(DPKG_BUILDPACKAGE) -rfakeroot $(DPKG_BUILDPACKAGE_OPTIONS)

$(d)/debian-clean:
	cd $(@D) && $(FAKEROOT) ./debian/rules clean

debian deb: $(d)/debian

debian-clean deb-clean: $(d)/debian-clean

endif # debian guard


#
# R E D H A T  R U L E S
#
ifneq "$(filter $(abspath $(d))/%, $(abspath $(firstword $(MAKEFILE_LIST))))" ""
.PHONY: $(d)/redhat $(d)/redhat-clean redhat rpm redhat-clean rpm-clean

redhat rpm: $(d)/redhat

redhat-clean rpm-clean: $(d)/redhat-clean

endif # redhat guard


#
# R E L E A S E  T A R B A L L  R U L E S
#
ifneq "$(filter $(abspath $(d))/%, $(abspath $(firstword $(MAKEFILE_LIST))))" ""

LUAOSSL_VERSION := $(shell $(d)/mk/changelog version)

.PHONY: $(d)/luaossl-$(LUAOSSL_VERSION).tgz release

$(d)/luaossl-$(LUAOSSL_VERSION).tgz:
	cd $(@D) && git archive --format=tar --prefix=$(basename $(@F))/ HEAD | gzip -c > $@

release: $(d)/luaossl-$(LUAOSSL_VERSION).tgz

endif # release guard


endif # include guard

# non-recursive epilogue
d := $(dirstack_$(sp))
sp := $(basename $(sp))