summaryrefslogtreecommitdiff
path: root/libc/debian/rules
blob: 1f394b280f46180a1a1032a8e35a2ed17929f567 (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
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
#!/usr/bin/make -f

include /usr/share/dpkg/architecture.mk
include /usr/share/dpkg/buildflags.mk

%:
	dh $@

export DH_VERBOSE = 1

CC = gcc
VERSION := $(shell dpkg-parsechangelog | perl -ne '/Version:\s+(.+)-[^-]+/ && print $$1')

# We must have this libraries so packages can be compiled,
# but if we just use filters provided by illumos gate, it causes
# some rare FTBFS with GNU ld. We can't use symlink (e. g. libpthread -> libc),
# because in this case libc can go before libgcc_s, and some other packages
# will crash in runtime. So we make a dummy library.

libs_filters := \
libaio \
libdoor \
libintl \
libpthread \
librt \
libsendfile \
libthread \
libxnet \

fake_libs := \
$(libs_filters) \
libposix4 \
libdl \

# These lists are used in packing orig tarball
# and in building binaries. Anything that need a
# special way of building is extracted in a special way too,
# for example ld and ldd.

# XXX order is important for building:
# usr/src/lib/* :
libs := \
common \
libavl \
libc \
libm \
libc_db \
libgen \
libcrypt \
libmd \
libmp \
libnsl \
libresolv \
libresolv2 \
librpcsvc \
libsecdb \
libsocket \
crypt_modules \
$(libs_filters)

# usr/src/lib/nsswitch/* :
nsswitch := \
files \
user \
nis \
dns \
compat \

# XXX order is important for building
# usr/src/cmd/sgs/* :
sgs := \
libconv \
libdl \
liblddbg \
libelf \
libld \
librtld \
librtld_db \
rtld \
lddstub \
crle \


# usr/src/cmd/* for libc functionality:
cmd := \
utmp_update \
utmpd \
zic \
getconf \
locale \
localedef \
zdump \
rpcinfo \
rpcgen \
getent \
gencat \

man1 := $(filter-out utmp_update,$(cmd))
man1 += $(filter-out lib% lddstub rtld, $(sgs) ld ldd)

# usr/src/common:
common := \
atomic \
avl \
crypto \
dtrace \
elfcap \
sgsrtcid \
unicode \
util \
xattr \

BUILD = build-tree
ROOT = $(BUILD)/root
ILLUMOS_GATE = illumos-gate

$(ILLUMOS_GATE):
	dh_illumos_gate --checkout --destdir=$(ILLUMOS_GATE)

.PHONY: create-orig
create-orig: $(ILLUMOS_GATE)
	dh_illumos_gate --create-orig --build \
		$(ILLUMOS_GATE)/usr/src/cmd/netfiles \
		$(ILLUMOS_GATE)/usr/src/cmd/sgs/Makefile* \
		$(ILLUMOS_GATE)/usr/src/cmd/sgs/include \
		$(ILLUMOS_GATE)/usr/src/cmd/sgs/ld \
		$(ILLUMOS_GATE)/usr/src/cmd/sgs/ldd \
		$(ILLUMOS_GATE)/usr/src/cmd/sgs/messages \
		$(ILLUMOS_GATE)/usr/src/cmd/sgs/packages/common/SUNWonld-README \
		$(ILLUMOS_GATE)/usr/src/cmd/sgs/packages/common/readme_revision \
		$(ILLUMOS_GATE)/usr/src/cmd/sgs/tools \
		$(ILLUMOS_GATE)/usr/src/head \
		$(ILLUMOS_GATE)/usr/src/lib/nsswitch/Makefile* \
		$(ILLUMOS_GATE)/usr/src/man/man2/\*.2 \
		$(ILLUMOS_GATE)/usr/src/man/man3/\*.3 \
		$(ILLUMOS_GATE)/usr/src/man/man3c/\*.3c \
		$(ILLUMOS_GATE)/usr/src/man/man4/crypt.conf.4 \
		$(ILLUMOS_GATE)/usr/src/man/man5/crypt_\*.5 \
		$(ILLUMOS_GATE)/usr/src/uts/\*/\*/krtld \
		$(ILLUMOS_GATE)/usr/src/uts/\*/krtld \
		$(ILLUMOS_GATE)/usr/src/uts/common/sys/avl*.h \
		$(cmd:%=$(ILLUMOS_GATE)/usr/src/cmd/%) \
		$(common:%=$(ILLUMOS_GATE)/usr/src/common/%) \
		$(libs:%=$(ILLUMOS_GATE)/usr/src/lib/%) \
		$(man1:%=$(ILLUMOS_GATE)/usr/src/man/man1\*/%.\*) \
		$(nsswitch:%=$(ILLUMOS_GATE)/usr/src/lib/nsswitch/%) \
		$(sgs:%=$(ILLUMOS_GATE)/usr/src/cmd/sgs/%) \

test-orig: create-orig
	./debian/rules clean
	rm -rf usr .pc
	tar xf ../libc_$(VERSION).orig.tar.xz --strip=1
	quilt push -a
	./debian/rules build
	fakeroot ./debian/rules binary

# libs having "install_h" target to install headers first:
libs_headers := \
libc \
libmd \
libsocket \
libnsl \
libgen \

override_dh_auto_configure:
	dh_illumos_gate --configure --destdir=$(BUILD) --root=$(ROOT)
	echo 'export DEB_CRYPT_MODULE_DIR_32="$$DEB_LIBDIR_32/security"' >> $(BUILD)/usr/env.sh
	echo 'export DEB_CRYPT_MODULE_DIR_64="$$DEB_LIBDIR_64/security"' >> $(BUILD)/usr/env.sh
	find $(BUILD)/usr/src/head -name \*.x -exec ./debian/fix.x.pl {} \;

override_dh_auto_build:
	. $(BUILD)/usr/env.sh; mkdir -p \
		$(ROOT)/$$DEB_CRYPT_MODULE_DIR_32 \
		$(ROOT)/$$DEB_CRYPT_MODULE_DIR_64 \
		$(ROOT)/$$DEB_LIBDIR_32 \
		$(ROOT)/$$DEB_LIBDIR_64 \
		$(ROOT)/$$DEB_USRLIBDIR_32 \
		$(ROOT)/$$DEB_USRLIBDIR_64 \
		$(ROOT)/etc/default \
		$(ROOT)/usr/include/sys \
		$(ROOT)/usr/bin \
		$(ROOT)/usr/sbin
	# We are changing soname, but keep links for build time.
	# These links also will go into libsunXXX-dev packages.
	# Watch out: libc build-conflicts with other libelf-dev and libavl-dev
	# implementations, and libsunXXX-dev will do too.
	. $(BUILD)/usr/env.sh; \
	ln -svf $$ROOT/$$DEB_LIBDIR_32/libsunelf.so.1 \
		$$ROOT/$$DEB_USRLIBDIR_32/libelf.so && \
	ln -svf $$ROOT/$$DEB_LIBDIR_64/libsunelf.so.1 \
		$$ROOT/$$DEB_USRLIBDIR_64/libelf.so && \
	ln -svf $$ROOT/$$DEB_LIBDIR_32/libsunavl.so.1 \
		$$ROOT/$$DEB_USRLIBDIR_32/libavl.so && \
	ln -svf $$ROOT/$$DEB_LIBDIR_64/libsunavl.so.1 \
		$$ROOT/$$DEB_USRLIBDIR_64/libavl.so

	# This is for ld and other to find the right library:
	. $(BUILD)/usr/env.sh; \
	ln -svf $$ROOT/$$DEB_LIBDIR_32/libld.so.4 \
		$$ROOT/$$DEB_USRLIBDIR_32/libld.so && \
	ln -svf $$ROOT/$$DEB_LIBDIR_64/libld.so.4 \
		$$ROOT/$$DEB_USRLIBDIR_64/libld.so && \
	ln -svf $$ROOT/$$DEB_LIBDIR_32/liblddbg.so.4 \
		$$ROOT/$$DEB_USRLIBDIR_32/liblddbg.so && \
	ln -svf $$ROOT/$$DEB_LIBDIR_64/liblddbg.so.4 \
		$$ROOT/$$DEB_USRLIBDIR_64/liblddbg.so

	# install headers
	dh_illumos_make $(make) $(BUILD)/usr/src/head -t install_h
	dh_illumos_make $(make) $(libs_headers:%=$(BUILD)/usr/src/lib/%) -t install_h
	cp -vf $(BUILD)/usr/src/uts/common/sys/avl*.h $(ROOT)/usr/include/sys/
	cp -vrf debian/compat_headers/* $(ROOT)/usr/include/

	# build libs
	# libutil is brought by our patch, it's not a part of the gate
	dh_illumos_make $(patsubst %,$(BUILD)/usr/src/lib/%,$(libs) libutil)
	dh_illumos_make $(nsswitch:%=$(BUILD)/usr/src/lib/nsswitch/%)

	# build sgs
	dh_illumos_make --native $(BUILD)/usr/src/cmd/sgs/tools
	dh_illumos_make $(sgs:%=$(BUILD)/usr/src/cmd/sgs/%)
	cp usr/src/man/man1/ld.1 $(BUILD)/usr/src/man/man1/sunld.1
	# these two are patched:
	dh_illumos_make --native \
		$(BUILD)/usr/src/cmd/sgs/ld/i386 \
		$(BUILD)/usr/src/cmd/sgs/ldd/i386 \

	# build tools:
	dh_illumos_make --native $(make) $(cmd:%=$(BUILD)/usr/src/cmd/%)
	. $(BUILD)/usr/env.sh; unset LD_ALTEXEC; \
		$(CC) $(CFLAGS) -o $(ROOT)/usr/bin/crle \
		-DDEB_USRLIBDIR_32=\"$$DEB_USRLIBDIR_32\" \
		-DDEB_USRLIBDIR_64=\"$$DEB_USRLIBDIR_64\" \
		-DDEB_HOST_ARCH_BITS=$$DEB_HOST_ARCH_BITS \
		debian/crle.c

override_dh_auto_install:
	rm -rf debian/tmp
	cp -a $(ROOT) debian/tmp
	for l in `find debian/tmp/lib32 -maxdepth 1 -type l -name \*.so`; do \
		ln -sf `readlink -f $$l` debian/tmp/usr/lib32/`basename $$l`; \
		rm $$l; \
	done
	for l in `find debian/tmp/lib/$(DEB_HOST_MULTIARCH) -maxdepth 1 -type l -name \*.so`; do \
		ln -sf `readlink -f $$l` debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/`basename $$l`; \
		rm $$l; \
	done
	symlinks -c debian/tmp/usr/lib32
	symlinks -c debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)
	set -x; for l in $(subst lib,,$(fake_libs)); do \
		rm -f debian/tmp/usr/lib32/lib$$l.so && \
		rm -f debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/lib$$l.so && \
		echo "ASSERT(1, \"This is a fake library: ld -l$$l works, but nothing is linked\")" > debian/tmp/usr/lib32/lib$$l.so && \
		echo "ASSERT(1, \"This is a fake library: ld -l$$l works, but nothing is linked\")" > debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/lib$$l.so; \
	done
	: # Make everybody happy:
	rm debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/libc.so
	echo 'INPUT(libc.so.1 AS_NEEDED(-lsocket -lnsl -lresolv -liconv /usr/lib/$(DEB_HOST_MULTIARCH)/libssp.so.0))' \
		> debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/libc.so
	: # Even sunld:
	ln -sf libc.so.1 debian/tmp/lib/$(DEB_HOST_MULTIARCH)/libc.so

override_dh_install: debian/LC_DATA.gz debian/locales.config
	dh_install
	find debian/locales/usr/share/i18n/locales -name *.UTF-8.src | \
		xargs sed -i '/^LC_CTYPE/,/^END LC_CTYPE/d'
	./debian/generate-locales-all

override_dh_installman:
	# language=C because of ld.so.1.1
	dh_installman --language=C

override_dh_strip:
	: # we don't strip *this* libc

override_dh_fixperms:
	dh_fixperms
	chmod 0755 \
		debian/*/usr/lib/*/lddstub \
		debian/*/usr/lib?*/lddstub \
		debian/*/usr/lib/*/crle \
		debian/*/usr/lib?*/crle \
		debian/*/lib/*/ld.so.* \
		debian/*/lib?*/ld.so.*
	chmod 4755 debian/*/usr/lib/utmp_update

override_dh_makeshlibs:
	dh_makeshlibs -- -c4

# We remove LC_DATA from all *.UTF-8.src
# and when regenerating locales will insert contents of LC_DATA
# into source locale file. Illumos localedef does not support
# copy action for including other files source files.
debian/LC_DATA.gz:
	sh $(BUILD)/usr/src/cmd/localedef/data/ctype.sh \
		$(BUILD)/usr/src/cmd/localedef/data/*.UTF-8.src \
		| gzip -c -9 > $@

debian/locales.config: debian/locales.config.in
	perl -pe 'BEGIN {undef $$/; open(IN, "debian/SUPPORTED"); $$j=<IN>;} s/__PROVIDED_LOCALES__/$$j/g;' \
		$< > $@

override_dh_auto_clean:
	rm -rf $(BUILD)
	rm -f debian/LC_DATA.*
	rm -f debian/locales.config