Whamcloud - gitweb
bef0c49eed1419090f90bd45d4b3cb184303263d
[fs/lustre-release.git] / debian / rules
1 #!/usr/bin/make -f
2 #
3 # Created 2009 by Brian J. Murrell based on work by
4 # Alastair McKinstry, <alastair.mckinstry@ichec.ie>, <mckinstry@debian.org>
5 # Patrick Winnertz, and the pkg-lustre Debian maintainers
6 #
7 # Copying and modification is unlimited, provided that the modified
8 # version is marked as being modified.
9
10 # Uncomment this to turn on verbose mode.
11 # export DH_VERBOSE=1
12
13 DEB_BUILD_GNU_SYSTEM = $(shell dpkg-architecture -qDEB_BUILD_GNU_SYSTEM)
14 DEB_BUILD_GNU_CPU = $(shell dpkg-architecture -qDEB_BUILD_GNU_CPU)
15
16 # whether to use module-assistant to build the kernel modules or not
17 USE_MA = true
18
19 CFLAGS = -Wall -g
20 ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
21         CFLAGS += -O0
22 else
23         CFLAGS += -O2
24 endif
25
26 # We need the kernels to be built with gcc-3.3; suspect that gcc-4.1 uses too
27 # much stack and crashes because of it.
28 #CC?=gcc-3.3
29 #export CC
30
31 # This is the debhelper compatability version to use.
32 export DH_COMPAT=7
33
34 # Module-assistant stuff
35 PACKAGE=lustre-client-modules
36 MA_DIR ?= /usr/share/modass
37 -include $(MA_DIR)/include/generic.make
38 -include $(MA_DIR)/include/common-rules.make
39
40 ARCH=$(shell dpkg --print-architecture)
41 TOP_DIR:=$(shell pwd)
42
43 # This is the Lustre version
44 VERSION=$(shell sed -n -e '1s/.*(\(.*\)) .*/\1/p' debian/changelog)
45 UPVERSION=$(shell echo $VERSION | sed -e 's/-[^-]*$$//')
46
47 # KVER is set to LINUXRELEASE being by autoconf which is either
48 # $(uname -r) or the version of the source specified by the user
49 KVER?=$(LINUXRELEASE)
50
51 # KVERS, KSRC are the kernel version and source to use when building lustre
52 # Will be the default when building lustre-utils, etc but whatever module-assistant
53 # supplied when building modules
54 KVERS?=$(KVER)
55 KSRC?=$(LINUX_OBJ)
56 KSRC_TREE?=$(LINUX)
57
58 # Packages
59 PATCH_PKG=linux-patch-lustre
60 UTILS_PKG=lustre-utils
61 TESTS_PKG=lustre-tests
62 DEV_PKG=lustre-dev
63 SOURCE_PKG=lustre-source
64 MODS_PKG=lustre-client-modules
65
66 #Build dir
67 #BUILDDIR=debian/build
68 #SRCDIR=../..
69 # I'm afraid we seem to have broken the BUILDDIR concept in Lustre's
70 # autoconf macros
71 BUILDDIR=.
72 SRCDIR=.
73
74 AVAIL_CPUS := $(shell getconf _NPROCESSORS_ONLN 2>/dev/null || echo 1)
75 ifneq ($(AVAIL_CPUS),1)
76       PMAKEARGS := -j $(AVAIL_CPUS)
77 endif
78
79 autogen: autogen-stamp
80 autogen-stamp: patch-stamp
81         # see if any patches requires us to run autogen
82         # (for a distribution release tarball, it is expected that if
83         #  downstream adds any patches that requires autogen.sh to be
84         #  run, a patch will be added by downstream to install the
85         #  needed autogen.sh scripts
86         #  see https://bugzilla.lustre.org/attachment.cgi?id=27156
87         #  for an example)
88         if grep -e "^--- .*\/autoconf\/" \
89                 -e "^--- .*\/autoMakefile\.am" \
90                 -e "^--- .*\/Makefile\.am" \
91                 -e "^--- .*\/configure\.ac" \
92                 -e "^--- .*\/configure\.in" \
93             debian/patches/*; then \
94                 if [ ! -f build/autogen.sh ]; then \
95                         echo "You have patches which require autogen.sh to be run, but it doesn't exist"; \
96                         echo "Please see https://bugzilla.lustre.org/attachment.cgi?id=27156"; \
97                         exit 1; \
98                 fi; \
99                 cp /usr/share/misc/config.sub config.sub; \
100                 cp /usr/share/misc/config.sub ldiskfs/config.sub; \
101                 cp /usr/share/misc/config.guess config.guess; \
102                 cp /usr/share/misc/config.guess ldiskfs/config.guess; \
103                 sh build/autogen.sh; \
104         fi; \
105         touch $@
106
107 configure: configure-stamp
108 configure-stamp: autogen-stamp debian/control.main debian/control.modules.in
109         dh_testdir
110         # touch files to same date, to avoid auto*
111         find . -type f -print0 | xargs -0 touch -r COPYING; \
112         if [ "$(BUILDDIR)" != "." ]; then \
113                 mkdir -p $(BUILDDIR)/build $(BUILDDIR)/lustre/contrib; \
114                 cp build/Makefile $(BUILDDIR)/build/; \
115                 cp lustre/contrib/mpich-*.patch $(BUILDDIR)/lustre/contrib/; \
116         fi
117         ( cd $(BUILDDIR) && \
118          $(SRCDIR)/configure --disable-dependency-tracking \
119                    --disable-modules \
120                    --disable-snmp \
121                    --disable-client \
122                    --enable-quota \
123                    --disable-server )
124         touch $@
125
126 build-arch build-indep: build
127
128 build: build-stamp
129 build-stamp: patch-stamp configure-stamp
130         dh_testdir
131         $(MAKE) -C $(BUILDDIR) $(PMAKEARGS)
132         $(MAKE) -C $(BUILDDIR) DESTDIR=$(TOP_DIR)/debian/tmp install
133         # jump our lustre-client-modules into the control file if not using m-a
134         if ! $(USE_MA); then \
135                 (cat debian/control.main; sed -e '1,/^$$/d' -e "s/_KVERS_/$(KVER)/g" < debian/control.modules.in) > debian/control; \
136                 for file in debian/*_KVERS_*; do \
137                         newfile=$$(echo $$file | sed -e "s/_KVERS_/$(KVER)/g"); \
138                         cp $$file $$newfile; \
139                 done; \
140         fi
141         touch $@
142
143 # let's try and operate as close as the user would and not build modules
144 # here (for now)
145 # instead we will build the modules with m-a in the "make debs" target
146 # binary-arch: binary-$(UTILS_PKG) binary-$(TESTS_PKG) binary-$(DEV_PKG) \
147 # binary-$(MODS_PKG) binary-kern-mods
148 binary-arch: binary-$(UTILS_PKG) binary-$(TESTS_PKG) binary-$(DEV_PKG)
149
150 binary-indep: binary-$(PATCH_PKG) binary-$(SOURCE_PKG)
151
152 binary: binary-indep binary-arch
153
154 binary-$(PATCH_PKG): patch-stamp
155         dh_testdir
156         dh_testroot
157         dh_installdirs -p $(PATCH_PKG)
158         dh_installdocs -p $(PATCH_PKG)
159 #       dh_installkpatches -p $(PATCH_PKG)
160         dh_install -p $(PATCH_PKG)
161
162         # Install apply script
163         cp $(TOP_DIR)/debian/linux-patch-lustre.apply $(TOP_DIR)/debian/$(PATCH_PKG)/usr/src/kernel-patches/lustre/scripts/apply
164         chmod a+x $(TOP_DIR)/debian/$(PATCH_PKG)/usr/src/kernel-patches/lustre/scripts/apply
165         set -e; for KERNEL in $(SUPPORTED_KERNELS); do \
166           mkdir -p $(TOP_DIR)/debian/$(PATCH_PKG)/usr/src/kernel-patches/all/$$KERNEL/apply/; \
167           ln -s ../../../lustre/scripts/apply $(TOP_DIR)/debian/$(PATCH_PKG)/usr/src/kernel-patches/all/$$KERNEL/apply/lustre; \
168         done
169
170         # Install unpatch script
171         cp $(TOP_DIR)/debian/linux-patch-lustre.unpatch $(TOP_DIR)/debian/$(PATCH_PKG)/usr/src/kernel-patches/lustre/scripts/unpatch
172         chmod a+x $(TOP_DIR)/debian/$(PATCH_PKG)/usr/src/kernel-patches/lustre/scripts/unpatch
173         set -e; for KERNEL in $(SUPPORTED_KERNELS); do \
174           mkdir -p $(TOP_DIR)/debian/$(PATCH_PKG)/usr/src/kernel-patches/all/$$KERNEL/unpatch/; \
175           ln -s ../../../lustre/scripts/unpatch $(TOP_DIR)/debian/$(PATCH_PKG)/usr/src/kernel-patches/all/$$KERNEL/unpatch/lustre; \
176         done
177
178         # Install series
179         cp lustre/kernel_patches/series/*.series $(TOP_DIR)/debian/$(PATCH_PKG)/usr/src/kernel-patches/lustre/series/
180
181         # Install patches
182         cp lustre/kernel_patches/patches/*.patch $(TOP_DIR)/debian/$(PATCH_PKG)/usr/src/kernel-patches/lustre/patches/
183
184         dh_installchangelogs -p $(PATCH_PKG) lustre/ChangeLog
185         dh_compress -p $(PATCH_PKG)
186         dh_installdeb -p $(PATCH_PKG)
187         dh_fixperms -p $(PATCH_PKG)
188         dh_gencontrol -p $(PATCH_PKG)
189         dh_md5sums -p $(PATCH_PKG)
190         dh_builddeb -p $(PATCH_PKG)
191
192 binary-$(UTILS_PKG): build-stamp
193         dh_testdir
194         dh_testroot
195         dh_installdirs -p $(UTILS_PKG)
196         dh_installdocs -p  $(UTILS_PKG)
197         dh_installman -p $(UTILS_PKG)
198         dh_install -p $(UTILS_PKG)
199         dh_makeshlibs -p $(UTILS_PKG)
200         dh_installexamples -p $(UTILS_PKG)
201         dh_installchangelogs -p $(UTILS_PKG) lustre/ChangeLog
202         dh_compress -p $(UTILS_PKG)
203         dh_strip -p $(UTILS_PKG)
204         dh_installdeb -p $(UTILS_PKG)
205         dh_fixperms -p $(UTILS_PKG)
206         dh_gencontrol -p $(UTILS_PKG)
207         dh_md5sums -p $(UTILS_PKG)
208         dh_builddeb -p $(UTILS_PKG)
209
210 binary-$(TESTS_PKG): build-stamp
211         dh_testdir
212         dh_testroot
213         dh_installdirs -p $(TESTS_PKG)
214         dh_installdocs -p  $(TESTS_PKG)
215         dh_installman -p $(TESTS_PKG)
216         dh_install -p $(TESTS_PKG)
217         dh_makeshlibs -p $(TESTS_PKG)
218         dh_installexamples -p $(TESTS_PKG)
219         dh_installchangelogs -p $(TESTS_PKG) lustre/ChangeLog
220         dh_compress -p $(TESTS_PKG)
221         dh_strip -p $(TESTS_PKG)
222         dh_installdeb -p $(TESTS_PKG)
223         dh_fixperms -p $(TESTS_PKG)
224         dh_gencontrol -p $(TESTS_PKG)
225         dh_md5sums -p $(TESTS_PKG)
226         dh_builddeb -p $(TESTS_PKG)
227
228 binary-$(DEV_PKG): build-stamp
229         dh_testdir
230         dh_testroot
231         dh_installdirs -p $(DEV_PKG)
232         dh_install -p $(DEV_PKG)
233         dh_installdocs -p $(DEV_PKG)
234         dh_installchangelogs -p $(DEV_PKG) lustre/ChangeLog
235         dh_compress -p $(DEV_PKG)
236         dh_installdeb -p $(DEV_PKG)
237         dh_fixperms -p $(DEV_PKG)
238         dh_gencontrol -p $(DEV_PKG)
239         dh_md5sums -p $(DEV_PKG)
240         dh_builddeb -p $(DEV_PKG)
241
242 binary-$(SOURCE_PKG): build-stamp
243         dh_testdir 
244         dh_testroot
245         # Copy everything 
246         dh_installdirs -p $(SOURCE_PKG) usr/src/modules/lustre/debian
247         rsync -av --exclude='debian/$(SOURCE_PKG)/*' \
248               --link-dest=$(PWD) \
249               . debian/$(SOURCE_PKG)/usr/src/modules/lustre
250         # Remove FULLCLEAN setting
251         rm debian/$(SOURCE_PKG)/usr/src/modules/lustre/debian/rules
252         sed -e 's/FULLCLEAN=full-clean/FULLCLEAN=/' < debian/rules > debian/$(SOURCE_PKG)/usr/src/modules/lustre/debian/rules
253         # clean up dest
254         rm -rf debian/$(SOURCE_PKG)/usr/src/modules/lustre/debian/patched \
255                debian/$(SOURCE_PKG)/usr/src/modules/lustre/debian/patches/* 
256         $(MAKE) -C debian/$(SOURCE_PKG)/usr/src/modules/lustre -f debian/rules clean
257         # Create the module-source tarball.
258         cd debian/$(SOURCE_PKG)/usr/src && tar jcf lustre.tar.bz2 modules 
259         rm -rf debian/$(SOURCE_PKG)/usr/src/modules
260         dh_install -p$(SOURCE_PKG)
261         dh_installchangelogs -p $(SOURCE_PKG) lustre/ChangeLog
262         dh_installdocs -p $(SOURCE_PKG) 
263         dh_link -p $(SOURCE_PKG) /usr/share/modass/packages/default.sh /usr/share/modass/overrides/lustre-source
264         dh_compress -p $(SOURCE_PKG)
265         dh_installdeb -p $(SOURCE_PKG)
266         dh_fixperms -p $(SOURCE_PKG)
267         dh_gencontrol -p $(SOURCE_PKG)
268         dh_md5sums -p $(SOURCE_PKG)
269         dh_builddeb -p $(SOURCE_PKG)
270
271 # if only we could use m-a for this, but this stupid "compliant.list"
272 # thing fouls that up
273 binary-kern-mods:
274         mkdir -p debian/m-a_root/usr_src/modules
275         ln -s ../../../../ debian/m-a_root/usr_src/modules/lustre
276         m-a -t -u debian/m-a_root/ -d -v -k $(KSRC) build lustre
277         mv -f debian/m-a_root/*.deb ..
278
279 # an alternative (to module-assistant) method of building the kernel modules
280 binary-$(MODS_PKG): build-stamp
281         if ! $(USE_MA); then \
282                 cp debian/lustre-client-modules.install debian/lustre-client-modules-$(KVER).install ; \
283                 dh_testdir; \
284                 dh_testroot; \
285                 dh_installdirs -p $(MODS_PKG)-$(KVER); \
286                 dh_installdocs -p $(MODS_PKG)-$(KVER); \
287                 dh_install -p $(MODS_PKG)-$(KVER); \
288                 dh_makeshlibs -p $(MODS_PKG)-$(KVER); \
289                 dh_installchangelogs -p $(MODS_PKG)-$(KVER) lustre/ChangeLog; \
290                 dh_compress -p $(MODS_PKG)-$(KVER); \
291                 dh_installdeb -p $(MODS_PKG)-$(KVER); \
292                 dh_strip -p $(MODS_PKG)-$(KVER); \
293                 dh_fixperms -p $(MODS_PKG)-$(KVER); \
294                 dh_gencontrol -p $(MODS_PKG)-$(KVER); \
295                 dh_md5sums -p $(MODS_PKG)-$(KVER); \
296                 dh_builddeb -p $(MODS_PKG)-$(KVER); \
297         fi
298
299 ###
300 ### For module-assistant
301 ###
302
303 # the kdist_clean target is called by make-kpkg modules_clean and from
304 # kdist* rules. It is responsible for cleaning up any changes that have
305 # been made by the other kdist_commands (except for the .deb files created)
306
307 kdist_clean: 
308         # can't dh_clean here or we remove the build artifacts for the other packages
309         # still in progress
310         #dh_clean
311         #-$(MAKE) $(MFLAGS) -f debian/rules clean
312         # put the userspace tools' control file back
313         cp debian/control.main debian/control
314
315
316 # module assistant calculates all needed things for us and sets
317 # # following variables:
318 # # KSRC (kernel source directory), KVERS (kernel version string), KDREV
319 # # (revision of the Debian kernel-image package), CC (the correct
320 # # compiler), VERSION (the final package version string), PKGNAME (full
321 # # package name with KVERS included), DEB_DESTDIR (path to store DEBs)
322 #
323 # # The kdist_configure target is called by make-kpkg modules_config and
324 # # by kdist* rules by dependency. It should configure the module so it is
325 # # ready for compilation (mostly useful for calling configure).
326 # # prep-deb-files from module-assistant creates the neccessary debian/ 
327 kdist_config: prep-deb-files patch-stamp
328         #  Check build dependencies again, needs to be done since we just
329         # replaced the control file.
330         dpkg-checkbuilddeps
331         # Prepare the kernel to lustres' liking
332         # as non-root, we won't have permission for this
333         #-$(MAKE) -C $(KSRC) prepare scripts
334         # touch files to same date, to avoid auto*
335         find . -type f -print0 | xargs -0 touch -r COPYING \;
336         # Doesn't seem possible to only build modules...
337         ./configure --with-linux=$(KSRC_TREE) \
338                     --with-linux-obj=$(KSRC) \
339                     --disable-server \
340                     --disable-quilt  \
341                     --disable-dependency-tracking \
342                     --disable-doc  \
343                     --disable-utils \
344                     --disable-iokit \
345                     --disable-snmp \
346                     --disable-tests \
347                     --enable-quota
348
349 kdist_configure: kdist_config
350
351 # the binary-modules rule is invoked by module-assistant while processing the
352 # kdist* targets. It is called by module-assistant or make-kpkg and *not*
353 # during a normal build
354 binary-modules: prep-deb-files
355         dh_testroot
356         dh_prep
357         $(MAKE) $(PMAKEARGS)
358         $(MAKE) install DESTDIR=$(CURDIR)/debian/$(PKGNAME)
359         # Remove stuff that doesn't belong (no module-only target)
360         cd $(CURDIR)/debian/$(PKGNAME) && rm -rf usr sbin etc
361         dh_installdocs -p$(PKGNAME)
362         dh_installchangelogs -p$(PKGNAME)
363         dh_installmodules -p $(PKGNAME)
364         dh_compress -p $(PKGNAME)
365         dh_fixperms -p $(PKGNAME)
366         dh_installdeb -p $(PKGNAME)
367         dh_gencontrol -- -v$(VERSION)
368         dh_md5sums -p $(PKGNAME)
369         dh_builddeb --destdir=$(DEB_DESTDIR) -p $(PKGNAME)
370         dh_prep -p $(PKGNAME)
371
372 clean:
373         dh_testdir
374         dh_testroot
375         dpatch deapply-all -v
376         -$(MAKE) distclean
377         rm -rf  debian/substvars debian/*.bak debian/*~ *~  *-stamp debian/$(PATCH_PKG)
378         ls -d debian/lustre-client-modules-* | grep -v _KVERS_ | xargs rm -f || true
379         # only remove this if the clean was not called from kdist_clean
380         if [ "$$MA_SOURCE_PKG" = "" ]; then \
381                 rm -rf  debian/m-a_root; \
382         fi
383         dh_clean
384         # make sure we have at least a basic control in place (see build-stamp)
385         rm -f debian/control
386         cp debian/control.main debian/control
387
388 patch: patch-stamp
389 patch-stamp:
390         dpatch apply-all -v
391         touch $@
392
393 unpatch:
394         dpatch deapply-all -v
395         rm -rf debian/patched patch-stamp
396
397 .PHONY: binary-arch clean source diff  binary binary-indep binary-arch install configure