1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
|
#!/usr/bin/make -f
# rules for building both the tun-source package as well as the
# tun-module package
DEB_HOST_GNU_SYSTEM ?= $(shell dpkg-architecture -qDEB_HOST_GNU_SYSTEM)
clean:
test -f debian/rules
-$(MAKE) distclean
-rm -rf debian/tmp debian/files* debian/substvars kdist_configure debian/control.real debian/changelog.real
# building the tun-source package
binary-indep:
if [ ! $$UID = 0 ]; then echo "not root!"; exit 1; fi
# gen dirs for docs and source stuff
install -d debian/tmp/DEBIAN debian/tmp/usr/src/modules/tun-module
install -d debian/tmp/usr/share/doc/tun-source
# install the docs and logs that have to be compressed
install -m 644 ChangeLog \
debian/tmp/usr/share/doc/tun-source/changelog
install -m 644 README FAQ debian/README.Debian debian/TODO \
debian/tmp/usr/share/doc/tun-source/
install -m 644 debian/changelog \
debian/tmp/usr/share/doc/tun-source/changelog.Debian
gzip -9 debian/tmp/usr/share/doc/tun-source/*
# install stuff that needs not be compressed
install -d debian/tmp/usr/share/doc/tun-source/examples
install -m 644 examples/* debian/tmp/usr/share/doc/tun-source/examples/
install -m 644 debian/copyright \
debian/tmp/usr/share/doc/tun-source/copyright
# now replicate the source tree into /usr/src/modules/tun-module
find . \( -path ./debian/tmp -o -name 'tmp*' \) -prune -o -print | \
cpio -admp debian/tmp/usr/src/modules/tun-module
chown -R root.src debian/tmp/usr/src
find debian/tmp -type d | xargs chmod 775
find debian/tmp -type f -perm -100 | xargs chmod 775
find debian/tmp -type f -not -perm -100 | xargs chmod 664
# build tarball
tar -C debian/tmp/usr/src -cf debian/tmp/usr/src/tun-module.tar modules
$(RM) -r debian/tmp/usr/src/modules
gzip -9 debian/tmp/usr/src/tun-module.tar
# package control stuff: control, md5sums and scripts
find debian/tmp -type f | grep -v "./DEBIAN" | xargs md5sum | \
sed -e 's#debian/tmp/##' > debian/tmp/DEBIAN/md5sums
chown -R root.root debian/tmp
chmod -R g-ws debian/tmp
# generate the tun-source package, ignore the others
dpkg-gencontrol -isp -Pdebian/tmp -ptun-source
dpkg --build debian/tmp ..
# we don't build anything here: that's making just the source package!
build:
binary-arch:
# binary-indep builds the source package
binary: binary-indep binary-arch
.PHONY: build binary binary-arch binary-indep clean
# that's the part for the module build process
.PHONY: kdist_clean kdist_image
# These are used for cross-compiling and for saving the configure script
# from having to guess our platform (since we know it already)
DEB_HOST_GNU_SYSTEM ?= $(shell dpkg-architecture -qDEB_HOST_GNU_SYSTEM)
DEB_HOST_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
# those will be passed by make-kpkg
ifeq ($(DEB_HOST_GNU_SYSTEM), linux)
kernel = linux
KSRC?=/usr/src/linux
endif
ifeq ($(DEB_HOST_GNU_SYSTEM), kfreebsd-gnu)
kernel = freebsd
KSRC_BASE := $(CURDIR)/kfreebsd-source
KSRC := $(KSRC_BASE)/src/sys
endif
KDREV?="custom.1.0"
ifeq ($(DEB_HOST_GNU_SYSTEM), linux)
KVERSION :=$(shell egrep '^VERSION +=' $(KSRC)/Makefile 2>/dev/null | \
sed -e 's/[^0-9]*\([0-9]*\)/\1/')
KPLEVEL :=$(shell egrep '^PATCHLEVEL +=' $(KSRC)/Makefile 2>/dev/null | \
sed -e 's/[^0-9]*\([0-9]*\)/\1/')
KSUBLEVEL:=$(shell egrep '^SUBLEVEL +=' $(KSRC)/Makefile 2>/dev/null | \
sed -e 's/[^0-9]*\([0-9]*\)/\1/')
else
KVERSION := 0
KPLEVEL := 0
KSUBLEVEL := 0
endif
# the sed regexps to insert the kernel version and revision
# into control and changelog
SUB1='s/$${kpkg:Kernel-Version}/$(KVERS)/g'
SUB2='s/$${kpkg:Revision}/$(KDREV)/g'
kdist_configure: kdist_clean
test -f debian/rules
dpkg-checkbuilddeps
ifeq ($(DEB_HOST_GNU_SYSTEM), linux)
# make sure it builds only for 2.2.x
if [ "$(KPLEVEL).$(KVERSION)" != "2.2" ]; then \
echo -e "\n\n*** You were trying to build this package for kernel $(KVERSION).$(KPLEVEL).$(KSUBLEVEL), but";\
echo "*** the package is supported only for the 2.2 kernel series.";\
echo -e "*** For kernels 2.4.x the tun/tap driver comes with the main kernel.\n";\
exit 1; fi
endif
ifeq ($(DEB_HOST_GNU_SYSTEM), kfreebsd-gnu)
mkdir -p $(KSRC_BASE)
tar -C $(KSRC_BASE) -xjpf /usr/src/kfreebsd5/src.tar.bz2
cd $(KSRC_BASE) && cat /usr/src/kfreebsd5/patches/*.diff | patch -p0
endif
cp /usr/share/misc/config.* ./
./configure --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) \
--prefix=/usr --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info --with-kernel=$(KSRC)
touch kdist_configure
kdist_clean: clean
ifeq ($(DEB_HOST_GNU_SYSTEM), kfreebsd-gnu)
rm -rf $(KSRC_BASE)
endif
kdist_image: kdist_configure
# clean up temp area
-rm -rf debian/tmp/
# build the module in $(kernel)/tun.o
ifeq ($(DEB_HOST_GNU_SYSTEM), kfreebsd-gnu)
freebsd-make -C freebsd
else
$(MAKE)
endif
# setup temp area for module, docs and control info
install -d debian/tmp/DEBIAN debian/tmp/etc/modutils
install -d debian/tmp/usr/share/doc/tun-module-$(KVERS)
install -d debian/tmp/lib/modules/$(KVERS)/misc
# the module goes into misc...
install $(kernel)/tun.o debian/tmp/lib/modules/$(KVERS)/misc
# the config file into /etc/modutils
install -m 644 debian/tun.modutuils debian/tmp/etc/modutils/tun-$(KVERS)
# do the necessary magic wrt. packagename and version:
# the kernelversion gets attached to the packagename,
# and the kernel revision becomes the package's version.
sed -e $(SUB1) -e $(SUB2) <debian/postinst.module >debian/tmp/DEBIAN/postinst
chmod 0755 debian/tmp/DEBIAN/postinst
cat debian/control debian/control.module \
|sed -e $(SUB1) -e $(SUB2) >debian/control.real
# the changelog gets prefixed with a dummy changelog that holds
# the version we want to set.
cat debian/changelog.module debian/changelog \
|sed -e $(SUB1) -e $(SUB2) >debian/changelog.real
# install the docs and logs that have to be compressed
install -m 644 debian/changelog.real debian/tmp/usr/share/doc/tun-module-$(KVERS)/changelog.Debian
install -m 644 ChangeLog \
debian/tmp/usr/share/doc/tun-module-$(KVERS)/changelog
install -m 644 README FAQ debian/README.Debian debian/TODO \
debian/tmp/usr/share/doc/tun-module-$(KVERS)/
gzip -9 debian/tmp/usr/share/doc/tun-module-$(KVERS)/*
# install stuff that needs not be compressed
install -d debian/tmp/usr/share/doc/tun-module-$(KVERS)/examples
install -m 644 examples/* debian/tmp/usr/share/doc/tun-module-$(KVERS)/examples/
install -m 644 debian/copyright \
debian/tmp/usr/share/doc/tun-module-$(KVERS)/copyright
# package control stuff: md5sums...
find debian/tmp -type f | grep -v "./DEBIAN" | xargs md5sum | \
sed -e 's#debian/tmp/##' > debian/tmp/DEBIAN/md5sums
chown -R root.root debian/tmp
chmod -R g-ws debian/tmp
# ...conffiles...
echo "/etc/modutils/tun-$(KVERS)" > debian/tmp/DEBIAN/conffiles
# ...and the control file for the tun-module-nnn package
# careful: we read different control and changelog files!
dpkg-gencontrol -isp -Pdebian/tmp -ptun-module-$(KVERS) -cdebian/control.real -ldebian/changelog.real
dpkg --build debian/tmp $(KSRC)/..
|