1dnl ##########################################################################
2dnl #
3dnl # Build CFEngine
4dnl #
5dnl # Run ./autogen.sh to build configure script
6dnl #
7dnl ##########################################################################
8
9AC_PREREQ(2.63)
10
11
12m4_define([cfversion_from_env], m4_normalize(m4_esyscmd([echo $EXPLICIT_VERSION])))
13m4_define([cfversion_from_file], m4_normalize(m4_esyscmd([cat CFVERSION])))
14m4_ifval(cfversion_from_env, [
15    m4_define([cfversion], cfversion_from_env)
16], [
17    m4_ifval(cfversion_from_file, [
18        m4_define([cfversion], cfversion_from_file)
19    ], [
20        m4_fatal([Could not determine CFEngine version;
21                  please set EXPLICIT_VERSION in the environment,
22                  or make sure all git tags are up to date and rerun autogen.sh])
23    ])
24])
25
26
27AC_INIT([cfengine-masterfiles], cfversion)
28
29cfengine_version=cfversion
30
31m4_undefine([cfversion])
32m4_undefine([cfversion_from_file])
33m4_undefine([cfversion_from_env])
34
35m4_define([cfrelease], m4_normalize(m4_esyscmd([cat CFRELEASE])))
36AC_SUBST([RELEASE], [cfrelease])
37cfengine_release=cfrelease
38m4_undefine([cfrelease])
39
40AC_CANONICAL_TARGET
41
42_AM_SET_OPTION([tar-ustar])
43AM_INIT_AUTOMAKE([foreign])
44AM_MAINTAINER_MODE([enable])
45
46AC_DEFINE_UNQUOTED(ABS_TOP_SRCDIR,
47"`cd -- "$srcdir"; pwd`",
48[Absolute path of source tree])
49
50m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
51
52dnl Libtool madness
53
54AC_CONFIG_MACRO_DIR([m4])
55
56dnl
57dnl hide [s]include macros, so old aclocal (automake < 1.10) won't find them and
58dnl won't complain about something/something.m4 not found
59dnl
60m4_define(incstart,sinc)
61m4_define(incend,lude)
62
63AC_PROG_MKDIR_P
64
65AC_PROG_INSTALL
66
67dnl ######################################################################
68dnl Figure out core and enterprise directory.
69dnl ######################################################################
70
71AC_ARG_WITH(core,
72    AS_HELP_STRING(--with-core=<core>,
73        [Build against core in directory <core>. Defaults to "../core". \
74        If not found there or if --with-core=no then tests are disabled]
75    ),
76    AS_IF(test "x$with_core" == "xno",
77    [
78        core_dir=
79    ],
80    [
81        dnl The user passed --with-core=path but we must check if it's a
82        dnl valid core directory.
83        AS_IF(test -d "$with_core/libpromises",
84        [
85            core_dir="$with_core"
86        ],
87        [
88            AC_MSG_ERROR([$with_core is not a valid core directory (--with-core=$with_core)])
89        ])
90    ]),
91
92    dnl If --with-core was not passed at all, then default to ../core
93    dnl only if that is a valid core directory.
94    [if test -d `pwd`/../core/libpromises
95    then
96        core_dir="`pwd`/../core"
97    else
98        core_dir=
99    fi]
100)
101
102dnl export HAVE_CORE for makefiles
103AM_CONDITIONAL(HAVE_CORE, test "x$core_dir" != x)
104dnl Transform the path from relative to absolute
105AS_IF(test "x$core_dir" != x,
106    [
107        AS_CASE([$core_dir], [/*], [],
108            [core_dir=`pwd`/$core_dir])
109    ]
110)
111AC_SUBST([core_dir])
112
113
114AC_ARG_WITH(enterprise,
115    AS_HELP_STRING(--with-enterprise=<enterprise>,
116        [Build against enterprise in directory <enterprise>. \
117        Defaults to "../enterprise"]
118    ),
119    AS_IF(test "x$with_enterprise" == "xno",
120    [
121        enterprise_dir=
122    ],
123    [
124        enterprise_dir=$with_enterprise
125    ]),
126    enterprise_dir=`pwd`/../enterprise
127)
128AS_CASE([$enterprise_dir], [/*], [], [enterprise_dir=`pwd`/$enterprise_dir])
129AM_CONDITIONAL([HAVE_ENTERPRISE], [test -d "$enterprise_dir/libcfenterprise"])
130AC_SUBST([enterprise_dir])
131
132dnl ######################################################################
133dnl Set prefix to correct directory.
134dnl ######################################################################
135
136AS_IF([test x"$prefix" = xNONE],
137    prefix=/var/cfengine
138)
139
140bindir="${bindir:-${exec_prefix}/bin}"
141dnl Expand ${prefix} and whatnot in bindir
142adl_RECURSIVE_EVAL("${bindir}", bindir)
143AC_SUBST(bindir, "${bindir}")
144
145dnl ######################################################################
146dnl OS specific stuff
147dnl ######################################################################
148
149m4_include([m4/cf3_platforms.m4])
150
151AC_CHECK_PROG([ac_cv_pkg_install], [pkg_install], [yes], [no])
152AC_CHECK_PROG([ac_cv_shunit2], [shunit2], [yes], [no])
153
154AM_CONDITIONAL([HAVE_PKG_INSTALL], [test "$ac_cv_pkg_install" = "yes"])
155AM_CONDITIONAL([HAVE_SHUNIT2], [test "$ac_cv_shunit2" = "yes"])
156
157dnl ######################################################################
158dnl Print summary
159dnl ######################################################################
160
161AC_MSG_RESULT()
162AC_MSG_RESULT(Summary:)
163AC_MSG_RESULT(Version              -> $cfengine_version)
164AC_MSG_RESULT(Release              -> $cfengine_release)
165AM_COND_IF(HAVE_CORE,
166    AC_MSG_RESULT(Core directory       -> $core_dir),
167    AC_MSG_RESULT(Core directory       -> not set - tests are disabled)
168)
169AM_COND_IF(HAVE_ENTERPRISE,
170    AC_MSG_RESULT(Enterprise directory -> $enterprise_dir),
171    AC_MSG_RESULT(Enterprise directory -> not set - some tests are disabled)
172)
173AC_MSG_RESULT(Install prefix       -> $prefix)
174AC_MSG_RESULT(bindir               -> $bindir)
175AC_MSG_RESULT()
176
177
178dnl ######################################################################
179dnl Generate install target list.
180dnl ######################################################################
181
182AC_MSG_NOTICE([generating makefile targets])
183
184# Do not try to unroll these for loops by putting the find commands directly in
185# the assignments, it will overflow on the Solaris and HP-UX shells.
186MASTERFILES_TESTS=''
187for i in `cd "$srcdir/tests/acceptance/" && find . -name '*.cf*'`
188do
189    MASTERFILES_TESTS="$MASTERFILES_TESTS $i"
190done
191AC_SUBST(MASTERFILES_TESTS)
192
193MASTERFILES_INSTALL_TARGETS=
194for j in `echo $srcdir/*.cf`
195do
196    # Only add those that don't have a corresponding .in file.
197    # They will be added later.
198    if ! test -f "$j.in"
199    then
200        MASTERFILES_INSTALL_TARGETS="$MASTERFILES_INSTALL_TARGETS $j"
201    fi
202done
203for j in `echo $srcdir/*.cf.in`
204do
205    # Add .in files, but without the .in suffix.
206    MASTERFILES_INSTALL_TARGETS="$MASTERFILES_INSTALL_TARGETS `echo $j | sed -e 's/\.in$//'`"
207done
208
209for i in cfe_internal controls inventory lib services
210do
211    for j in `find "$srcdir/$i" -name '*.cf'`
212    do
213        # Only add those that don't have a corresponding .in file.
214        # They will be added later.
215        if ! test -f "$j.in"
216        then
217            MASTERFILES_INSTALL_TARGETS="$MASTERFILES_INSTALL_TARGETS $j"
218        fi
219    done
220    for j in `find "$srcdir/$i" -name '*.cf.in'`
221    do
222        # Add .in files, but without the .in suffix.
223        MASTERFILES_INSTALL_TARGETS="$MASTERFILES_INSTALL_TARGETS `echo $j | sed -e 's/\.in$//'`"
224    done
225done
226for i in templates cfe_internal modules/packages/vendored
227do
228    for j in `find "$srcdir/$i" -name '*.mustache' -o -name '*.sh' -o -name '*.awk' -o -name '*.sed' -o -name '*.ps1'`
229    do
230        MASTERFILES_INSTALL_TARGETS="$MASTERFILES_INSTALL_TARGETS $j"
231    done
232done
233
234
235AC_SUBST(MASTERFILES_INSTALL_TARGETS)
236
237dnl ######################################################################
238dnl Now make the Makefiles
239dnl ######################################################################
240
241AC_CONFIG_FILES([Makefile
242                controls/update_def.cf
243                promises.cf
244                standalone_self_upgrade.cf
245                tests/Makefile
246                tests/acceptance/Makefile
247                tests/unit/Makefile
248])
249
250AC_OUTPUT
251
252
253AC_MSG_RESULT()
254AC_MSG_RESULT(DONE: Configuration done. Run "make install" to install CFEngine Masterfiles.)
255AC_MSG_RESULT()
256