summaryrefslogtreecommitdiffstats
path: root/debian/rules
blob: ce3086916f91d1009252c1813e4f78d0a15b032e (plain)
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
#!/usr/bin/make -f
include debian/make.mk

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

$(call lazy,DEB_BUILD_ARCH,$$(shell dpkg-architecture -qDEB_BUILD_ARCH))
$(call lazy,DEB_BUILD_GNU_TYPE,$$(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE))
$(call lazy,DEB_HOST_ARCH,$$(shell dpkg-architecture -qDEB_HOST_ARCH))
$(call lazy,DEB_HOST_ARCH_OS,$$(shell dpkg-architecture -qDEB_HOST_ARCH_OS))
$(call lazy,DEB_HOST_GNU_TYPE,$$(shell dpkg-architecture -qDEB_HOST_GNU_TYPE))
$(call lazy,DEB_HOST_GNU_CPU,$$(shell dpkg-architecture -qDEB_HOST_GNU_CPU))
$(call lazy,DEB_HOST_MULTIARCH,$$(shell dpkg-architecture -qDEB_HOST_MULTIARCH))
$(call lazy,CFLAGS,$$(shell dpkg-buildflags --get CFLAGS))
$(call lazy,CPPFLAGS,$$(shell dpkg-buildflags --get CPPFLAGS))
$(call lazy,LDFLAGS,$$(shell dpkg-buildflags --get LDFLAGS))

