Merge branch 'master' of git.freeside.biz:/home/git/freeside
[freeside.git] / torrus / configure.ac
1 #  Copyright (C) 2002-2010  Stanislav Sinyagin
2 #
3 #  This program is free software; you can redistribute it and/or modify
4 #  it under the terms of the GNU General Public License as published by
5 #  the Free Software Foundation; either version 2 of the License, or
6 #  (at your option) any later version.
7 #
8 #  This program is distributed in the hope that it will be useful,
9 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 #  GNU General Public License for more details.
12 #
13 #  You should have received a copy of the GNU General Public License
14 #  along with this program; if not, write to the Free Software
15 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
16
17 # $Id: configure.ac,v 1.1 2010-12-27 00:03:31 ivan Exp $
18 # Stanislav Sinyagin <ssinyagin@yahoo.com>
19 #
20
21
22 AC_INIT([torrus],[1.0.9],[ssinyagin@users.sourceforge.net])
23 AC_PREREQ([2.59])
24 AC_CONFIG_AUX_DIR(conftools)
25 AC_CANONICAL_HOST
26 AM_INIT_AUTOMAKE(1.9)
27
28 AC_PATH_PROG(PERL, perl, no)
29
30 # Need this for init.torrus
31 AC_PATH_PROG(SU, su, no)
32 AC_PATH_PROG(KILL, kill, no)
33 AC_PATH_PROG(SED, sed, no)
34 AC_PATH_PROG(FIND, find, no)
35 AC_PATH_PROG(RM, rm, no)
36 AC_PATH_PROG(SLEEP, sleep, no)
37
38
39 # This will generate doc pages from POD sources
40 AC_PATH_PROG(POD2TEXT, pod2text, no)
41 AM_CONDITIONAL([POD2TEXT_PRESENT], [test "$POD2TEXT" != no])
42 AC_PATH_PROG(POD2MAN, pod2man, no)
43 AM_CONDITIONAL([POD2MAN_PRESENT], [test "$POD2MAN" != no])
44
45 AC_ARG_ENABLE(pkgonly,
46         [AC_HELP_STRING([--enable-pkgonly],
47                         [Skip all checking])])
48 AC_SUBST(enable_pkgonly)
49
50 AC_ARG_ENABLE(threads,
51         [AC_HELP_STRING([--disable-threads],
52                         [Disable Perl threads usage])])
53         
54 perllibdirs="\'\${perllibdir}\'"
55
56 PERLOPTS=
57 AC_ARG_VAR(PERLINC,  [[] Additional space-separated Perl library paths])
58 if test ! -z "$PERLINC"; then
59    for d in $PERLINC; do
60        PERLOPTS="${PERLOPTS} -I${d}"
61        perllibdirs=${perllibdirs}"\,\'"${d}"\'"
62    done
63 fi
64
65 find_rrdtool () {
66     if ${PERL} -e 'use RRDs' 2>/dev/null; then :; else
67         if test "$enable_pkgonly" != yes; then
68             AC_MSG_NOTICE([RRDs.pm is not in default Perl search paths.])
69             AC_MSG_CHECKING([RRDtool in /usr/local/rrdtool*])
70             with_rrdtool=`ls -1dr /usr/local/rrdtool* | head -1`
71             if test -d $with_rrdtool; then
72                AC_MSG_RESULT([${with_rrdtool}])
73             else
74                AC_MSG_ERROR([Cannot find RRDtool])
75             fi
76             test_rrdtool
77         else
78             with_rrdtool="/usr/local/rrdtool"
79         fi
80     fi
81 }
82
83 test_rrdtool () {
84     if test "$enable_pkgonly" != yes; then
85         if ${PERL} -I${with_rrdtool}/lib/perl -e 'use RRDs'; then :; else
86             AC_MSG_ERROR([Could not find RRDs perl module in ${with_rrdtool}])
87         fi
88     fi
89     perllibdirs=${perllibdirs}"\,\'"${with_rrdtool}"/lib/perl/\'"
90 }
91
92 AC_ARG_WITH(rrdtool,
93         [AC_HELP_STRING(--with-rrdtool=DIR,RRDTool location)],
94         test_rrdtool, find_rrdtool)
95
96 AC_SUBST(perllibdirs, [${perllibdirs}])
97
98
99 # Check the necessary Perl modules
100
101 if test "$enable_pkgonly" != yes; then
102
103    for module in 'BerkeleyDB' 'XML::LibXML' 'Template' \
104                  'Proc::Daemon' 'Net::SNMP' 'URI::Escape' 'Apache::Session' \
105                  'Date::Parse' 'JSON'
106    do
107      AC_MSG_CHECKING([presence of $module])
108      if ${PERL} ${PERLOPTS} -e 'use '$module 2>/dev/null; then
109          AC_MSG_RESULT([Ok])
110      else
111          AC_MSG_ERROR([Perl cannot find $module]);
112      fi
113    done
114
115 #  Check if Perl threads can be used.
116 #  Requirements are: perl 5.8.8 with threads compiled,
117 #  threads ver. 1.41 or higher, threads::shared ver. 1.03 or higher
118    
119    perlithreads=1
120    if test x"$enable_threads" = xno; then
121      perlithreads=0     
122    else
123    
124      AC_MSG_CHECKING([if Perl version is 5.8.8 or higher])
125      if ${PERL} ${PERLOPTS} -e 'use 5.8.8' 2>/dev/null; then
126        AC_MSG_RESULT([Ok])
127      else
128        perlithreads=0
129      fi       
130
131      if test ${perlithreads} -eq 1; then
132        AC_MSG_CHECKING([threading support in Perl])
133        if ${PERL} ${PERLOPTS} -e 'use threads' 2>/dev/null; then
134          AC_MSG_RESULT([Ok])
135        else
136          perlithreads=0
137        fi
138      fi
139
140      if test ${perlithreads} -eq 1; then     
141        AC_MSG_CHECKING([if threads module version is 1.41 or higher])
142        if ${PERL} ${PERLOPTS} -e \
143          'use threads; exit($threads::VERSION >= 1.41 ? 0:1)'; then
144            AC_MSG_RESULT([Ok])
145        else
146            perlithreads=0
147        fi
148      fi
149
150      if test ${perlithreads} -eq 1; then  
151        AC_MSG_CHECKING([if threads::shared module version is 1.03 or higher])
152        if ${PERL} ${PERLOPTS} -e \
153          'use threads; use threads::shared;
154           exit($threads::shared::VERSION >= 1.03 ? 0:1)'; then
155            AC_MSG_RESULT([Ok])
156        else         
157            perlithreads=0
158        fi
159      fi
160      
161      if test ${perlithreads} -eq 0; then  
162        AC_MSG_RESULT([No. Multithreading will not be used.])
163      fi
164           
165    fi
166    AC_SUBST(perlithreads, [${perlithreads}])   
167 fi
168
169 AC_ARG_VAR(torrus_user,  [[torrus] UID to run the daemons])
170 if test -z "$torrus_user"; then
171    torrus_user=torrus; fi
172
173 if test "$enable_pkgonly" != yes; then
174     AC_MSG_CHECKING([if user ${torrus_user} exists])
175     torrus_check_file=torrus_usercheck_$$
176     torrus_check_error=no
177     if ! touch ${torrus_check_file}; then
178         AC_MSG_ERROR([Cannot create ${torrus_check_file}])
179     elif ! chown ${torrus_user} ${torrus_check_file}; then
180         torrus_check_error=yes
181     fi
182     rm -f ${torrus_check_file}
183     if test ${torrus_check_error} = yes; then
184         AC_MSG_ERROR([User ${torrus_user} does not exist])
185     else
186         AC_MSG_RESULT([Ok])
187     fi
188 fi
189    
190
191 # Set the var/db and var/cache ownership
192
193 AC_ARG_VAR(var_user,  [[TORRUS_USER] Owner of db and cache directories])
194 AC_ARG_VAR(var_group, [[torrus] Group of db and cache directories])
195 AC_ARG_VAR(var_mode,  [[775] Mode of db and cache directories])
196
197 AC_ARG_ENABLE(varperm,
198         [AC_HELP_STRING(--disable-varperm,
199         Disable db and cache access rights tuning)],
200         [],
201         [enable_varperm="yes"])
202 AC_SUBST(enable_varperm)
203
204 AC_ARG_VAR(pkghome,   [[PREFIX/torrus] Place for Torrus static files])
205 if test -z "$pkghome"; then
206    pkghome='${prefix}/torrus'; fi
207
208 AC_ARG_VAR(pkgbindir,   [[PKGHOME/bin] Torrus executables])
209 if test -z "$pkgbindir"; then
210    pkgbindir='${pkghome}/bin'; fi
211
212 AC_ARG_VAR(cfgdefdir,   [[PKGHOME/conf_defaults] torrus-config.pl and others])
213 if test -z "$cfgdefdir"; then
214    cfgdefdir='${pkghome}/conf_defaults'; fi
215
216 AC_ARG_VAR(pkgdocdir, [[PKGHOME/doc] Documentation files])
217 if test -z "$pkgdocdir"; then
218    pkgdocdir='${pkghome}/doc'; fi
219
220 AC_ARG_VAR(exmpdir, [[PKGHOME/examples] Examples])
221 if test -z "$exmpdir"; then
222    exmpdir='${pkghome}/examples'; fi
223
224 AC_ARG_VAR(perllibdir,  [[PKGHOME/perllib] Torrus Perl libraries])
225 if test -z "$perllibdir"; then
226    perllibdir='${pkghome}/perllib'; fi
227
228 AC_ARG_VAR(pluginsdir,   [[PKGHOME/plugins] Plugin configurations])
229 if test -z "$pluginsdir"; then
230    pluginsdir='${pkghome}/plugins'; fi
231
232 AC_ARG_VAR(plugtorruscfgdir, [[PLUGINSDIR/torrus-config]])
233 if test -z "$plugtorruscfgdir"; then
234    plugtorruscfgdir='${pluginsdir}/torrus-config'; fi
235
236 AC_ARG_VAR(plugdevdisccfgdir, [[PLUGINSDIR/devdiscover-config]])
237 if test -z "$plugdevdisccfgdir"; then
238    plugdevdisccfgdir='${pluginsdir}/devdiscover-config'; fi
239
240 AC_ARG_VAR(plugwrapperdir, [[PLUGINSDIR/wrapper]])
241 if test -z "$plugwrapperdir"; then
242    plugwrapperdir='${pluginsdir}/wrapper'; fi
243
244       
245 AC_ARG_VAR(scriptsdir, [[PKGHOME/scripts] Script files])
246 if test -z "$scriptsdir"; then
247    scriptsdir='${pkghome}/scripts'; fi
248
249 AC_ARG_VAR(supdir, [[PKGHOME/sup] Supplementary files])
250 if test -z "$supdir"; then
251    supdir='${pkghome}/sup'; fi
252
253 AC_ARG_VAR(webplaindir, [[SUPDIR/webplain] Web interface plain files path])
254 if test -z "$webplaindir"; then
255    webplaindir='${supdir}/webplain'; fi
256
257 AC_ARG_VAR(webscriptsdir,
258         [[SUPDIR/webscripts] Directory for optional web scripts])
259 if test -z "$webscriptsdir"; then
260    webscriptsdir='${supdir}/webscripts'; fi
261
262 AC_ARG_VAR(tmpldir, [[PKGHOME/templates] Template files])
263 if test -z "$tmpldir"; then
264    tmpldir='${pkghome}/templates'; fi
265
266 AC_ARG_VAR(distxmldir, [[PKGHOME/xmlconfig] Distribution XML config files])
267 if test -z "$distxmldir"; then
268    distxmldir='${pkghome}/xmlconfig'; fi
269
270 AC_ARG_VAR(sitedir, [[SYSCONFDIR/torrus] Site configuration files])
271 if test -z "$sitedir"; then
272    sitedir='${sysconfdir}/torrus'; fi
273
274 AC_ARG_VAR(siteconfdir, [[SITEDIR/conf] Site configuration files])
275 if test -z "$siteconfdir"; then
276    siteconfdir='${sitedir}/conf'; fi
277
278 AC_ARG_VAR(tmpluserdir, [[SITEDIR/templates] User-defined Template files])
279 if test -z "$tmpluserdir"; then
280    tmpluserdir='${sitedir}/templates'; fi
281
282 AC_ARG_VAR(sitexmldir, [[SITEDIR/xmlconfig] Site XML configs])
283 if test -z "$sitexmldir"; then
284    sitexmldir='${sitedir}/xmlconfig'; fi
285
286 AC_ARG_VAR(logdir, [[/var/log/torrus] Log files])
287 if test -z "$logdir"; then
288    logdir='/var/log/torrus'; fi
289
290 AC_ARG_VAR(piddir, [[/var/run/torrus] PID files])
291 if test -z "$piddir"; then
292    piddir='/var/run/torrus'; fi
293
294 AC_ARG_VAR(varprefix, [[/var/torrus] Common prefix for runtime data])
295 if test -z "$varprefix"; then
296    varprefix='/var/torrus'; fi
297    
298 AC_ARG_VAR(cachedir, [[VARPREFIX/cache] Renderer cache])
299 if test -z "$cachedir"; then
300    cachedir='${varprefix}/cache'; fi
301
302 AC_ARG_VAR(dbhome, [[VARPREFIX/db] Berkeley DB files])
303 if test -z "$dbhome"; then
304    dbhome='${varprefix}/db'; fi
305
306 AC_ARG_VAR(reportsdir, [[VARPREFIX/reports] Reports output])
307 if test -z "$reportsdir"; then
308    reportsdir='${varprefix}/reports'; fi
309
310 AC_ARG_VAR(seslockdir, [[VARPREFIX/session_data/lock] Web session locks])
311 if test -z "$seslockdir"; then
312    seslockdir='${varprefix}/session_data/lock'; fi
313
314 AC_ARG_VAR(sesstordir, [[VARPREFIX/session_data/store] Web session storage])
315 if test -z "$sesstordir"; then
316    sesstordir='${varprefix}/session_data/store'; fi
317
318 AC_ARG_VAR(wrapperdir, [[BINDIR] CLI wrapper])
319 if test -z "$wrapperdir"; then
320    wrapperdir='${bindir}'; fi
321
322 AC_ARG_VAR(mansec_usercmd, [[1] User commands man section])
323 if test -z "$mansec_usercmd"; then
324    mansec_usercmd='1'; fi
325
326 AC_ARG_VAR(mansec_misc, [[7] Miscellaneous man section])
327 if test -z "$mansec_misc"; then
328    mansec_misc='7'; fi
329
330 AC_ARG_VAR(defrrddir, [[/srv/torrus/collector_rrd] Default RRD storage path])
331 if test -z "$defrrddir"; then
332    defrrddir='/srv/torrus/collector_rrd'; fi
333
334    
335 AC_CONFIG_FILES([Makefile bin/Makefile configs/Makefile])
336 AC_CONFIG_FILES([doc/Makefile doc/manpages/Makefile])
337 AC_CONFIG_FILES([examples/Makefile perllib/Makefile])
338 AC_CONFIG_FILES([sup/Makefile xmlconfig/Makefile])
339                                     
340 AC_CONFIG_FILES([setup_tools/substvars.sh],[chmod +x setup_tools/substvars.sh])
341 AC_CONFIG_FILES([setup_tools/mkvardir.sh], [chmod +x setup_tools/mkvardir.sh])
342 AC_CONFIG_FILES([init.d/torrus], [chmod +x init.d/torrus])
343
344 AC_SUBST(VERSION)
345
346 AC_OUTPUT
347
348 VARSAVE=configs/instvars
349 echo creating $VARSAVE
350 rm -f $VARSAVE
351 for VAR in $ac_subst_vars; do
352     case ${VAR} in
353       DEFS | PACKAGE* | INSTALL* | VERSION | ACLOCAL | AUTO* | MAKEINFO |\
354       install_sh | AM* | am* | ac* | ECHO* | build* | host* | target* |\
355       CYG* | PATH_SEPARATOR | AWK | STRIP | mkdir* |\
356       perllibdirs )
357       ;;
358       *)
359         eval 'VAL=${'$VAR'}'
360         echo ${VAR}=\'${VAL}\' >>$VARSAVE
361       ;;
362     esac
363 done