Skip to content

Commit b01578e

Browse files
authored
Merge pull request #1777 from larsewi/configure
ENT-12600: configure: Documented and refactored script
2 parents f3548fd + a503c1a commit b01578e

File tree

1 file changed

+109
-100
lines changed

1 file changed

+109
-100
lines changed

build-scripts/configure

Lines changed: 109 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,139 +1,148 @@
1-
#!/bin/sh -x
2-
3-
4-
. `dirname "$0"`/functions
1+
#!/bin/sh
2+
3+
#
4+
# This script runs configure on each of the CFEngine repositories.
5+
# It determines which configure options and compiler flags to use based on the dependencies found in compile-options script.
6+
#
7+
# The script expects the following repositories to exist side by side:
8+
# .
9+
# ├── buildscripts
10+
# ├── core
11+
# ├── enterprise
12+
# ├── nova
13+
# └── masterfiles
14+
#
15+
# ^ When building community you won't need enterprise, nova.
16+
#
17+
# The script can be run as follows:
18+
# ```
19+
# $ PROJECT=[nova|community] BUILD_TYPE=[DEBUG|RELEASE] EXPLICIT_ROLE=[hub|agent] ./buildscripts/build-scripts/configure
20+
# ```
21+
#
22+
23+
24+
. "$(dirname "$0")"/functions
525
. detect-environment
626
. compile-options
727
. version
828

29+
# Make sure the PROJECT variable is set correctly
930
case "$PROJECT" in
10-
community) NOVA=no ;;
11-
nova) NOVA=yes ;;
12-
*) fatal "Unknown project: $PROJECT" ;;
31+
community)
32+
NOVA=no
33+
;;
34+
nova)
35+
NOVA=yes
36+
;;
37+
*)
38+
fatal "Unknown project: $PROJECT"
39+
;;
1340
esac
1441

1542

1643
P=$BUILDPREFIX
1744

18-
ARGS="--prefix=$P --libdir=$P/lib --with-workdir=$P --sysconfdir=/etc --with-openssl=$P --with-pcre2=$P --with-librsync=$P --with-init-script"
45+
ARGS="--prefix=$P --libdir=$P/lib --with-workdir=$P --sysconfdir=/etc --with-openssl=$P --with-pcre2=$P --with-librsync=$P --with-init-script --with-lmdb=$P"
46+
47+
for dep in ldap libxml2 libyaml librsync leech libacl libvirt libcurl; do
48+
case "$DEPS" in
49+
*"$dep"*)
50+
var_append ARGS "--with-$dep=$P"
51+
;;
52+
*)
53+
var_append ARGS "--without-$dep"
54+
;;
55+
esac
56+
done
1957

20-
if [ $EMBEDDED_DB = lmdb ]
21-
then
22-
var_append ARGS "--with-lmdb=$P"
23-
fi
24-
case "$DEPS" in
25-
*pthreads-w32*) var_append ARGS "--with-pthreads=$P" ;;
26-
esac
27-
case "$DEPS" in
28-
*openldap*) var_append ARGS "--with-ldap=$P" ;;
29-
*) var_append ARGS "--without-ldap" ;;
30-
esac
31-
case "$DEPS" in
32-
*libxml2*) var_append ARGS "--with-libxml2=$P" ;;
33-
*) var_append ARGS "--without-libxml2" ;;
34-
esac
35-
case "$DEPS" in
36-
*libyaml*) var_append ARGS "--with-libyaml=$P" ;;
37-
*) var_append ARGS "--without-libyaml" ;;
38-
esac
39-
case "$DEPS" in
40-
*librsync*) var_append ARGS "--with-librsync=$P" ;;
41-
*) var_append ARGS "--without-librsync" ;;
42-
esac
43-
case "$DEPS" in
44-
*leech*) var_append ARGS "--with-leech=$P" ;;
45-
*) var_append ARGS "--without-leech" ;;
46-
esac
47-
case "$DEPS" in
48-
*postgresql*) var_append ARGS "--with-postgresql=$P --without-mysql" ;;
49-
*) var_append ARGS "--without-sql" ;;
50-
esac
51-
case "$DEPS" in
52-
*libacl*) var_append ARGS "--with-libacl=$P" ;;
53-
*) var_append ARGS "--without-libacl" ;;
54-
esac
5558
case "$DEPS" in
56-
*libvirt*) var_append ARGS "--with-libvirt=$P" ;;
57-
*) var_append ARGS "--without-libvirt" ;;
59+
*pthreads-w32*)
60+
var_append ARGS "--with-pthreads=$P"
61+
;;
5862
esac
59-
# both libcurl or libcurl-hub are valid
63+
6064
case "$DEPS" in
61-
*libcurl*) var_append ARGS "--with-libcurl=$P" ;;
62-
*) var_append ARGS "--without-libcurl" ;;
65+
*postgresql*)
66+
var_append ARGS "--with-postgresql=$P --without-mysql"
67+
;;
68+
*)
69+
var_append ARGS "--without-sql"
70+
;;
6371
esac
72+
6473
case "$ROLE" in
65-
hub) var_append ARGS "--with-cfmod --with-enterprise-api --with-postgresql=$P" ;;
66-
agent) var_append ARGS "--without-cfmod --without-postgresql" ;;
67-
*) fatal "Unknown ROLE: $ROLE" ;;
74+
hub)
75+
var_append ARGS "--with-cfmod --with-enterprise-api --with-postgresql=$P"
76+
;;
77+
agent)
78+
var_append ARGS "--without-cfmod --without-postgresql"
79+
;;
80+
*)
81+
fatal "Unknown ROLE: $ROLE"
82+
;;
6883
esac
84+
6985
case "$WITH_SYSTEMD" in
70-
yes) var_append ARGS "--with-systemd-service" ;;
71-
*) var_append ARGS "--without-systemd-service" ;;
86+
yes)
87+
var_append ARGS "--with-systemd-service"
88+
;;
89+
*)
90+
var_append ARGS "--without-systemd-service"
91+
;;
7292
esac
7393

