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