aboutsummaryrefslogtreecommitdiff
path: root/debian/rules
blob: 6e64b4553eba43d13a5d70e279bc4baab658a149 (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
#!/usr/bin/make -f
#
# $(DEBIAN)/rules for Ubuntu linux
#
# Use this however you want, just give credit where credit is due.
#
# Copyright (c) 2007 Ben Collins <bcollins@ubuntu.com>
#

DEBIAN=$(shell awk -F= '($$1 == "DEBIAN") { print $$2 }' <debian/debian.env)
TIMESTAMP:=$(shell printf %x $$(date +%s))
_DUMMY:=$(shell sed -i -e '1 s/%TIMESTAMP%/$(TIMESTAMP)/'  $(DEBIAN)/changelog)

# dpkg-buildpackage passes options that are incomptatible
# with the kernel build.
unexport CFLAGS
unexport LDFLAGS

export LC_ALL=C
export SHELL=/bin/bash -e

# Where do we find the common configuration.
export DROOT=debian

# Common variables for all architectures
include $(DROOT)/rules.d/0-common-vars.mk

# Pull in some arch specific stuff
-include $(DEBIAN)/rules.d/$(arch).mk

# Maintainer targets
include $(DROOT)/rules.d/1-maintainer.mk

# Stages
ifeq ($(DEB_STAGE),stage1)
    do_tools=false
    do_doc_package=false
    do_source_package=false
    do_flavour_image_package=false
    do_flavour_header_package=false
endif

# Debian Build System targets
binary: binary-indep binary-arch

build: build-arch build-indep

clean: debian/control
	dh_testdir
	dh_testroot
	dh_clean

	# d-i stuff
	rm -rf $(DEBIAN)/d-i-$(arch)

	# normal build junk
	rm -rf $(DEBIAN)/abi/$(release)-$(revision)
	rm -rf $(builddir)
	rm -f $(stampdir)/stamp-*
	rm -rf $(DEBIAN)/linux-*

	# This gets rid of the d-i packages in control
	cp -f $(DEBIAN)/control.stub $(DEBIAN)/control
	cat $(DEBIAN)/changelog debian/changelog | \
		sed -e '1 s/%TIMESTAMP%/$(TIMESTAMP)/' > debian/changelog

	# Install the copyright information.
	cp -p $(DEBIAN)/copyright debian/copyright

distclean: clean
	rm -rf $(DEBIAN)/control $(DEBIAN)/control.stub \
		$(DEBIAN)/d-i/kernel-versions debian/changelog \
		debian/control debian/control.stub debian/copyright

# Builds the image, arch headers and debug packages
include $(DROOT)/rules.d/2-binary-arch.mk

# Rules for building the udebs ($(DEBIAN)-installer)
include $(DROOT)/rules.d/5-udebs.mk

# Builds the source, doc and linux-headers indep packages
include $(DROOT)/rules.d/3-binary-indep.mk

# Various checks to be performed on builds
include $(DROOT)/rules.d/4-checks.mk

# Misc stuff
$(DEBIAN)/control.stub: $(DEBIAN)/d-i/kernel-versions.in	\
		$(DROOT)/scripts/control-create		\
		$(DEBIAN)/control.stub.in			\
		$(DEBIAN)/changelog			\
		$(wildcard $(DEBIAN)/control.d/* $(DEBIAN)/sub-flavours/*.vars)
	for i in $(DEBIAN)/d-i/kernel-versions.in $(DEBIAN)/control.stub.in; do	\
	  new=`echo $$i | sed 's/\.in$$//'`;					\
	  cat $$i | sed -e 's/PKGVER/$(release)/g'                              \
	        -e 's/ABINUM/$(abinum)/g'                                       \
		-e 's/COMMONSRCPKGNAME/$(common_src_pkg_name)/g'          \
		-e 's/SRCPKGNAME/$(src_pkg_name)/g'                             \
	  > $$new;								\
	done
	flavours="$(wildcard $(DEBIAN)/control.d/vars.* $(DEBIAN)/sub-flavours/*.vars)";\
	for i in $$flavours; do							\
	  $(SHELL) $(DROOT)/scripts/control-create $$i |			\
		sed -e 's/PKGVER/$(release)/g'                                  \
		-e 's/ABINUM/$(abinum)/g'                                       \
		-e 's/COMMONSRCPKGNAME/$(common_src_pkg_name)/g'          \
		-e 's/SRCPKGNAME/$(src_pkg_name)/g'                             \
		>> $(DEBIAN)/control.stub;					\
	done
	cp $(DEBIAN)/control.stub $(DEBIAN)/control

.PHONY: debian/control
debian/control: $(DEBIAN)/control.stub
	rm -rf $(builddir)/modules $(builddir)/firmware			\
		$(builddir)/kernel-versions $(builddir)/package-list	\
		$(builddir)/$(DEBIAN)
	mkdir -p $(builddir)/modules/$(arch)/
	cp $(DEBIAN)/d-i/modules/* $(builddir)/modules/$(arch)/
	mkdir -p $(builddir)/firmware/$(arch)/
	cp $(DEBIAN)/d-i/firmware/* $(builddir)/firmware/$(arch)/
	cp $(DEBIAN)/d-i/package-list $(DEBIAN)/d-i/kernel-versions $(builddir)/
	touch $(builddir)/modules/$(arch)/kernel-image
	# kernel-wedge needs to poke around in $(DEBIAN)/
	ln -nsf $(CURDIR)/debian $(builddir)/debian

	# Some files may need to differ between architectures
	if [ -d $(DEBIAN)/d-i/modules-$(arch) ]; then			\
	    cp $(DEBIAN)/d-i/modules-$(arch)/* \
		$(builddir)/modules/$(arch)/;				\
	fi
	if [ -d $(DEBIAN)/d-i/firmware-$(arch) ]; then			\
	    cp $(DEBIAN)/d-i/firmware-$(arch)/* \
		$(builddir)/firmware/$(arch)/;				\
	fi

	# Remove unwanted stuff for this architecture
	if [ -r "$(DEBIAN)/d-i/exclude-modules.$(arch)" ]; then		\
	    (cat $(DEBIAN)/d-i/exclude-modules.$(arch);			\
	     ls $(builddir)/modules/$(arch)/) | sort | uniq -d |	\
		(cd $(builddir)/modules/$(arch)/; xargs rm -f);		\
	fi
	if [ -r "$(DEBIAN)/d-i/exclude-firmware.$(arch)" ]; then		\
	    (cat $(DEBIAN)/d-i/exclude-firmware.$(arch);			\
	     ls $(builddir)/firmware/$(arch)/) | sort | uniq -d |	\
		(cd $(builddir)/firmware/$(arch)/; xargs rm -f);	\
	fi

	# Per flavour module lists
	flavour_modules=`ls $(DEBIAN)/d-i/modules.$(arch)-* 2>/dev/null`	\
		|| true;						\
	if [ "$$flavour_modules" != "" ]; then				\
	    for flav in $$flavour_modules; do				\
		name=`echo $$flav | sed 's/.*\/modules.$(arch)-//'`;	\
		mkdir $(builddir)/modules/$(arch)-$$name;		\
		(cd $(builddir)/modules/; tar cf - `cat ../$$flav`) |	\
		    (cd $(builddir)/modules/$(arch)-$$name/; tar xf -);	\
		touch $(builddir)/modules/$(arch)-$$name/kernel-image;	\
	    done;							\
	fi
	flavour_firmware=`ls $(DEBIAN)/d-i/firmware.$(arch)-* 2>/dev/null`	\
		|| true;						\
	if [ "$$flavour_firmware" != "" ]; then				\
	    for flav in $$flavour_firmware; do				\
		name=`echo $$flav | sed 's/.*\/firmware.$(arch)-//'`;	\
		mkdir $(builddir)/firmware/$(arch)-$$name;		\
		(cd $(builddir)/firmware/; tar cf - `cat ../$$flav`) |	\
		    (cd $(builddir)/firmware/$(arch)-$$name/; tar xf -);\
		touch $(builddir)/firmware/$(arch)-$$name/kernel-image;	\
	    done;							\
	fi

	# Some files may need to differ between flavours
	flavour_module_dirs=`ls -d $(DEBIAN)/d-i/modules-$(arch)-* 2>/dev/null`\
		|| true;						\
	if [ "$$flavour_module_dirs" ]; then				\
	    for flav in $$flavour_module_dirs; do			\
		name=`echo $$flav | sed 's/.*\/modules-$(arch)-//'`;	\
		[ -d $(builddir)/modules/$(arch)-$$name ] ||		\
		    cp -a $(builddir)/modules/$(arch)			\
			modules/$(arch)-$$name;				\
		cp $$flav/* $(builddir)/modules/$(arch)-$$name/;	\
	    done;							\
	fi
	flavour_firmware_dirs=`ls -d $(DEBIAN)/d-i/firmware-$(arch)-* 2>/dev/null`\
		|| true;						\
	if [ "$$flavour_firmware_dirs" ]; then				\
	    for flav in $$flavour_firmware_dirs; do			\
		name=`echo $$flav | sed 's/.*\/firmware-$(arch)-//'`;	\
		[ -d $(builddir)/firmware/$(arch)-$$name ] ||		\
		    cp -a $(builddir)/firmware/$(arch)			\
			firmware/$(arch)-$$name;			\
		cp $$flav/* $(builddir)/firmware/$(arch)-$$name/;	\
	    done;							\
	fi

	# Remove unwanted stuff for each flavour
	flavour_exclude=`ls $(DEBIAN)/d-i/exclude-modules.$(arch)-* 2>/dev/null`\
		|| true;						\
	if [ "$$flavour_exclude" ]; then				\
	    for flav in $$flavour_exclude; do				\
		name=`echo $$flav | sed 's/.*\/exclude-modules.$(arch)-//'`;\
		[ -d $(builddir)/modules/$(arch)-$$name ] ||		\
		    cp -a $(builddir)/modules/$(arch) 			\
			$(builddir)/modules/$(arch)-$$name;		\
		(cat $$flav;						\
		 ls $(builddir)/modules/$(arch)-$$name) |		\
		 sort |	uniq -d |					\
		    (cd $(builddir)/modules/$(arch)-$$name/;		\
		     xargs rm -f);					\
	    done;							\
	fi
	flavour_exclude=`ls $(DEBIAN)/d-i/exclude-firmware.$(arch)-* 2>/dev/null`\
		|| true;						\
	if [ "$$flavour_exclude" ]; then				\
	    for flav in $$flavour_exclude; do				\
		name=`echo $$flav | sed 's/.*\/exclude-firmware.$(arch)-//'`;\
		[ -d $(builddir)/firmware/$(arch)-$$name ] ||		\
		    cp -a $(builddir)/firmware/$(arch) 			\
			$(builddir)/firmware/$(arch)-$$name;		\
		(cat $$flav;						\
		 ls $(builddir)/firmware/$(arch)-$$name) |		\
		 sort |	uniq -d |					\
		    (cd $(builddir)/firmware/$(arch)-$$name/;		\
		     xargs rm -f);					\
	    done;							\
	fi

	if [ ! -d $(builddir)/modules/$(build_arch) ]; then		\
		mkdir -p $(builddir)/modules/$(build_arch);		\
		cp $(builddir)/modules/$(arch)/*			\
			$(builddir)/modules/$(build_arch);		\
	fi
	if [ ! -d $(builddir)/firmware/$(build_arch) ]; then		\
		mkdir -p $(builddir)/firmware/$(build_arch);		\
		cp $(builddir)/firmware/$(arch)/*			\
			$(builddir)/firmware/$(build_arch);		\
	fi

	cp $(DEBIAN)/control.stub debian/control.stub
	cd $(builddir) && kernel-wedge gen-control > $(CURDIR)/debian/control