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