1#! /usr/bin/make -f
2# -*- makefile -*-
3#
4# Invoke each target with `./debian/rules <target>'.  All targets should be
5# invoked with the package root as the current directory.
6#
7# The `binary' target must be run as root, as it needs to install files with
8# specific ownerships.
9
10# Uncomment this to turn on verbose mode.
11export DH_VERBOSE=1
12
13package = e2fsprogs
14ARCH = $(shell dpkg --print-architecture)
15
16# find the version for the main package, from changelog file
17MAIN_VERSION = $(shell head -1 debian/changelog | cut '-d ' -f 2 | sed 's/[()]//g')
18# find versions for libraries going into their own packages, from their Makefile.in's
19COMERR_VERSION = $(shell grep ELF_VERSION lib/et/Makefile.in | cut '-d ' -f3)
20COMERR_MAJOR = $(word 1,$(subst ., ,$(COMERR_VERSION)))
21SS_VERSION = $(shell grep ELF_VERSION lib/ss/Makefile.in | cut '-d ' -f3)
22SS_MAJOR = $(word 1,$(subst ., ,$(SS_VERSION)))
23
24topdir = $(shell pwd)
25debdir = $(topdir)/debian
26maindir = $(debdir)/tmp
27builddir = $(topdir)/builddir
28docdir = $(maindir)/usr/doc/$(package)
29
30SUBPACKAGES_DIRS = tmp e2fslibsg e2fslibsg-dev comerr$(COMERR_MAJOR)g comerrg-dev \
31	ss$(SS_MAJOR)g ssg-dev
32
33installdoc = install -m 644
34installbin = install -m 755
35
36ifeq ($(ARCH),alpha)
37CCOPTS = -g -O2 -fsigned-char -DHAVE_NETINET_IN_H
38LIBC-DEV = libc6.1-dev
39else
40CCOPTS = -g -O2 -fsigned-char
41LIBC-DEV = libc6-dev
42endif
43
44build: configured
45	dh_testdir
46	make -C $(builddir)
47	make -C $(builddir)/misc findsuper
48	cd doc && texi2html -split_chapter libext2fs.texinfo
49	cd lib/et && texi2html -split_chapter -expandinfo com_err.texinfo
50	touch build
51
52configured:
53	dh_testdir
54	mkdir -p $(builddir)
55	cd $(builddir) && CFLAGS="$(CFLAGS)" \
56		../configure --enable-elf-shlibs --enable-dynamic-e2fsck \
57		--with-ccopts="$(CCOPTS)"
58	touch configured
59
60clean:
61	dh_testdir
62	rm -f build configured install
63	-make -C $(builddir) -i distclean
64	rm -rf $(builddir)
65	rm -f doc/libext2fs_*.html lib/et/com_err_*.html
66	dh_clean
67
68binary-indep: build
69  # no arch-independant debs.
70
71binary-arch: build
72	dh_testversion 0.56 # == 0.53 + fixes
73	dh_testdir -a
74	dh_testroot -a
75	dh_clean -a -k
76	dh_installdirs -a
77
78	make -C $(builddir) install DESTDIR=$(maindir)
79	install -m 755 $(builddir)/misc/findsuper $(maindir)/sbin
80  # static libs and .h files
81	make -C $(builddir) install-libs DESTDIR=$(maindir)
82	install -m 644 $(builddir)/lib/ss/ss_err.h $(maindir)/usr/include/ss/
83
84# fix and install compile_et script
85	sed s%$(topdir)/lib/et%/usr/share/comerr% \
86	  <$(builddir)/lib/et/compile_et \
87	  >$(debdir)/comerrg-dev/usr/bin/compile_et
88	chmod 755 $(debdir)/comerrg-dev/usr/bin/compile_et
89# add support files for compile_et
90	install -m 644 lib/et/et_c.awk lib/et/et_h.awk \
91	  $(debdir)/comerrg-dev/usr/share/comerr/
92
93# fix and install mk_cmds script
94	sed s%$(topdir)/lib/ss%/usr/share/ss% \
95	  <$(builddir)/lib/ss/mk_cmds \
96	  >$(debdir)/ssg-dev/usr/bin/mk_cmds
97	chmod 755 $(debdir)/ssg-dev/usr/bin/mk_cmds
98# add support files for mk_cmds
99	install -m 644 lib/ss/ct_c.awk lib/ss/ct_c.sed \
100	  $(debdir)/ssg-dev/usr/share/ss/
101
102# docs
103	mkdir -p $(debdir)/e2fslibsg-dev/usr/doc/e2fslibsg
104	ln -sf e2fslibsg $(debdir)/e2fslibsg-dev/usr/doc/e2fslibsg-dev
105	mkdir -p $(maindir)/usr/doc/e2fslibsg
106	ln -sf e2fslibsg $(maindir)/usr/doc/e2fsprogs
107	mkdir -p $(debdir)/comerrg-dev/usr/doc/comerr$(COMERR_MAJOR)g
108	ln -sf comerr$(COMERR_MAJOR)g $(debdir)/comerrg-dev/usr/doc/comerrg-dev
109	mkdir -p $(debdir)/ssg-dev/usr/doc/ss$(SS_MAJOR)g
110	ln -sf ss$(SS_MAJOR)g $(debdir)/ssg-dev/usr/doc/ssg-dev
111	dh_installdocs -a
112
113  # HTML docs
114	install -d $(debdir)/e2fslibsg-dev/usr/doc/e2fslibsg-dev/html-info/
115	install -p $(topdir)/doc/libext2fs_*.html \
116	   $(debdir)/e2fslibsg-dev/usr/doc/e2fslibsg-dev/html-info/
117	install -d $(debdir)/comerrg-dev/usr/doc/comerrg-dev/html-info/
118	install -p $(topdir)/lib/et/com_err_*.html \
119	   $(debdir)/comerrg-dev/usr/doc/comerrg-dev/html-info/
120
121  # texinfo docs
122	install -p $(topdir)/doc/libext2fs.texinfo \
123	   $(debdir)/e2fslibsg-dev/usr/doc/e2fslibsg/libext2fs.texi
124	install -p $(topdir)/lib/et/com_err.texinfo \
125	   $(debdir)/comerrg-dev/usr/doc/comerr2g/com_err.texi
126
127  # doc-base support
128	install -d $(debdir)/e2fslibsg-dev/usr/share/doc-base/
129	install -p -m 644 $(debdir)/libext2fs.docbase \
130	   $(debdir)/e2fslibsg-dev/usr/share/doc-base/libext2fs
131	install -d $(debdir)/comerrg-dev/usr/share/doc-base/
132	install -p -m 644 $(debdir)/com_err.docbase \
133	   $(debdir)/comerrg-dev/usr/share/doc-base/com_err
134
135  # examples
136	dh_installexamples -a
137
138  # dh_installmanpages still makes a mess as of 0.54 (see below dh_movefiles)
139	install -p $(topdir)/lib/et/compile_et.1 $(maindir)/usr/man/man1/
140	install -d $(maindir)/usr/man/man3/
141	install -p $(topdir)/lib/et/com_err.3 $(maindir)/usr/man/man3/
142	ln -s e2fsck.8 $(maindir)/usr/man/man8/fsck.ext2.8
143	ln -s mke2fs.8 $(maindir)/usr/man/man8/mkfs.ext2.8
144
145	dh_movefiles -a
146  # cleanup empty dirs
147	cd  $(maindir) && rmdir usr/man/cat? bin lib usr/include/* usr/include \
148		usr/info usr/lib usr/man/man3 usr/doc/e2fslibsg
149
150#	dh_installmenu -a
151
152  # broken + useless in 0.52
153  #	dh_installmanpages -a
154
155	dh_undocumented -a
156
157	dh_installchangelogs -pe2fslibsg -pcomerr$(COMERR_MAJOR)g -pss$(SS_MAJOR)g ChangeLog
158
159	dh_strip -a
160	dh_compress -a
161	dh_fixperms -a
162
163	echo "libcdev:Depends=$(LIBC-DEV)" > debian/comerrg-dev.substvars
164	echo "libcdev:Depends=$(LIBC-DEV)" > debian/ssg-dev.substvars
165	echo "libcdev:Depends=$(LIBC-DEV)" > debian/e2fslibsg-dev.substvars
166
167	dh_installdeb -a
168	LD_LIBRARY_PATH=$(builddir)/lib:/lib:/usr/lib \
169	  dh_shlibdeps -a
170	dh_gencontrol -u '-isp' -pe2fsprogs -pe2fslibsg -pe2fslibsg-dev
171	dh_gencontrol -u '-isp' -pcomerr$(COMERR_MAJOR)g -pcomerrg-dev \
172	  -u '-v$(COMERR_VERSION)-$(MAIN_VERSION)'
173	dh_gencontrol -u '-isp' -pss$(SS_MAJOR)g -pssg-dev \
174	  -u '-v$(SS_VERSION)-$(MAIN_VERSION)'
175	dh_makeshlibs -a
176#	dh_du -a
177	dh_md5sums -a
178	dh_builddeb -a
179
180binary: binary-indep binary-arch
181
182.PHONY: binary binary-arch binary-indep clean checkroot
183