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