7494
# RHEL 8 requires an SELinux policy
75-
if [ "x$OS" = "xrhel" ] && [ "${OS_VERSION%\.*}" -gt "7" ]; then
95+
if [ "$OS" = "rhel" ] && [ "${OS_VERSION%\.*}" -gt "7" ]; then
7696
var_append ARGS "--with-selinux-policy"
7797
fi
7898

7999
# Cross-compiling Windows?
80100
case "$ARCH-${OS_FAMILY}" in
81-
x86-mingw) var_append ARGS "--host=i686-w64-mingw32" ;;
82-
x64-mingw) var_append ARGS "--host=x86_64-w64-mingw32" ;;
101+
x86-mingw)
102+
var_append ARGS "--host=i686-w64-mingw32"
103+
;;
104+
x64-mingw)
105+
var_append ARGS "--host=x86_64-w64-mingw32"
106+
;;
83107
esac
84108

85109

110+
# Select configure options and compiler flags based on BUILD_TYPE
86111
case "$BUILD_TYPE" in
87-
88-
RELEASE)
89-
CFLAGS="-g2 -O2 -DNDEBUG $CFLAGS"
90-
;;
91-
DEBUG)
92-
ARGS="$ARGS --enable-debug"
93-
# Override the default "-g3 -O0" that comes with ./configure --enable-debug
94-
# in order to reduce the size of the packages
95-
CFLAGS="-g2 -O1 $CFLAGS"
96-
;;
97-
CODE_COVERAGE)
98-
ARGS="$ARGS --enable-debug"
99-
# lcov is not found in Windows and other platforms
100-
case "${OS}-${OS_VERSION}" in
101-
mingw*)
112+
RELEASE)
113+
CFLAGS="-g2 -O2 -DNDEBUG $CFLAGS"
114+
;;
115+
DEBUG)
116+
ARGS="$ARGS --enable-debug"
117+
# Override the default "-g3 -O0" that comes with ./configure --enable-debug
118+
# in order to reduce the size of the packages
119+
CFLAGS="-g2 -O1 $CFLAGS"
120+
;;
121+
*)
122+
fatal "Unknown BUILD_TYPE '$BUILD_TYPE'"
102123
;;
103-
hpux*)
104-
;;
105-
solaris*)
106-
;;
107-
rhel-4.*)
108-
;;
109-
aix*)
110-
;;
111-
*)
112-
ARGS="$ARGS --enable-coverage"
113-
;;
114-
esac
115-
;;
116-
*)
117-
echo "Unknown build type: $BUILD_TYPE"
118-
exit 42
119-
;;
120124
esac
121125

122-
if [ "x$OS" = "xsolaris" ]
123-
then
126+
if [ "$OS" = solaris ]; then
127+
# Otherwise, we pick wrong pkg-config file (from OS), with a lower version of libxml dependency than we would like to have.
124128
export PKG_CONFIG_PATH="$BUILDPREFIX/lib/pkgconfig"
125129
fi
126130

127-
128-
( cd $BASEDIR/core && env $OPTS CFLAGS="$CFLAGS" ./configure $ARGS )
129-
130-
if [ "x$NOVA" = "xyes" ]
131-
then
132-
( cd $BASEDIR/enterprise && env $OPTS CFLAGS="$CFLAGS" ./configure $ARGS )
133-
if [ "x$ROLE" = "xhub" ]
134-
then
135-
( cd $BASEDIR/nova && env $OPTS CFLAGS="$CFLAGS" ./configure $ARGS )
131+
log_debug running configure on core repo...
132+
# shellcheck disable=SC2086
133+
( cd "$BASEDIR"/core && run_and_print_on_failure env $OPTS CFLAGS="$CFLAGS" ./configure $ARGS )
134+
135+
if [ "$NOVA" = yes ]; then
136+
log_debug running configure on enterprise repo...
137+
# shellcheck disable=SC2086
138+
( cd "$BASEDIR"/enterprise && run_and_print_on_failure env $OPTS CFLAGS="$CFLAGS" ./configure $ARGS )
139+
if [ "$ROLE" = hub ]; then
140+
log_debug running configure on nova repo...
141+
# shellcheck disable=SC2086
142+
( cd "$BASEDIR"/nova && run_and_print_on_failure env $OPTS CFLAGS="$CFLAGS" ./configure $ARGS )
136143
fi
137144
fi
138145

139-
( cd $BASEDIR/masterfiles && env $OPTS CFLAGS="$CFLAGS" ./configure $ARGS )
146+
log_debug running configure on masterfiles repo...
147+
# shellcheck disable=SC2086
148+
( cd "$BASEDIR"/masterfiles && run_and_print_on_failure env $OPTS CFLAGS="$CFLAGS" ./configure $ARGS )

0 commit comments

Comments
 (0)