Add script to generate Debian package files for static applications
[oonf.git] / files / create_debian_package.sh
1 #!/bin/sh
2
3 # store source directory
4 SOURCE=$(git rev-parse --show-toplevel)
5
6 # handle script input and variables
7 : ${BUILD:=oonf_build_debian}
8
9 BUILDDIR=/tmp/${BUILD}
10
11 if [ "$#" -eq "0" ]
12 then
13         TARGET=olsrd2
14 else
15         TARGET=${1}
16 fi
17
18 if [ "${TOOLCHAIN}" != "" ]
19 then
20     echo "Using toolchain file: ${TOOLCHAIN}"
21     TOOLCHAIN="-D CMAKE_TOOLCHAIN_FILE=`realpath ${TOOLCHAIN}`"
22 fi
23
24 if [ "${ARCH}" != "" ]
25 then
26     echo "Using architecture: ${ARCH}"
27     ARCH="-a${ARCH}"
28 fi
29
30 # calculate version and tarball names
31 VERSION=`git describe --abbrev=0| sed -e "s/^v//"`
32 FULLVERSION=`git describe`
33
34 TARPREFIX=${TARGET}_${VERSION}
35 TARBALL=${BUILDDIR}/${TARPREFIX}.orig.tar.gz
36
37 # check if target is there and prepared for a debian package
38 if [ ! -d ${SOURCE}/src/${TARGET} ]
39 then
40     echo "Could not find target '${TARGET}'"
41     exit 1
42 fi
43
44 if [ ! -f ${SOURCE}/src/${TARGET}/debian_changelog ]
45 then
46     echo "Could not find target '${TARGET}' debian changelog"
47     exit 1
48 fi
49
50 # create clean build directory
51 if [ -d ${BUILDDIR} ]
52 then
53     echo "remove ${BUILDDIR}"
54     rm -r ${BUILDDIR}
55 fi
56
57 mkdir -p ${BUILDDIR}
58 cd ${BUILDDIR}
59
60 # create directory structure
61 mkdir build
62
63 # build tarball of current source
64 cd build
65
66 cmake -DTARBALL=${TARBALL} -DTARPREFIX=${TARPREFIX} ${SOURCE}
67 make targz
68
69 cd ${BUILDDIR}
70
71 # uncompress tarball
72 tar xf ${TARBALL}
73
74 # build debian directory from template
75 cd ${TARPREFIX}
76
77 cp ${SOURCE}/src/${TARGET}/debian_changelog ./debian/changelog
78 cp ${SOURCE}/src/${TARGET}/debian_control ./debian/control
79 cp ${SOURCE}/files/default_licence.txt ./debian/copyright
80
81 # adapt changelog template
82 sed -i  -e "s@SHORTVERSION@${VERSION}@" \
83         -e "s@FULLVERSION@${FULLVERSION}@" \
84         -e "s@DATETIME@`date -R`@" \
85         ./debian/changelog
86
87 # adapt rules template
88 sed -i  -e "s@SOURCEDIR@${BUILDDIR}/${TARPREFIX}@" \
89         -e "s@SOURCETOOLCHAIN@${TOOLCHAIN}@" \
90         -e "s@TARGETNAME@${TARGET}@" \
91         -e "s@INSTALLDESTDIR@${BUILDDIR}/${TARPREFIX}/debian/${TARGET}@" \
92         ./debian/rules
93
94 # create debian package
95 debuild -us -uc ${ARCH}
96
97 # copy package to source directory
98 cp ${BUILDDIR}/*.deb ${SOURCE}