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

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

export DH_VERBOSE = 1

CC = gcc

# only for testing:
#make = -m '/home/sunmake/make -j2 --sun'

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

# Actually, order is important:
libs_core := \
common \
libavl \
libc \
libutil \
libgen \
libcrypt \
libmd \
libmp \
libnsl \
libresolv \
libresolv2 \
librpcsvc \
libsecdb \
libsocket \
crypt_modules \

libs_filters := \
libintl \
libpthread \
libxnet \
librt \

libs := $(libs_core) $(libs_filters)

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

# usr/src/cmd/sgs/* :
sgs := \
libconv \
libdl \
liblddbg \
libelf \
libld \
librtld \
rtld \
lddstub \
crle

# Debugging libraries, going into libc-db package
# (headers proc_service.h, rtld_db.h, and thread_db.h)
sgs += librtld_db
libs += libc_db

# usr/src/cmd/* for libc functionality:
#
# NOTES:
# 1. tzselect is under zic
cmd := \
utmp_update \
utmpd \
zic \
getconf \
locale \
localedef \
zdump \
rpcinfo \
rpcgen \
getent \
gencat \


# 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.
FAKE_LIBS = $(subst lib,,$(libs_filters) libdl libaio libsendfile libthread libposix4 libdoor)

unpack: unpack-stamp
unpack-stamp:
	dh_testdir
	# TODO: unpack only required stuff
	dh_illumos_gate
	rm -fv usr/src/uts/common/sys/feature_tests.h
	echo 'export DEB_CRYPT_MODULE_DIR_32="$$DEB_LIBDIR_32/security"' >> usr/env.sh
	echo 'export DEB_CRYPT_MODULE_DIR_64="$$DEB_LIBDIR_64/security"' >> usr/env.sh
	touch $@

libc-mapfile := usr/src/lib/libc/port/mapfile-vers
patch: patch-stamp
patch-stamp: unpack-stamp
	dh_testdir
	[ ! -f debian/patches/series ] || QUILT_PATCHES=debian/patches quilt push -a || test $$? = 2
	cp usr/src/man/man1/ld.1 \
		usr/src/man/man1/sunld.1
	touch $@

unpatch:
	dh_testdir
	[ ! -f debian/patches/series ] || QUILT_PATCHES=debian/patches quilt pop -a -f || test $$? = 2
	[ ! -f $(libc-mapfile).orig ] || mv $(libc-mapfile).orig $(libc-mapfile)
	rm -f patch-stamp

fix-x-stamp: patch-stamp
	find usr/src/head -name \*.x \
		-exec ./debian/fix.x.pl {} \;
	touch $@

dirs-stamp:
	. usr/env.sh; mkdir -p \
		debian/tmp$$DEB_CRYPT_MODULE_DIR_32 \
		debian/tmp$$DEB_CRYPT_MODULE_DIR_64 \
		debian/tmp$$DEB_LIBDIR_32 \
		debian/tmp$$DEB_LIBDIR_64 \
		debian/tmp$$DEB_USRLIBDIR_32 \
		debian/tmp$$DEB_USRLIBDIR_64 \
		debian/tmp/etc/default \
		debian/tmp/usr/include/sys \
		debian/tmp/usr/bin \
		debian/tmp/usr/sbin
	touch $@

	# 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.
	. usr/env.sh; \
	ln -sf $(CURDIR)/debian/tmp$$DEB_LIBDIR_32/libsunelf.so.1 \
		debian/tmp$$DEB_USRLIBDIR_32/libelf.so && \
	ln -sf $(CURDIR)/debian/tmp$$DEB_LIBDIR_64/libsunelf.so.1 \
		debian/tmp$$DEB_USRLIBDIR_64/libelf.so && \
	ln -sf $(CURDIR)/debian/tmp$$DEB_LIBDIR_32/libsunavl.so.1 \
		debian/tmp$$DEB_USRLIBDIR_32/libavl.so && \
	ln -sf $(CURDIR)/debian/tmp$$DEB_LIBDIR_64/libsunavl.so.1 \
		debian/tmp$$DEB_USRLIBDIR_64/libavl.so

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

	touch $@

headers-stamp: patch-stamp dirs-stamp fix-x-stamp
	dh_illumos_make $(make) usr/src/head -t install_h
	dh_illumos_make $(make) $(libs_headers:%=usr/src/lib/%) -t install_h
	cp -vf usr/src/uts/common/sys/avl*.h debian/tmp/usr/include/sys/
	cp -vrf debian/compat_headers/* debian/tmp/usr/include/
	touch $@

lib-stamp: headers-stamp
	dh_illumos_make $(make) $(libs:%=usr/src/lib/%)
	touch $@

nsswitch-stamp: lib-stamp
	dh_illumos_make $(make) $(nsswitch:%=usr/src/lib/nsswitch/%)
	touch $@

# Some libs and, more important, runtime linker are in usr/src/cmd/sgs.
# We will not build all sgs stuff, but only related to libc.
sgs-stamp: lib-stamp
	dh_illumos_make $(make) --native usr/src/cmd/sgs/tools
	dh_illumos_make $(make) $(sgs:%=usr/src/cmd/sgs/%)
	# We have patched this:
	dh_illumos_make $(make) --native \
		usr/src/cmd/sgs/ldd/i386 \
		usr/src/cmd/sgs/ld/i386 \

	touch $@


cmd-stamp: lib-stamp sgs-stamp
	dh_illumos_make --native $(make) $(cmd:%=usr/src/cmd/%)
	touch $@

build-stamp: lib-stamp sgs-stamp nsswitch-stamp headers-stamp cmd-stamp debian/LC_DATA.gz debian/locales.config crle
install-stamp: build-stamp
	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 $(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

	touch $@

build build-arch build-indep: build-stamp
binary binary-arch binary-indep: binary-stamp
install: install-stamp


binary-stamp: install-stamp
	dh_testdir
	dh_testroot
	dh_installdirs
	dh_install
	find debian/locales/usr/share/i18n/locales -name *.UTF-8.src | \
		xargs sed -i '/^LC_CTYPE/,/^END LC_CTYPE/d'
	# language=C because of ld.so.1.1
	./debian/generate-locales-all
	dh_installman --language=C
	dh_installdocs
	dh_installexamples
	dh_installchangelogs
	dh_installdebconf
	dh_link
	dh_compress
	dh_makeshlibs -- -c4
	dh_shlibdeps

	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

	dh_installdeb
	dh_gencontrol
	dh_md5sums
	dh_builddeb
	touch $@

# 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: patch-stamp
	sh usr/src/cmd/localedef/data/ctype.sh \
		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;' \
		$< > $@

crle: debian/crle.c
	. usr/env.sh; unset LD_ALTEXEC; \
		$(CC) $(CFLAGS) -o $@ \
		-DDEB_USRLIBDIR_32=\"$$DEB_USRLIBDIR_32\" \
		-DDEB_USRLIBDIR_64=\"$$DEB_USRLIBDIR_64\" \
		-DDEB_HOST_ARCH_BITS=$$DEB_HOST_ARCH_BITS \
		$<

clean: unpatch
	dh_testdir
	rm -f debian/LC_DATA.*
	rm -f debian/locales.config
	rm -rf usr .pc
	rm -f crle
	dh_clean