PREPROCESS_FILES := $(wildcard debian/*.in) nss/pkg/pkg-config/nss-config.in
PREPROCESSED_FILES := $(addprefix debian/,$(notdir $(PREPROCESS_FILES:.in=)))

$(filter debian/%,$(PREPROCESS_FILES:.in=)): %: %.in
debian/nss-config: nss/pkg/pkg-config/nss-config.in
$(PREPROCESSED_FILES):
	sed 's,/@DEB_HOST_MULTIARCH@,$(DEB_HOST_MULTIARCH:%=/%),g;$(EXTRA_REPLACES)' $< > $@

UPSTREAM_VERSION := $(shell dpkg-parsechangelog | sed -n 's/^Version: *\([0-9]*:\)\?\([0-9.]*+really\)\?\([^~]*\)\(~.*\)\?-.*$$/\3/ p')
MOD_MAJOR_VERSION := $(word 1, $(subst ., ,$(UPSTREAM_VERSION)))
MOD_MINOR_VERSION := $(word 2, $(subst ., ,$(UPSTREAM_VERSION)))
MOD_PATCH_VERSION := $(or $(word 3, $(subst ., ,$(UPSTREAM_VERSION))),0)

debian/nss.pc: EXTRA_REPLACES := s/@VERSION@/$(UPSTREAM_VERSION)/
debian/nss-config: EXTRA_REPLACES := s/@MOD_MAJOR_VERSION@/$(MOD_MAJOR_VERSION)/;s/@MOD_MINOR_VERSION@/$(MOD_MINOR_VERSION)/;s/@MOD_PATCH_VERSION@/$(MOD_PATCH_VERSION)/;s/@prefix@/\/usr/
debian/libnss3.lintian-overrides: EXTRA_REPLACES := s,/@DEB_HOST_MULTIARCH_WC@,$(DEB_HOST_MULTIARCH:%=/*),g

TOOLCHAIN :=

ifneq ($(DEB_HOST_ARCH),$(DEB_BUILD_ARCH))
ifeq ($(origin CC),default)
TOOLCHAIN += CC=$(DEB_HOST_GNU_TYPE)-gcc
endif
ifeq ($(origin CXX),default)
CXX := $(DEB_HOST_GNU_TYPE)-g++
TOOLCHAIN += CXX=$(CXX)
endif
TOOLCHAIN += CCC=$(CXX)
ifeq ($(origin RANLIB),default)
TOOLCHAIN += RANLIB=$(DEB_HOST_GNU_TYPE)-ranlib
endif
TOOLCHAIN += OS_TEST=$(DEB_HOST_GNU_CPU)
TOOLCHAIN += KERNEL=$(DEB_HOST_ARCH_OS)
endif

# $(foreach foo,$(list),$(call cmd,some command $(foo))) expands to
#    some command first-elem
#    some command second-elem
#    etc.
# This avoid using a long one liner with semi colons.
define cmd
$(1)

endef

CFLAGS += -Wall -pipe

DISTDIR := $(CURDIR)/dist

COMMON_MAKE_FLAGS := \
	$(and $(filter terse,$(DEB_BUILD_OPTIONS)),-s) \
	SOURCE_PREFIX=$(DISTDIR) \
	SOURCE_MD_DIR=$(DISTDIR) \
	DIST=$(DISTDIR) \
	OBJDIR_NAME=OBJS \
	$(and $(filter 64,$(shell dpkg-architecture -qDEB_HOST_ARCH_BITS)),USE_64=1) \
	$(and $(filter x32,$(shell dpkg-architecture -qDEB_HOST_ARCH)),USE_X32=1) \
	$(NULL)

# Disable -Werror on less mainline architectures.
ifneq (,$(filter-out i386 x86_64 aarch64,$(DEB_HOST_GNU_CPU)))
COMMON_MAKE_FLAGS += NSS_ENABLE_WERROR=0
endif

NSS_TOOLS := \
	certutil \
	chktest \
	cmsutil \
	crlutil \
	derdump \
	httpserv \
	modutil \
	ocspclnt \
	p7content \
	p7env \
	p7sign \
	p7verify \
	pk12util \
	pk1sign \
	pwdecrypt \
	rsaperf \
	selfserv \
	shlibsign \
	signtool \
	signver \
	ssltap \
	strsclnt \
	symkeyutil \
	tstclnt \
	vfychain \
	vfyserv \
	$(NULL)

override_dh_auto_build:
	$(MAKE) -C nss/coreconf/nsinstall \
		$(COMMON_MAKE_FLAGS) \
		CC=$(DEB_BUILD_GNU_TYPE)-gcc \
		ARCHFLAG=

	$(MAKE) -C nss \
		all \
		$(COMMON_MAKE_FLAGS) \
		MOZILLA_CLIENT=1 \
		NSPR_INCLUDE_DIR=/usr/include/nspr \
		NSPR_LIB_DIR=/usr/lib/$(DEB_HOST_MULTIARCH) \
		BUILD_OPT=1 \
		NS_USE_GCC=1 \
		OPTIMIZER="$(CFLAGS) $(CPPFLAGS)" \
		LDFLAGS='$(LDFLAGS) $$(ARCHFLAG) $$(ZDEFS_FLAG)' \
		DSO_LDOPTS='-shared $$(LDFLAGS)' \
		NSS_USE_SYSTEM_SQLITE=1 \
		NSS_ENABLE_ECC=1 \
		CHECKLOC= \
		$(TOOLCHAIN)

override_dh_auto_clean:
	-$(MAKE) -C nss \
		clobber \
		$(COMMON_MAKE_FLAGS) \
		BUILD_OPT=1

	rm -rf $(DISTDIR) $(PREPROCESSED_FILES)

manpage = $(addsuffix .1,$(addprefix nss/doc/nroff/,$(1)))

override_dh_auto_install: $(PREPROCESSED_FILES)
	install -m 755 -d debian/libnss3/usr/lib/$(DEB_HOST_MULTIARCH) debian/libnss3-dev/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig
	install -m 644 -t debian/libnss3/usr/lib/$(DEB_HOST_MULTIARCH) \
		$(DISTDIR)/lib/libnss3.so \
		$(DISTDIR)/lib/libnssutil3.so \
		$(DISTDIR)/lib/libsmime3.so \
		$(DISTDIR)/lib/libssl3.so \
		$(DISTDIR)/lib/libfreebl3.so \
		$(DISTDIR)/lib/libfreeblpriv3.so \
		$(DISTDIR)/lib/libsoftokn3.so \
		$(DISTDIR)/lib/libnssdbm3.so \
		$(DISTDIR)/lib/libnssckbi.so

	install -m 644 -t debian/libnss3-dev/usr/include/nss \
		$(DISTDIR)/public/nss/*
	install -m 644 -t debian/libnss3-dev/usr/lib/$(DEB_HOST_MULTIARCH) \
		$(DISTDIR)/lib/libcrmf.a
	install -m 644 -t debian/libnss3-dev/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig debian/nss.pc
	install -m 755 -t debian/libnss3-dev/usr/bin debian/nss-config

	install -m 755 -t debian/libnss3-tools/usr/bin $(addprefix $(DISTDIR)/bin/,$(NSS_TOOLS))
	install -m 755 -d $(DISTDIR)/man
	install -m 644 -t $(DISTDIR)/man $(wildcard $(call manpage,$(NSS_TOOLS)))

	# these utilities are too generically-named, so we prefix them with nss- (see http://bugs.debian.org/701141)
	$(foreach bin, \
		addbuiltin \
		dbtest \
		pp \
		, \
		$(call cmd,install -m 755 -T $(DISTDIR)/bin/$(bin) debian/libnss3-tools/usr/bin/nss-$(bin)) \
		$(if $(wildcard $(call manpage,$(bin))),$(call cmd,install -m 644 -T $(call manpage,$(bin)) $(DISTDIR)/man/nss-$(bin).1)))

ifeq ($(DEB_HOST_ARCH),$(DEB_BUILD_ARCH))
SHLIBSIGN = LD_LIBRARY_PATH=debian/libnss3/usr/lib/$(DEB_HOST_MULTIARCH) debian/libnss3-tools/usr/bin/shlibsign
else
SHLIBSIGN = shlibsign
endif

override_dh_strip:
	dh_strip
	$(foreach lib,libsoftokn3.so libfreebl3.so libfreeblpriv3.so libnssdbm3.so, \
		$(call cmd,umask 022; $(SHLIBSIGN) -v -i debian/libnss3/usr/lib/$(DEB_HOST_MULTIARCH)/$(lib)))

ifeq ($(DEB_HOST_ARCH),$(DEB_BUILD_ARCH))
	# Check FIPS mode correctly works
	mkdir debian/tmp
	LD_LIBRARY_PATH=debian/libnss3/usr/lib/$(DEB_HOST_MULTIARCH) debian/libnss3-tools/usr/bin/modutil -create -dbdir debian/tmp < /dev/null
	LD_LIBRARY_PATH=debian/libnss3/usr/lib/$(DEB_HOST_MULTIARCH) debian/libnss3-tools/usr/bin/modutil -fips true -dbdir debian/tmp < /dev/null
endif

override_dh_makeshlibs:
	dh_makeshlibs -a -- -c4

%:
	dh $@