Fix bug in configure, it wasn't looking the correct plugin dir. Added ABOUT option...
[MonkeyD.git] / configure
blob27aa6a260176eee8610f98ef40f24476ccfdca23
1 #!/bin/bash
3 # Monkey HTTP Daemon
4 # ------------------
5 # Copyright (C) 2001-2009, Eduardo Silva P.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Library General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 VERSION="0.11.0-dev"
22 SYSNAME=`uname -s`
23 SYSINFO=`uname -sr`
25 INCDIR="src/include/"
27 messages_en()
29 case "$*" in
30 "1")
31 echo "+ Creating conf/monkey.conf"
33 "2")
34 echo "+ Creating Makefile"
36 "3")
37 echo "+ Creating src/Makefile"
39 "4")
40 echo "+ Creating src/include/info.h"
42 "5")
43 echo "+ Creating banana script"
45 "6")
46 echo -n "Configuration done, just type 'make"
48 "7")
49 echo -n "+ Checking for Pthreads lib.........."
51 esac
54 # Create configuration files under 'conf/'
55 make_conf()
57 cat $INCDIR/config.path lang/"$*"/mconf lang/"$*"/sites/default > makeconf.sh
58 chmod 755 makeconf.sh
59 ./makeconf.sh
60 rm makeconf.sh
61 rm $INCDIR/config.path
64 local_dirs()
66 bin="bin"
67 logs="logs"
68 sites="conf/sites"
70 if [ ! -d $bin ]; then
71 mkdir $bin
74 if [ ! -d $logs ]; then
75 mkdir $logs
78 if [ ! -d $sites ]; then
79 mkdir $sites
84 main()
86 local_dirs
87 dir=0
88 actual_path=`pwd`
90 if [ "$prefix" != "$actual_path" ]; then
91 dir=1
94 if [ "$bindir" != "$actual_path/bin" ]; then
95 dir=1
98 if [ "$cgibin" != "$actual_path/cgi-bin" ]; then
99 dir=1
102 if [ "$sysconfdir" != "$actual_path/conf" ]; then
103 dir=1
106 if [ "$datadir" != "$actual_path/htdocs" ]; then
107 dir=1
110 if [ "$logdir" != "$actual_path/logs" ]; then
111 dir=1
114 echo
115 echo "Checking dependencies"
116 echo "====================="
117 echo
118 messages_$lang "7"
119 check_lib lang
121 echo
122 echo "Creating Makefiles and scripts"
123 echo "=============================="
124 echo
126 messages_$lang "1"
127 create_conf prefix bindir cgibin sysconfdir datadir logdir
129 make_conf $lang
130 messages_$lang "2"
132 if [ "$dir" = 0 ]; then
133 create_makefile1 bindir
134 else
135 create_makefile1_install prefix bindir cgibin sysconfdir datadir logdir
138 messages_$lang "3"
139 create_makefile2 mod_libs mod_obj make_script add_obj_mod cheetah_obj
141 messages_$lang "4"
142 create_info sysconfdir SYSNAME VERSION
144 messages_$lang "5"
145 create_banana_script bindir logdir
146 echo
147 messages_$lang "6"
149 if [ "$dir" = 1 ]; then
150 echo -n " && make install' "
151 else
152 echo "' "
154 echo
156 create_makefile_plugins $plugdir
158 echo "#define CC \"${CC}\"" > src/include/env.h
161 # Check pthreads lib
162 check_lib()
164 cat > check.c <<EOF
165 #include <pthread.h>
166 int main(){ return 0;}
169 libtest=`gcc check.c -lpthread &>configure.log`
170 libstatus=`cat configure.log`
171 if test -n "$libstatus" ; then
172 echo "no"
173 rm -fr check* configure.log
174 exit 1
176 echo "yes"
177 rm -fr check* configure.log a.out
181 # Create Makefile
182 create_makefile1()
184 cat > Makefile << EOF
185 # Monkey HTTP Daemon: Makefile
186 # ============================
187 default:
188 @(cd src; make all)
190 plugins:
191 @(cd plugins; make all)
193 clean:
194 @(cd src; make clean)
195 distclean:
196 @(cd src; make distclean)
200 create_makefile1_install()
202 # Look for plugins and create list
203 for entry in plugins/*
205 if [ -d $entry ]; then
206 echo -e "\tinstall -s -m 644 $entry/*.so \${PLUGINDIR}" >> plugins.list
208 done;
209 plglist=`cat plugins.list`
210 rm -rf plugins.list
212 # Look for plugins configuration
213 for entry in conf/plugins/*
215 if [ -d $entry ]; then
216 echo -e "\tcp -r $entry \${SYSCONFDIR}/plugins/" >> plugins.conf
218 done;
219 plgconf=`cat plugins.conf`
220 rm -rf plugins.conf
222 cat > Makefile <<EOF
223 # Monkey HTTP Daemon: Makefile
224 # ============================
225 PREFIX=\$(DESTDIR)${prefix}
226 BINDIR=\$(DESTDIR)${bindir}
227 CGIBIN=\$(DESTDIR)${cgibin}
228 SYSCONFDIR=\$(DESTDIR)${sysconfdir}
229 DATADIR=\$(DESTDIR)${datadir}
230 LOGDIR=\$(DESTDIR)${logdir}
231 PLUGINDIR=\$(DESTDIR)${plugdir}
233 default:
234 @(cd src; make all)
235 clean:
236 @(cd src; make clean)
237 distclean:
238 @(cd src; make distclean)
240 install:
241 make -C src all
242 install -d \$(BINDIR)
243 install -d \$(CGIBIN)
244 install -d \$(SYSCONFDIR)
245 install -d \${SYSCONFDIR}/sites
246 install -d \${SYSCONFDIR}/plugins
247 install -d \$(DATADIR)
248 install -d \${DATADIR}/imgs
249 install -d \${DATADIR}/php
250 install -d \${DATADIR}/docs
251 install -d \${LOGDIR}
252 install -d \${PLUGINDIR}
253 install -m 755 bin/monkey \$(BINDIR)
254 $STRIP \$(BINDIR)/monkey
255 install -m 755 bin/banana \$(BINDIR)
256 install -m 644 ./conf/*.* \$(SYSCONFDIR)
257 $plgconf
258 install -m 644 ./conf/sites/* \${SYSCONFDIR}/sites
259 $plglist
260 install -m 644 ./htdocs/*.* \$(DATADIR)
261 install -m 644 ./htdocs/imgs/*.* \${DATADIR}/imgs
262 @echo
263 @echo " Running Monkey :"
264 @echo " ----------------"
265 @echo
266 @echo " # $bindir/monkey"
267 @echo
268 @echo " For more help use '-h' option"
269 @echo
274 # Create monkey/src/Makefile
275 create_makefile2()
278 cat > src/Makefile<<EOF
279 CC = $CC
280 CFLAGS = $CFLAGS
281 DEFS = $DEFS
282 INCDIR = ./include
283 LDFLAGS =
284 DESTDIR = ../bin/monkey
285 LIBS = -ldl -lpthread $mod_libs $MORE_LIBS
286 OBJ = monkey.o method.o mimetype.o request.o \\
287 header.o config.o logfile.o signals.o \\
288 user.o utils.o chars.o epoll.o scheduler.o \\
289 str.o memory.o connection.o iov.o http.o \\
290 file.o socket.o clock.o cache.o worker.o \\
291 server.o plugin.o \\
292 $add_obj_mod
294 all: ../bin/monkey
296 ../bin/monkey: \$(OBJ)
297 @echo
298 @echo "Compiling Monkey"
299 @echo "================"
300 \$(CC) \$(CFLAGS) \$(DEFS) \$(LIBS) \$(LDFLAGS) -o \$@ \$(OBJ) $mod_obj
301 @echo
302 @echo "Compiling Plugins"
303 @echo "================="
304 @(cd ../plugins && make all && cd ..)
306 clean:
307 rm -rf *.o
308 rm -rf ../bin/monkey
310 distclean:
311 rm -rf *.o ../bin/* Makefile \\
312 ../Makefile ../conf/monkey.conf \\
313 ../conf/sites/* include/info.h ../logs/*\\
315 .c.o:
316 \$(CC) -c \$(CFLAGS) \$(DEFS) -I\$(INCDIR) \$<
320 create_makefile_plugins()
322 cd plugins
323 cat > Makefile <<EOF
324 all:
326 dir=`pwd`
327 plugins_load="../conf/plugins.load"
328 echo -n > $plugins_load
329 echo "# Monkey plugins are loaded on run, by default all " >> $plugins_load
330 echo "# plugins are disabled, if you want to enable" >> $plugins_load
331 echo "# one, just remove the comment character for each line" >> $plugins_load
332 echo "" >> $plugins_load
334 for plugin_dir in `echo */ "" | sed "s/\/ /\n/g"`;
336 comment=""
337 if test -e $plugin_dir/DISABLED ; then
338 continue
341 if test -e $plugin_dir/MANDATORY ; then
342 comment=""
345 if test -e $plugin_dir/OPTIONAL ; then
346 comment="#"
349 echo " @(cd $plugin_dir && make && cd ..)" >> Makefile;
350 sed -e "s/\$CFLAGS/$CFLAGS/" -e "s/\$DEFS/$DEFS/" $plugin_dir/Makefile.in > $plugin_dir/Makefile
352 if test -e $plugin_dir/ABOUT ; then
353 cat $plugin_dir/ABOUT | sed -e 's/^/#/' >> ../conf/plugins.load
356 if [ "$plugdir" != "" ]; then
357 echo "${comment}LoadPlugin $plugdir/monkey-$plugin_dir.so" >> ../conf/plugins.load
358 else
359 echo "${comment}LoadPlugin $dir/$plugin_dir/monkey-$plugin_dir.so" >> ../conf/plugins.load
361 done
363 # Add 'install' option to make file if plugdir was specified
364 if [ "$plugdir" != "" ]; then
365 echo -e "\ninstall:" >> Makefile
366 echo -e "\tinstall -d $plugdir" >> Makefile
368 list=`echo */ "" | sed "s/\/ /\n/g"`
369 for i in $list;
371 echo -e "\tinstall -m 644 $dir/$i/monkey-$i.so $plugdir/" >> Makefile
372 done
374 cd ..
377 # Creando include/info.h
378 create_info()
380 cat > $INCDIR/info.h <<EOF
381 #define OS "$SYSNAME"
382 #define VERSION "$VERSION" /* Version de Monkey */
383 #define MONKEY_PATH_CONF "$sysconfdir"
387 create_conf()
389 cat > $INCDIR/config.path <<EOF
390 #!/bin/sh
391 prefix=$prefix
392 bindir=$bindir
393 cgibin=$cgibin
394 sysconfdir=$sysconfdir
395 datadir=$datadir
396 logdir=$logdir
400 create_banana_script()
402 cat > bin/banana << EOF
403 #!/bin/sh
405 # Monkey HTTP Daemon - Banana Script
406 # -----------------------------------
407 # This script allow you to control monkey. Written by Eduardo Silva
408 # ----------------------------
409 # Date : 2002/09/01.
410 # ----------------------------
412 # Use: ./banana OPTION
414 # Options available to banana:
416 # start -> start monkey
417 # restart -> restart monkey
418 # stop -> stop monkey if this is running
419 # help -> what do u think ?
421 PIDFILE="$logdir/monkey.pid"
422 BINMONKEY="$bindir/monkey"
424 for arg in \$*; do
425 case "\$arg" in
426 -*=*) optarg=\`echo "\$arg" | sed 's/[-_a-zA-Z0-9]*=//'\` ;;
427 *) optarg= ;;
428 esac
430 if ! test -f \$PIDFILE ; then
431 STATUS="no"
432 else
433 PIDMONKEY=\`cat \$PIDFILE\`
434 if ! kill -0 \$PIDMONKEY 2>/dev/null; then
435 STATUS="no"
436 else
437 STATUS="yes"
441 case "\$arg" in
442 start)
443 if [ "\$STATUS" = "yes" ] ; then
444 echo "Monkey is running... (PID=\$PIDMONKEY)"
445 exit 1
447 if ! test -x \$BINMONKEY ; then
448 echo "Error: I can't run binary file"
449 exit 1
450 else
451 if \$BINMONKEY -D 2>/dev/null ; then
452 echo "Running Monkey -> OK"
453 exit 0
457 stop)
458 if [ "\$STATUS" = "no" ]; then
459 echo "Monkey is not running."
460 exit 1
462 kill -9 \$PIDMONKEY
463 rm -rf \$PIDFILE > /dev/null
464 echo "Monkey stopped (\$PIDMONKEY)"
465 exit 0
467 restart)
468 if [ "\$STATUS" = "yes" ]; then
469 if ! kill \$PIDMONKEY > /dev/null ; then
470 killall -9 monkey
471 else
472 echo -n "Stopping Monkey... "
474 else
475 echo -n "Monkey is not running... "
477 if ! test -x \$BINMONKEY ; then
478 echo "Error: I can't run binary file"
479 exit 1
480 else
481 \$BINMONKEY -D > /dev/null
482 echo "Restarting -> OK"
483 exit 0
487 echo "Use : banana [start|stop|restart|help]"
488 exit 1
490 esac
491 done
492 echo "Use : banana [start|stop|restart|help]"
494 exit 0
496 chmod 755 bin/banana
499 #---------------------------#
500 # End Functions
501 #---------------------------#
504 #---------------------------#
505 # Starting configure
506 #---------------------------#
507 aux=`pwd`
509 prefix="$aux"
510 bindir="$aux/bin"
511 cgibin="$aux/cgi-bin"
512 sysconfdir="$aux/conf"
513 datadir="$aux/htdocs"
514 logdir="$aux/logs"
515 plugdir=""
517 for arg in $*; do
518 case "$arg" in
519 -*=*)
520 optarg=`echo "$arg" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
521 *) optarg= ;;
522 esac
524 case "$arg" in
525 --prefix*)
526 prefix=$optarg
527 bindir="$optarg/bin"
528 cgibin="$optarg/cgi-bin"
529 sysconfdir="$optarg/conf"
530 datadir="$optarg/htdocs"
531 logdir="$optarg/logs"
532 plugdir="$optarg/plugins"
534 --bindir*)
535 bindir=$optarg
537 --cgibin*)
538 cgibin=$optarg
540 --sysconfdir*)
541 sysconfdir=$optarg
543 --datadir*)
544 datadir=$optarg
546 --logdir*)
547 logdir=$optarg
549 --plugdir*)
550 plugdir=$optarg
552 --debug*)
553 debug=1
555 --trace*)
556 trace=1
558 --version*)
559 echo "Monkey HTTP Daemon v$VERSION"
560 echo "-------------------------"
561 echo "Copyright 2001-2010"
562 echo "Developed by Eduardo Silva Pereira"
563 echo "Monkey Home : http://www.monkey-project.com"
564 echo "Contact Email : edsiper@gmail.com"
565 echo
566 exit 1
569 echo "Usage: configure [--prefix=PREFIXDIR] [ --bindir=BINDIR]"
570 echo " [--sysconfdir=SYSCONFDIR] [--datadir=DATADIR]"
571 echo " [--logdir=LOGDIR] [--plugdir=PLUGDIR]"
572 echo
573 echo "Options: "
574 echo " --help Display this help and exit"
575 echo " --version Display version information and exit"
576 echo " --debug Compile Monkey with debugging symbols"
577 echo " --trace Compile Monkey with trace messages (don't use in production)"
578 echo
579 echo " --prefix=PREFIX Install Monkey under PREFIX directory"
580 echo " --bindir=BINDIR Install Monkey binaries under BINDIR directory"
581 echo " --sysconfdir=SYSCONFDIR Install Monkey conf files under SYSCONFDIR dir"
582 echo " --datadir=DATADIR Install Monkey data dir files under DATADIR directory"
583 echo " --logdir=LOGDIR Install Monkey log files under LOGDIR directory"
584 echo " --plugdir=PLUGDIR Target directory for Monkey plugins"
585 echo
586 exit 1
588 esac
589 done
591 echo "********************************************"
592 echo " Monkey HTTP Daemon v$VERSION "
593 echo "* http://www.monkey-project.com *"
594 echo "* ---------------------------------------- *"
595 echo "* We need beta testers, developers and *"
596 echo "* translators!, if u want help to this *"
597 echo "* project, email us : *"
598 echo "* *"
599 echo "* monkeyd@googlegroups.com *"
600 echo "* *"
601 echo "* Thanks for use Monkey!!! *"
602 echo "* *"
603 echo "********************************************"
604 echo "System : $SYSINFO"
606 lang="en"
609 # Configure environment
610 if test -z "$CC" ; then
611 CC="gcc"
614 if test -z "$STRIP" ; then
615 STRIP="strip"
618 if test -z "$debug" ; then
619 CFLAGS="-O2 -Wall"
620 else
621 CFLAGS="-g -Wall"
624 if [ $trace ] ; then
625 DEFS="-DTRACE"
628 # Starting main function
629 main prefix lang bindir cgibin sysconfdir datadir logdir plugdir modules SYSNAME VERSION
630 exit 0