1#!/usr/bin/make -f
2# Sample debian/rules that uses debhelper.
3# GNU copyright 1997 to 1999 by Joey Hess.
4
5DEBVERSION:=$(shell head -n 1 debian/changelog \
6                    | sed -e 's/^[^(]*(\([^)]*\)).*/\1/')
7UPVERSION:=$(shell dpkg-parsechangelog | sed -ne 's/^Version: \(\([0-9]\+\):\)\?\(.*\)-.*/\3/p')
8
9FILENAME := kamailio_$(UPVERSION).orig.tar.gz
10URL := http://www.kamailio.org/pub/kamailio/$(UPVERSION)/src/kamailio-$(UPVERSION)_src.tar.gz
11
12DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
13
14export DEB_BUILD_MAINT_OPTIONS = hardening=+all
15DPKG_EXPORT_BUILDFLAGS = 1
16include /usr/share/dpkg/buildflags.mk
17
18# Uncomment this to turn on verbose mode.
19#export DH_VERBOSE=1
20
21export JAVA_HOME=/usr/lib/jvm/java-gcj
22export FREERADIUS=1
23
24# modules not in the "main" kamailio package
25EXCLUDED_MODULES=
26
27# extra modules to skip, because they are not compilable now
28# - regardless if they go to the main kamailio package or to some module package,
29# they will be excluded from compile and install of all
30EXTRA_EXCLUDED_MODULES=bdb dbtext oracle pa iptrtpproxy mi_xmlrpc geoip2 phonenum mongodb
31
32# module groups that are packaged in seperate packages
33# (with the name kamailio-$(group_name)-modules)
34# Note: the order is important (should be in dependency order, the one
35# on which other depend first)
36PACKAGE_GROUPS=mysql postgres berkeley unixodbc radius presence \
37			   ldap xml perl utils lua memcached \
38			   snmpstats carrierroute xmpp cpl redis python geoip \
39			   sqlite json mono ruby ims sctp java \
40			   tls outbound websocket autheph dnssec kazoo cnxcc \
41			   erlang systemd rabbitmq python3 mqtt
42
43# module groups to be packaged onto kamailio-extra-modules
44EXTRA_GROUPS=gzcompress uuid ev jansson http_async
45
46# name of libdir in the path for libraries (e.g., lib for 32b, lib64 for 64b)
47export LIBDIR ?= lib/$(DEB_HOST_MULTIARCH)
48
49# directories with possible duplicate libraries (that should be deleted
50# from current module* packages)
51DUP_LIBS_DIRS=$(CURDIR)/debian/kamailio/usr/$(LIBDIR)/kamailio \
52			$(CURDIR)/debian/kamailio-db-modules/usr/$(LIBDIR)/kamailio
53
54# "function" to get package short name out of a dir/module_name
55# it also transforms db_foo into foo
56mod_name=$(subst db_,,$(lastword $(subst /, ,$(1))))
57
58define PACKAGE_GRP_BUILD_template
59	# package all the modules in PACKAGE_GROUPS in separate packages
60	$(foreach grp,$(PACKAGE_GROUPS),\
61		$(MAKE) every-module group_include="k$(grp)" quiet=verbose
62	)
63endef
64
65define PACKAGE_GRP_INSTALL_template
66	$(foreach grp,$(PACKAGE_GROUPS),\
67		$(MAKE) install-modules-all LIBDIR=$(LIBDIR) group_include="k$(grp)" \
68		BASEDIR=$(CURDIR)/debian/kamailio-$(grp)-modules \
69		cfg_prefix=$(CURDIR)/debian/kamailio-$(grp)-modules \
70		doc-dir=share/doc/kamailio-$(grp)-modules quiet=verbose
71		# eliminate duplicate libs
72		-for d in $(DUP_LIBS_DIRS); do \
73			test "$$d" != "$(CURDIR)/debian/kamailio-$(grp)-modules/usr/$(LIBDIR)/kamailio" &&\
74			for r in `find $$d -name 'lib*'|xargs`; do \
75				echo "removing $(grp) lib `basename $$r` present also in $$d";\
76				rm -f $(CURDIR)/debian/kamailio-$(grp)-modules/usr/$(LIBDIR)/kamailio/`basename "$$r"` ; \
77			done ; \
78		done
79		find $(CURDIR)/debian/kamailio-$(grp)-modules -depth -empty -type d -exec rmdir {} \;
80	)
81endef
82
83define PACKAGE_EXTRA_BUILD_template
84	# package all the modules in EXTRA_GROUPS in separate packages
85	$(foreach grp,$(EXTRA_GROUPS),\
86		$(MAKE) every-module group_include="k$(grp)" quiet=verbose
87	)
88endef
89
90define PACKAGE_EXTRA_INSTALL_template
91	$(foreach grp,$(EXTRA_GROUPS),\
92		$(MAKE) install-modules-all LIBDIR=$(LIBDIR) group_include="k$(grp)" \
93		BASEDIR=$(CURDIR)/debian/kamailio-extra-modules \
94		cfg_prefix=$(CURDIR)/debian/kamailio-extra-modules \
95		doc-dir=share/doc/kamailio-extra-modules quiet=verbose
96	)
97	# eliminate duplicate libs
98	-for d in $(DUP_LIBS_DIRS); do \
99		test "$$d" != "$(CURDIR)/debian/kamailio-extra-modules/usr/$(LIBDIR)/kamailio" &&\
100		for r in `find $$d -name 'lib*'|xargs`; do \
101			echo "removing extra lib `basename $$r` present also in $$d";\
102			rm -f $(CURDIR)/debian/kamailio-extra-modules/usr/$(LIBDIR)/kamailio/`basename "$$r"` ; \
103		done ; \
104	done
105	find $(CURDIR)/debian/kamailio-extra-modules -depth -empty -type d -exec rmdir {} \;
106endef
107
108# CFLAGS + CPPFLAGS -> CC_EXTRA_OPTS
109CC_EXTRA_OPTS := $(shell dpkg-buildflags --get CPPFLAGS)
110CC_EXTRA_OPTS += $(shell DEB_CFLAGS_MAINT_STRIP=-O2 dpkg-buildflags --get CFLAGS)
111CXXFLAGS := $(shell DEB_CXXFLAGS_MAINT_STRIP=-O2 dpkg-buildflags --get CXXFLAGS)
112# LDFLAGS -> LD_EXTRA_OPTS
113LD_EXTRA_OPTS := $(shell dpkg-buildflags --get LDFLAGS)
114
115# https://wiki.debian.org/ReproducibleBuilds/
116CC_EXTRA_OPTS += -DVERSION_NODATE
117
118configure: configure-stamp
119configure-stamp:
120	dh_testdir
121	# Add here commands to configure the package.
122	$(MAKE) FLAVOUR=kamailio cfg prefix=/usr cfg_prefix=$(CURDIR)/debian/kamailio \
123			cfg_target=/etc/kamailio/ \
124			BASEDIR=$(CURDIR)/debian/kamailio \
125			skip_modules="$(EXCLUDED_MODULES) $(EXTRA_EXCLUDED_MODULES)" \
126			CC_EXTRA_OPTS="$(CC_EXTRA_OPTS)" \
127			LD_EXTRA_OPTS="$(LD_EXTRA_OPTS)" \
128			group_include="kstandard" quiet=verbose
129
130	touch configure-stamp
131
132
133build: build-stamp
134build-arch: build-stamp
135build-indep: build-stamp
136build-stamp: configure-stamp
137	dh_testdir
138	# Add here commands to compile the package.
139	$(MAKE) all quiet=verbose
140	# make groups
141	$(call PACKAGE_GRP_BUILD_template)
142	$(call PACKAGE_EXTRA_BUILD_template)
143	touch build-stamp
144
145clean:
146	dh_testdir
147	dh_testroot
148	rm -f build-stamp configure-stamp
149	# Add here commands to clean up after the build process.
150	$(MAKE) maintainer-clean
151	dh_clean
152
153install: build
154	dh_testdir
155	dh_testroot
156	dh_prep
157	dh_installdirs
158	# Add here commands to install the package into debian/kamailio
159	$(MAKE) install group_include="kstandard"
160	# make group packages
161	$(call PACKAGE_GRP_INSTALL_template)
162	$(call PACKAGE_EXTRA_INSTALL_template)
163	mv $(CURDIR)/debian/kamailio-berkeley-modules/usr/sbin/kambdb_recover \
164		$(CURDIR)/debian/kamailio-berkeley-bin/usr/sbin/kambdb_recover
165	# install /etc/default/kamailio file
166	mkdir -p $(CURDIR)/debian/kamailio/etc/default
167	cp -f debian/kamailio.default $(CURDIR)/debian/kamailio/etc/default/kamailio
168	# delete /run/kamailio dir
169	rm -rf $(CURDIR)/debian/kamailio/usr/local
170
171
172# This single target is used to build all the packages, all at once, or
173# one at a time. So keep in mind: any options passed to commands here will
174# affect _all_ packages. Anything you want to only affect one package
175# should be put in another target, such as the install target.
176binary-common:
177	dh_testdir
178	dh_testroot
179	dh_installdebconf
180	dh_installdocs
181	dh_installexamples -Xobsoleted -Xsr
182	dh_installmenu
183	dh_systemd_enable -pkamailio
184	dh_installinit -pkamailio -- defaults 23
185	dh_systemd_start -pkamailio
186	dh_installcron
187	dh_installman
188	dh_installinfo
189	dh_lintian
190	dh_installchangelogs ChangeLog
191	dh_link
192	dh_strip --dbg-package=kamailio-dbg
193	dh_compress
194	dh_fixperms
195	dh_makeshlibs
196	dh_installdeb
197	dh_shlibdeps
198	dh_gencontrol
199	dh_md5sums
200	dh_builddeb
201
202# Build architecture-independent packages using the common target
203binary-indep: build install
204# (Uncomment this next line if you have such packages.)
205#        $(MAKE) -f debian/rules DH_OPTIONS=-i binary-common
206# We have nothing to do by default.
207
208
209# Build architecture-dependent packages using the common target
210binary-arch: build install
211	$(MAKE) -f debian/rules DH_OPTIONS=-a binary-common
212
213# Any other binary targets build just one binary package at a time.
214binary-%: build install
215	$(MAKE) -f debian/rules binary-common DH_OPTIONS=-p$*
216
217print-version:
218	@@echo "Debian version:          $(DEBVERSION)"
219	@@echo "Upstream version:        $(UPVERSION)"
220
221get-orig-source:
222	@@dh_testdir
223	@@[ -d ../tarballs/. ]||mkdir -p ../tarballs
224	@@echo Downloading $(FILENAME) from $(URL) ...
225	@@wget -nv -T10 -t3 -O ../tarballs/$(FILENAME) $(URL)
226
227binary: binary-indep binary-arch
228.PHONY: build clean binary-indep binary-arch binary install configure
229
230