aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/deb/create-pkg.sh
blob: f8ad20accff632e326354b661bd4956bd5e495ee (plain)
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
#!/bin/sh

scp_server="pkgs@kurwik"
project="embedlog"

if [ ${#} -ne 3 ]
then
    echo "usage: ${0} <version> <arch> <host_os>"
    echo ""
    echo "where:"
    echo "    <version>         git branch, tag or commit to build"
    echo "    <arch>            target architecture"
    echo "    <host_os>         target os (debian9, debian8 etc)"
    echo ""
    echo "example"
    echo "      ${0} 1.0.0 i386 debian9"
    exit 1
fi

version="${1}"
arch="${2}"
host_os="${3}"

###
# preparing
#

rm -rf "/tmp/${project}-${version}"
mkdir "/tmp/${project}-${version}"

cd "/tmp/${project}-${version}"
git clone "https://git.kurwinet.pl/${project}"
cd "${project}"

git checkout "${version}" || exit 1

if [ ! -d "pkg/deb" ]
then
    echo "pkg/deb does not exist, cannot create debian pkg"
    exit 1
fi

version="$(grep "AC_INIT(" "configure.ac" | cut -f3 -d\[ | cut -f1 -d\])"
abi_version="$(echo ${version} | cut -f1 -d.)"

echo "version ${version}"
echo "abi version ${abi_version}"

###
# building package
#

codename="$(lsb_release -c | awk '{print $2}')"

cp -r "pkg/deb/" "debian"
sed -i "s/@{DATE}/$(date -R)/" "debian/changelog.template"
sed -i "s/@{VERSION}/${version}/" "debian/changelog.template"
sed -i "s/@{CODENAME}/${codename}/" "debian/changelog.template"
sed -i "s/@{ABI_VERSION}/${abi_version}/" "debian/control.template"

mv "debian/changelog.template" "debian/changelog"
mv "debian/control.template" "debian/control"

export CFLAGS="-I/usr/bofc/include -g"
export LDFLAGS="-L/usr/bofc/lib"
debuild -us -uc || exit 1

# unsed, so it these don't pollute gcc, when we built test program
unset CFLAGS
unset LDFLAGS

###
# verifying
#

cd ..

# debuild doesn't fail when lintial finds an error, so we need
# to check it manually, it doesn't take much time, so whatever

for d in *.deb
do
    echo "Running lintian on ${d}"
    lintian ${d} || exit 1
done

dpkg -i "lib${project}${abi_version}_${version}_${arch}.deb" || exit 1
dpkg -i "lib${project}-dev_${version}_${arch}.deb" || exit 1

failed=0
gcc ${project}/pkg/test.c -o testprog -lembedlog || failed=1

if ldd ./testprog | grep "\/usr\/bofc"
then
    # sanity check to make sure test program uses system libraries
    # and not locally installed ones (which are used as build
    # dependencies for other programs

    echo "test prog uses libs from manually installed /usr/bofc \
        instead of system path!"
    failed=1
fi

./testprog || failed=1

dpkg -r "lib${project}${abi_version}" "lib${project}-dev" || exit 1

# run test prog again, but now fail if there is no error, testprog
# should fail as there is no library in te system any more
./testprog && failed=1

if [ ${failed} -eq 1 ]
then
    exit 1
fi

if [ -n "${scp_server}" ]
then
    dbgsym_pkg="lib${project}${abi_version}-dbgsym_${version}_${arch}.deb"

    if [ ! -f "${dbgsym_pkg}" ]
    then
        # on some systems packages with debug symbols are created with
        # ddeb extension and not deb
        dbgsym_pkg="lib${project}${abi_version}-dbgsym_${version}_${arch}.ddeb"
    fi

    echo "copying data to ${scp_server}:${project}/${host_os}/${arch}"
    scp "lib${project}-dev_${version}_${arch}.deb" \
        "${dbgsym_pkg}" \
        "lib${project}${abi_version}_${version}_${arch}.deb" \
        "lib${project}_${version}.dsc" \
        "lib${project}_${version}.tar.xz" \
        "lib${project}_${version}_${arch}.build" \
        "lib${project}_${version}_${arch}.buildinfo" \
        "lib${project}_${version}_${arch}.changes" \
        "${scp_server}:${project}/${host_os}/${arch}" || exit 1
fi