File: Makefile.Debian.single

package info (click to toggle)
lua5.1-policy 33
  • links: PTS, VCS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, stretch, wheezy
  • size: 140 kB
  • ctags: 16
  • sloc: sh: 45; ansic: 42; makefile: 30
file content (340 lines) | stat: -rw-r--r-- 12,506 bytes parent folder | download | duplicates (2)
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
### $Id: Makefile.Debian 213 2006-09-16 11:35:46Z gareuselesinge $
### vim: foldmethod=marker

LUA_POLICY_PATH=/usr/share/lua5.1-policy-dev/
C_TEST_FILE=$(LUA_POLICY_PATH)app.c
CONFIGURATION_FILE=debian/Makefile.Debian.conf

include $(CONFIGURATION_FILE)

### {{{ a bunch of definitions (standard at least for debian)
### you should not need to change this
PKG_NAME_DASH=$(subst .,-,$(PKG_NAME))
PREFIX=$(DESTDIR)/usr/
LUA_VERSION=5.1
LUA=lua$(LUA_VERSION)
# liblua5.1-foo
LIBNAME=lib$(LUA)-$(PKG_NAME_DASH)
PKG_CONF_NAME=$(LUA)-$(PKG_NAME_DASH).pc
LBTL=libtool --silent --tag=CC
PKGCONF=pkg-config $(LUA) --define-variable=prefix=$(PREFIX)
GCC_FLAGS= -g -Wall -O2 $(LUA_CFLAGS) $(CLIB_CFLAGS) 
# liblua5.1-foo.so.0.0.0
REALSO=$(LIBNAME).so.$(subst :,.,$(VERSION_INFO))
# -I/usr/include/lua5.1
LUA_CFLAGS = $(shell $(PKGCONF) --cflags)
# /usr/lib/liblua5.1.la
LUA_LBTL_S = $(shell $(PKGCONF) --libs --static)
LUA_LBTL_D = $(shell $(PKGCONF) --libs)
# /usr/lib/, /usr/lib/lua/5.1, /usr/share/lua/5.1/
LUA_CPATH=$(shell $(PKGCONF) --variable=INSTALL_CMOD)
LUA_SPATH=$(shell $(PKGCONF) --variable=INSTALL_LMOD)
DEB_HOST_MULTIARCH=$(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
LUA_LPATH=$(PREFIX)/lib/$(DEB_HOST_MULTIARCH)
# /usr/include/lua5.1
LUA_HPATH=$(shell $(PKGCONF) --variable=includedir)/$(LUA)
# debian packages name and derivates
_DEB_PKG=lib$(LUA)-$(PKG_NAME_DASH)
DEB_PKG_LIB=$(_DEB_PKG)$(DEB_EXTRA_DASH)$(shell echo $(VERSION_INFO) | cut -d : -f 1)
DEB_PKG_DEV=$(_DEB_PKG)-dev
ifeq "$(LUA_HEADER)" ""
  LUA_HEADER=lua-$(PKG_NAME_DASH).h
endif
ifeq "$(LUA_MODNAME)" ""
  LUA_MODNAME=$(PKG_NAME)
endif
ifeq "$(LUA_MODNAME_CPART)" ""
  LUA_MODNAME_CPART=$(LUA_MODNAME)
endif
# luasql.mysql -> /usr/lib/lua/5.1/sql/mysql
LUA_MODNAME_PATH=$(subst .,/,$(LUA_MODNAME_CPART))
# luaopen_luasql_mysql(lua_State* L)
LUA_MODNAME_CPART_UNDERSCORE=$(subst .,_,$(LUA_MODNAME_CPART))
# depending on the nesting, a '../' for every level
LUA_MODNAME_DOTS=$(shell echo $(LUA_MODNAME_CPART) | sed 's/[^\.]//g' | sed 's/\./..\//g')
C_TEST_FILE_STAMP=ctestfile-stamp.$(PKG_NAME)
DEB_INST_LIB=debian/$(DEB_PKG_LIB).install
DEB_INST_DEV=debian/$(DEB_PKG_DEV).install
DEB_INSTALLS=$(DEB_INST_LIB) $(DEB_INST_DEV)
# debian .install generation
DEB_PKGCONF_INST=usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/$(PKG_CONF_NAME)
DEB_PKGCONF_INST_REX=\/?usr\/lib\/.*\/pkgconfig\/
DEB_HEADERS_INST=usr/include/$(LUA)/$(shell basename $(LUA_HEADER))
DEB_HEADERS_INST_REX=\/?usr\/include\/$(LUA)\/
DEB_LUA_INST=usr/share/lua/$(LUA_VERSION)/*
DEB_LUA_INST_REX=\/?usr\/share\/lua\/$(LUA_VERSION)\/
DEB_LIBSO_INST=usr/lib/$(DEB_HOST_MULTIARCH)/$(LIBNAME).so
DEB_LIBSO_INST_REX=\/?usr\/lib\/.*\.so
DEB_LIBA_INST=usr/lib/$(DEB_HOST_MULTIARCH)/$(LIBNAME).a
DEB_LIBA_INST_REX=\/?usr\/lib\/$(DEB_HOST_MULTIARCH)\/.*\.a
DEB_LIBSOABI_INST=usr/lib/$(DEB_HOST_MULTIARCH)/$(LIBNAME).so.*
DEB_LIBSOABI_INST_REX=\/?usr\/lib\/$(DEB_HOST_MULTIARCH)\/.*\.so\..*
DEB_LIBSOM_INST=usr/lib/$(DEB_HOST_MULTIARCH)/lua/$(LUA_VERSION)/$(LUA_MODNAME_PATH).so
DEB_LIBSOM_INST_REX=\/?usr\/lib\/$(DEB_HOST_MULTIARCH)\/lua\/$(LUA_VERSION)\/.*\.so
# common utilities
GREP=egrep
ECHO=echo 
# to help crosscompiling
DEB_BUILD_ARCH=$(shell dpkg-architecture -qDEB_BUILD_ARCH)
DEB_HOST_ARCH=$(shell dpkg-architecture -qDEB_HOST_ARCH)
### }}}

.PHONY: all clean test install

# ---------------------- Here starts the Makefile ------------------------------

# {{{ entrypoints 
ifeq "$(CLIB_OBJS)" ""
all: pre-all-hook $(DEB_INSTALLS) post-all-hook
test: pre-test-hook test-lua-dynamic 
install: pre-install-hook installcommon post-install-hook
else
all: pre-all-hook $(LIBNAME).la $(PKG_CONF_NAME) $(DEB_INSTALLS) post-all-hook
test: $(LIBNAME).la pre-test-hook test-lua-dynamic test-app-dynamic test-app-static
install: pre-install-hook installcommon installso post-install-hook
endif
clean: pre-clean-hook clean1 post-clean-hook
# }}}

# ---------------------------- Testing -----------------------------------------

# {{{ test the module, from lua and from a dynamically/statically linked C app
test-lua-dynamic-fake:
	@echo "********************** lua dynamic **************************"
	@echo SKIPPED!
	@echo "*************************************************************"

test-app-static-fake:
	@echo "*********************** app static **************************"
	@echo SKIPPED!
	@echo "*************************************************************"

test-app-dynamic-test:
	@echo "********************** app dynamic **************************"
	@echo SKIPPED!
	@echo "*************************************************************"

test-lua-dynamic-real:
	@echo "********************** lua dynamic **************************"
	HOME=$(shell pwd)/debian LUA_INIT= SEGFAULT_SIGNALS=all catchsegv \
	     $(LUA) -l $(LUA_MODNAME) $(LUA_TEST)
	@echo "*************************************************************"

test-app-static-real:
	@echo "*********************** app static **************************"
	ldd ./app
	HOME=$(shell pwd)/debian LUA_INIT= SEGFAULT_SIGNALS=all \
	     catchsegv ./app $(LUA_TEST)
	@echo "*************************************************************"

test-app-dynamic-real:
	@echo "********************** app dynamic **************************"
	$(LBTL) --mode=execute -dlopen $(LIBNAME).la ldd ./.libs/app
	HOME=$(shell pwd)/debian LUA_INIT= SEGFAULT_SIGNALS=all \
	     $(LBTL) --mode=execute -dlopen $(LIBNAME).la \
	     catchsegv ./app $(LUA_TEST)
	@echo "*************************************************************"

ifeq "$(LUA_TEST)" "" 
test-lua-dynamic: pre-lua-dynamic-test-hook test-lua-dynamic-fake
test-app-static: static-stamp.$(PKG_NAME) pre-app-static-test-hook test-app-static-fake
test-app-dynamic: dynamic-stamp.$(PKG_NAME) pre-app-dynamic-test-hook test-app-dynamic-test
else
ifneq "$(DEB_HOST_ARCH)" "$(DEB_BUILD_ARCH)"
test-lua-dynamic: pre-lua-dynamic-test-hook test-lua-dynamic-fake
test-app-static: static-stamp.$(PKG_NAME) pre-app-static-test-hook test-app-static-fake
test-app-dynamic: dynamic-stamp.$(PKG_NAME) pre-app-dynamic-test-hook test-app-dynamic-test
else
test-lua-dynamic: pre-lua-dynamic-test-hook test-lua-dynamic-real
test-app-static: static-stamp.$(PKG_NAME) pre-app-static-test-hook test-app-static-real 
test-app-dynamic: dynamic-stamp.$(PKG_NAME) pre-app-dynamic-test-hook test-app-dynamic-real
endif
endif
# }}}

# ------------------------- Installation ---------------------------------------
  
# {{{ install static and dynamic libraries for module to global location
installso: $(LIBNAME).la $(PKG_CONF_NAME) $(DEB_INSTALLS) $(LUA_HEADER)
	# .so installation
	# $(LUA_MODNAME) installation (symlink to .so)
	# FIXME ../../ should be 
	mkdir -p $(LUA_CPATH)
	mkdir -p $(LUA_LPATH)
	$(LBTL) --mode=install install $(LIBNAME).la \
		$(LUA_LPATH)/$(LIBNAME).la
	$(LBTL) --finish $(LUA_LPATH)
	cd $(LUA_CPATH); \
		mkdir -p $(dir $(LUA_MODNAME_PATH));\
		ln -s $(LUA_MODNAME_DOTS)../../$(REALSO) $(LUA_MODNAME_PATH).so
	# .install
	for X in $(DEB_INST_LIB)  $(DEB_INST_DEV); do\
		if [ -e $$X -a ! -e install.in-stamp.$(PKG_NAME).`basename $$X | sed 's?.install$$??'` ]; then\
			echo;\
			echo -e "\t\t*** WARNING: user provided $$X found and ignored";\
			echo -e "\t\t*** WARNING: please use an .install.in";\
			echo;\
			cp $$X $$X.backup;\
		fi;\
	done
	$(GREP) '$(DEB_LIBSOM_INST_REX)' $(DEB_INST_LIB) || \
		$(ECHO) "$(DEB_LIBSOM_INST)" >> $(DEB_INST_LIB)
	$(GREP) '$(DEB_LIBSOABI_INST_REX)' $(DEB_INST_LIB) || \
		$(ECHO) "$(DEB_LIBSOABI_INST)" >> $(DEB_INST_LIB)
	$(GREP) '$(DEB_LIBSO_INST_REX)' $(DEB_INST_DEV) || \
		$(ECHO) "$(DEB_LIBSO_INST)" >> $(DEB_INST_DEV)
	$(GREP) '$(DEB_LIBA_INST_REX)' $(DEB_INST_DEV) || \
		$(ECHO) "$(DEB_LIBA_INST)" >> $(DEB_INST_DEV)
	# .pc
	mkdir -p $(LUA_LPATH)/pkgconfig/
	$(LBTL) --mode=install install -m 0644 $(PKG_CONF_NAME) \
		$(LUA_LPATH)/pkgconfig/
	$(GREP) '$(DEB_PKGCONF_INST_REX)' $(DEB_INST_DEV) || \
		$(ECHO) "$(DEB_PKGCONF_INST)" >> $(DEB_INST_DEV)
	# .h
	if [ ! -z "$(LUA_HEADER)" ]; then\
		mkdir -p $(LUA_HPATH);\
		$(LBTL) --mode=install install -m 0644 \
			$(LUA_HEADER) $(LUA_HPATH)/;\
		$(GREP) '$(DEB_HEADERS_INST_REX)' $(DEB_INST_DEV) || \
			$(ECHO) "$(DEB_HEADERS_INST)" >> $(DEB_INST_DEV);\
	fi

installcommon: $(DEB_INSTALLS)
	if [ ! -z "$(LUA_SOURCES)" ]; then\
		mkdir -p $(LUA_SPATH);\
		cp -r $(LUA_SOURCES) $(LUA_SPATH)/;\
		$(GREP) '$(DEB_LUA_INST_REX)' $(DEB_INST_LIB) || \
			$(ECHO) "$(DEB_LUA_INST)" >> $(DEB_INST_LIB);\
	fi
# }}}

# ------------------------- C compilation --------------------------------------

# {{{ compilation rules: .lo .la app
%.lo: %.c
	$(LBTL) --mode=compile $(CC) -c $(GCC_FLAGS) -o $@ $< 

$(C_TEST_FILE_STAMP):$(C_TEST_FILE).conf.in $(LUA_HEADER)
	cp $< `basename $(C_TEST_FILE).conf`
	sed -i 's?@@LUA_HEADER@@?$(LUA_HEADER)?' `basename $(C_TEST_FILE).conf`
	sed -i \
	 's?@@LUA_MODNAME_CPART_UNDERSCORE@@?$(LUA_MODNAME_CPART_UNDERSCORE)?'\
	 `basename $(C_TEST_FILE).conf`
	sed -i 's?@@LUA_MODNAME_CPART@@?$(LUA_MODNAME_CPART)?' \
	 `basename $(C_TEST_FILE).conf`
	touch $(C_TEST_FILE_STAMP)

$(LIBNAME).la $(LUA_MODNAME_PATH).so: $(CLIB_OBJS)
	$(LBTL) --mode=link $(CC) \
	    -rpath $(LUA_LPATH) -o $(LIBNAME).la \
	    -version-info $(VERSION_INFO) \
	    -Wl,--no-add-needed \
	    $(CLIB_OBJS) $(CLIB_LDFLAGS)
	mkdir -p $(dir $(LUA_MODNAME_PATH))
	ln -sf $(LUA_MODNAME_DOTS)./.libs/$(REALSO) $(LUA_MODNAME_PATH).so

app static-stamp.$(PKG_NAME): $(C_TEST_FILE_STAMP) $(LIBNAME).la pre-static-link-hook 
	rm -f dynamic-stamp.$(PKG_NAME)
	$(LBTL) --mode=link $(CC) -Wall -O2 $(GCC_FLAGS) -Wl,--no-add-needed \
		-static -o app -I . \
		$(C_TEST_FILE) $(LIBNAME).la \
		$(CLIB_LDFLAGS_STATIC) $(LUA_LBTL_S)
	touch static-stamp.$(PKG_NAME)

./.libs/app dynamic-stamp.$(PKG_NAME): $(C_TEST_FILE_STAMP) $(LIBNAME).la pre-dynamic-link-hook 
	rm -f static-stamp.$(PKG_NAME)
	$(LBTL) --mode=link $(CC) -Wall -O2 $(GCC_FLAGS) -Wl,--no-add-needed \
		-o app -I . \
		$(C_TEST_FILE) $(LIBNAME).la \
		$(CLIB_LDFLAGS) $(LUA_LBTL_D)
	touch dynamic-stamp.$(PKG_NAME)

# }}}

# ------------------------- .in processing -------------------------------------

# {{{ pkgconfig, .install and (evental) .h generation
$(PKG_CONF_NAME): $(LUA_POLICY_PATH)pkg-config.pc.in
	cat $< | \
	sed 's|@@PKG_VERSION@@|$(PKG_VERSION)|' | \
	sed 's|@@PKG_NAME@@|$(PKG_NAME_DASH)|' | \
	sed 's|@@PKG_LUA@@|$(LUA)|' | \
	sed 's|@@PKG_LIBS_PRIVATE@@|$(PKG_LIBS_PRIVATE)|' | \
	sed 's|@@PKG_URL@@|$(PKG_URL)|' | \
	sed 's|@@PKG_REQUIRES@@|$(PKG_REQUIRES)|' | \
	sed 's|@@PKG_CONFLICTS@@|$(PKG_CONFLICTS)|' \
		> $@

debian/%.install:
	if [ -e $@.in ]; then\
		cat $@.in | sed 's|@@LUA_VERSION@@|$(LUA_VERSION)|' | \
			sed 's|@@DEB_HOST_MULTIARCH@@|$(DEB_HOST_MULTIARCH)|' > $@;\
	else\
		touch $@;\
	fi;\
	touch install.in-stamp.$(PKG_NAME).$*

$(LUA_HEADER):
	echo "/* This file has been automatically generated by lua5.1-policy-dev */" > $@
	echo >> $@
	echo "extern int luaopen_$(LUA_MODNAME_CPART_UNDERSCORE)(lua_State*);" >> $@
	echo >> $@
	echo "/* eof */" >> $@
	touch header-stamp.$(PKG_NAME)

# }}}

# ------------------------- Not interesting stuff ------------------------------

# {{{ hooks in CDBS style
pre-all-hook ::
	@echo pre-all-hook 
post-all-hook::
	@echo post-all-hook
pre-test-hook ::
	@echo pre-test-hook
pre-install-hook ::
	@echo pre-install-hook 
post-install-hook ::
	@echo post-install-hook
pre-static-link-hook ::
	@echo pre-static-link-hook 
pre-dynamic-link-hook::
	@echo pre-dynamic-link-hook
pre-lua-dynamic-test-hook::
	@echo pre-lua-dynamic-test-hook
pre-app-static-test-hook ::
	@echo pre-app-static-test-hook 
pre-app-dynamic-test-hook ::
	@echo pre-app-dynamic-test-hook 
pre-clean-hook::
	@echo pre-clean-hook
post-clean-hook::
	@echo post-clean-hook
# }}}

# {{{ some trivial rules
clean1:
	$(RM) -f $(CLIB_OBJS:%.lo=%.o) $(CLIB_OBJS) $(LIBNAME).la app
	rm -f $(LUA_MODNAME_PATH).so
	rmdir $(dir $(LUA_MODNAME_PATH)) || true
	$(RM) -rf $(foreach x,$(CLIB_OBJS),$(dir $(x)).libs/) .libs/
	$(RM) -rf $(C_TEST_FILE).conf $(PKG_CONF_NAME)
	if [ -e header-stamp.$(PKG_NAME) ]; then $(RM) -f $(LUA_HEADER); fi
	if [ -n "`ls debian/*.install.backup 2>/dev/null`" ]; then\
		for X in debian/*.install.backup; do\
			mv $$X debian/`basename $$X .backup`;\
		done;\
	fi
	for X in install.in-stamp.$(PKG_NAME).*; do\
		if [ -e $$X ]; then\
			$(RM) -f $${X#install.in-stamp.$(PKG_NAME).};\
		fi;\
	done
	$(RM) -f static-stamp.$(PKG_NAME) dynamic-stamp.$(PKG_NAME) 
	$(RM) -f header-stamp.$(PKG_NAME) install.in-stamp.$(PKG_NAME).*
	$(RM) -f $(C_TEST_FILE_STAMP)
# }}}

# eof