chiark / gitweb /
Fix elogind debug mode:
[elogind.git] / pwx_local / rebuild_all.sh
1 #!/bin/bash
2
3 xVersion="$1"
4 xType="$2"
5
6 if [[ "x$xType" != "xdebug" ]] && [[ "x$xType" != "xrelease" ]]; then
7         echo "Usage: $0 <version> <debug|release> [additional configure options]"
8         exit 1
9 fi
10
11 shift 2
12
13 minVers=${xVersion:0:3}
14
15 if [[ ! $minVers =~ [0-9]{3} ]]; then
16         echo "The version must be like \"nnn[.n[n]]\""
17         exit 2
18 fi
19
20 PREFIX=/tmp/elogind_test
21 if [[ $UID -eq 0 ]]; then
22         PREFIX=""
23 else
24         rm -rf $PREFIX
25         mkdir -p $PREFIX
26 fi
27
28 my_CFLAGS="$CFLAGS"
29 my_LDFLAGS="$LDFLAGS"
30
31 if [[ "x$xType" = "xdebug" ]]; then
32         my_CFLAGS="-Og -g3 -ggdb -ftrapv ${my_CFLAGS} -fPIE"
33         LDFLAGS="${my_LDFLAGS} -fPIE"
34 else
35         my_CFLAGS="-O2 -fwrapv ${my_CFLAGS}"
36 fi
37
38 if [[ $minVers -gt 234 ]]; then
39         # After 234 the new meson+ninja build system is used:
40
41         debug_opt="-Ddebug=\"\" --buildtype release"
42         if [[ "x$xType" = "xdebug" ]]; then
43                 debug_opt="-Ddebug=elogind -Dtests=unsafe --buildtype debug"
44         fi
45
46         set -x
47         rm -rf build
48         mkdir build
49
50         cgdefault="$(grep "^rc_cgroup_mode" /etc/rc.conf | cut -d '"' -f 2)"
51
52         extra_opts="$@"
53
54         set +x
55         if [[ "x$extra_opts" != "x" ]]; then
56                 echo -n "Configure ? [y/N] (cg $cgdefault) [$extra_opts]"
57         else
58                 echo -n "Configure ? [y/N] (cg $cgdefault)  "
59         fi
60         read answer
61
62         if [[ "x$answer" != "xy" ]]; then
63                 exit 0
64         fi
65
66         set -x
67
68         CFLAGS="-march=native -pipe ${my_CFLAGS} -Wall -Wextra -Wunused -Wno-unused-parameter -Wno-unused-result -ftree-vectorize" \
69         LDFLAGS="${my_LDFLAGS}" \
70                 meson $debug_opt --prefix $PREFIX/usr -Drootprefix=$PREFIX \
71                         --wrap-mode nodownload --libdir lib64 \
72                         --localstatedir $PREFIX/var/lib  --sysconfdir $PREFIX/etc \
73                          -Ddocdir=$PREFIX/usr/share/doc/elogind-9999 \
74                          -Dhtmldir=$PREFIX/usr/share/doc/elogind-9999/html \
75                          -Dpamlibdir=$PREFIX/lib64/security \
76                          -Dudevrulesdir=$PREFIX/lib/udev/rules.d \
77                          --libdir=$PREFIX/usr/lib64 -Drootlibdir=$PREFIX/lib64 \
78                          -Drootlibexecdir=$PREFIX/lib64/elogind \
79                          -Dsmack=true -Dman=auto -Dhtml=auto \
80                          -Dcgroup-controller=openrc -Ddefault-hierarchy=$cgdefault \
81                          -Dacl=true -Dpam=true -Dselinux=false \
82                          -Dbashcompletiondir=$PREFIX/usr/share/bash-completion/completions \
83                          -Dzshcompletiondir=$PREFIX/usr/share/zsh/site-functions \
84                          $extra_opts $(pwd -P) $(pwd -P)/build
85
86         set +x
87         echo -n "Build and install ? [y/N] "
88         read answer
89
90         if [[ "x$answer" = "xy" ]]; then
91                 set -x
92                 ninja -C build && ninja -C build install
93                 set +x
94         fi
95 else
96         # Up to 233 the old autotools build system is used
97
98         debug_opt="--disable-debug"
99         if [[ "x$xType" = "xdebug" ]]; then
100 #               debug_opt="--enable-debug=elogind --enable-address-sanitizer --enable-undefined-sanitizer --enable-coverage"
101                 debug_opt="--enable-debug=elogind --enable-address-sanitizer --enable-undefined-sanitizer"
102 #               debug_opt="--enable-debug=elogind --enable-undefined-sanitizer --enable-coverage"
103 #               debug_opt="--enable-debug=elogind --enable-undefined-sanitizer"
104         fi
105
106         set -x
107         make clean
108         make distclean
109         intltoolize --automake --copy --force
110         libtoolize --install --copy --force --automake
111         aclocal -I m4
112         autoconf --force
113         autoheader
114         automake --add-missing --copy --foreign --force-missing
115         set +x
116
117         extra_opts="$@"
118         if [[ "x$extra_opts" != "x" ]]; then
119                 echo -n "Configure ? [y/N] [$extra_opts]"
120         else
121                 echo -n "Configure ? [y/N] "
122         fi
123         read answer
124
125         if [[ "x$answer" != "xy" ]]; then
126                 exit 0
127         fi
128
129         set --x
130         CFLAGS="-march=native -pipe ${my_CFLAGS} -Wall -Wextra -Wunused -Wno-unused-parameter -Wno-unused-result -ftree-vectorize" \
131         LDFLAGS="${my_LDFLAGS}" \
132                 ./configure --prefix=$PREFIX/usr --with-rootprefix=$PREFIX/ \
133                         --with-bashcompletiondir=$PREFIX/usr/share/bash-completion/completions \
134                         --enable-dependency-tracking --disable-silent-rules \
135                         --build=x86_64-pc-linux-gnu --host=x86_64-pc-linux-gnu \
136                         --mandir=$PREFIX/usr/share/man --infodir=$PREFIX/usr/share/info \
137                         --datadir=$PREFIX/usr/share --sysconfdir=$PREFIX/etc \
138                         --localstatedir=$PREFIX/var/lib \
139                         --docdir=$PREFIX/usr/share/doc/elogind-${xVersion} \
140                         --htmldir=$PREFIX/usr/share/doc/elogind-${xVersion}/html \
141                         --with-pamlibdir=$PREFIX/lib64/security \
142                         --with-udevrulesdir=$PREFIX/lib/udev/rules.d \
143                         --enable-smack --with-cgroup-controller=openrc \
144                         --enable-acl --enable-pam --disable-selinux \
145                         $debug_opt $extra_opts
146         set +x
147
148         echo -n "Build and install ? [y/N] "
149         read answer
150
151         if [[ "x$answer" = "xy" ]]; then
152                 set -x
153                 make update-man-list && \
154                 make -j 17 && \
155                 make update-man-list && \
156                 make && make install
157                 set +x
158         fi
159 fi