[PATCH] Added list.h with the needed definitions to manage double linked list. Added...
[MonkeyD.git] / configure
blob453c4dae011313c106111f1ff9be88c49dbf841f
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.1-git"
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 install -m 755 bin/banana \$(BINDIR)
255 install -m 644 ./conf/*.* \$(SYSCONFDIR)
256 $plgconf
257 install -m 644 ./conf/sites/* \${SYSCONFDIR}/sites
258 $plglist
259 install -m 644 ./htdocs/*.* \$(DATADIR)
260 install -m 644 ./htdocs/imgs/*.* \${DATADIR}/imgs
261 $STRIP \$(BINDIR)/monkey
262 $STRIP \${PLUGINDIR}/*
263 @echo
264 @echo " Running Monkey :"
265 @echo " ----------------"
266 @echo
267 @echo " # $bindir/monkey"
268 @echo
269 @echo " For more help use '-h' option"
270 @echo
275 # Create monkey/src/Makefile
276 create_makefile2()
279 cat > src/Makefile<<EOF
280 CC = $CC
281 CFLAGS = $CFLAGS
282 DEFS = $DEFS
283 INCDIR = ./include
284 LDFLAGS =
285 DESTDIR = ../bin/monkey
286 LIBS = -ldl -lpthread $mod_libs $MORE_LIBS
287 OBJ = monkey.o method.o mimetype.o request.o \\
288 header.o config.o signals.o \\
289 user.o utils.o chars.o epoll.o scheduler.o \\
290 str.o memory.o connection.o iov.o http.o \\
291 file.o socket.o clock.o cache.o worker.o \\
292 server.o plugin.o \\
293 $add_obj_mod
295 all: ../bin/monkey
297 ../bin/monkey: \$(OBJ)
298 @echo
299 @echo "Compiling Monkey"
300 @echo "================"
301 \$(CC) \$(CFLAGS) \$(DEFS) \$(LIBS) \$(LDFLAGS) -o \$@ \$(OBJ) $mod_obj
302 @echo
303 @echo "Compiling Plugins"
304 @echo "================="
305 @(cd ../plugins && \$(MAKE) all && cd ..)
307 clean:
308 rm -rf *.o
309 rm -rf ../bin/monkey
311 distclean:
312 rm -rf *.o ../bin/* Makefile \\
313 ../Makefile ../conf/monkey.conf \\
314 ../conf/sites/* include/info.h ../logs/*\\
316 .c.o:
317 \$(CC) -c \$(CFLAGS) \$(DEFS) -I\$(INCDIR) \$<
321 create_makefile_plugins()
323 cd plugins
324 cat > Makefile <<EOF
325 all:
327 dir=`pwd`
328 plugins_load="../conf/plugins.load"
329 echo -n > $plugins_load
330 echo "# Monkey Plugins Loader" >> $plugins_load
331 echo "# =====================" >> $plugins_load
332 echo "# Monkey plugins are extended functionalities for Monkey," >> $plugins_load
333 echo "# the main directive to load a plugin is LoadPlugin plus" >> $plugins_load
334 echo "# the absolute path for the desired plugin." >> $plugins_load
335 echo "#" >> $plugins_load
336 echo "# Please check the following list of available plugins:" >> $plugins_load
337 echo "" >> $plugins_load
338 echo "[PLUGINS]" >> $plugins_load
339 echo "" >> $plugins_load
341 for plugin_dir in `echo */ "" | sed "s/\/ /\n/g"`;
343 comment=" "
344 if test -e $plugin_dir/DISABLED ; then
345 continue
348 if test -e $plugin_dir/MANDATORY ; then
349 comment=" "
352 if test -e $plugin_dir/OPTIONAL ; then
353 comment=" # "
356 echo " @(cd $plugin_dir && \$(MAKE) && cd ..)" >> Makefile;
357 sed -e "s|\$CC|$CC|" -e "s/\$CFLAGS/$CFLAGS/" -e "s/\$DEFS/$DEFS/" $plugin_dir/Makefile.in > $plugin_dir/Makefile
359 if test -e $plugin_dir/ABOUT ; then
360 cat $plugin_dir/ABOUT | sed -e 's/^/ # /' >> ../conf/plugins.load
361 echo " #" >> ../conf/plugins.load
362 else
363 echo " #" >> ../conf/plugins.load
366 if [ "$plugdir" != "" ]; then
367 echo "${comment}Load $plugdir/monkey-$plugin_dir.so" >> ../conf/plugins.load
368 else
369 echo "${comment}Load $dir/$plugin_dir/monkey-$plugin_dir.so" >> ../conf/plugins.load
372 echo "" >> ../conf/plugins.load
373 done
375 # Add 'install' option to Makefile if plugdir was specified
376 if [ "$plugdir" != "" ]; then
377 echo -e "\ninstall:" >> Makefile
378 echo -e "\tinstall -d $plugdir" >> Makefile
380 list=`echo */ "" | sed "s/\/ /\n/g"`
381 for i in $list;
383 echo -e "\tinstall -m 644 $dir/$i/monkey-$i.so $plugdir/" >> Makefile
384 done
386 cd ..
389 # Creando include/info.h
390 create_info()
392 cat > $INCDIR/info.h <<EOF
393 #define OS "$SYSNAME"
394 #define VERSION "$VERSION" /* Version de Monkey */
395 #define MONKEY_PATH_CONF "$sysconfdir"
399 create_conf()
401 cat > $INCDIR/config.path <<EOF
402 #!/bin/sh
403 prefix=$prefix
404 bindir=$bindir
405 cgibin=$cgibin
406 sysconfdir=$sysconfdir
407 datadir=$datadir
408 logdir=$logdir
412 create_banana_script()
414 cat > bin/banana << EOF
415 #!/bin/sh
417 # Monkey HTTP Daemon - Banana Script
418 # -----------------------------------
419 # This script allow you to control monkey. Written by Eduardo Silva
420 # ----------------------------
421 # Date : 2002/09/01.
422 # ----------------------------
424 # Use: ./banana OPTION
426 # Options available to banana:
428 # start -> start monkey
429 # restart -> restart monkey
430 # stop -> stop monkey if this is running
431 # help -> what do u think ?
433 PIDFILE="$logdir/monkey.pid"
434 BINMONKEY="$bindir/monkey"
436 for arg in \$*; do
437 case "\$arg" in
438 -*=*) optarg=\`echo "\$arg" | sed 's/[-_a-zA-Z0-9]*=//'\` ;;
439 *) optarg= ;;
440 esac
442 if ! test -f \$PIDFILE ; then
443 STATUS="no"
444 else
445 PIDMONKEY=\`cat \$PIDFILE\`
446 if ! kill -0 \$PIDMONKEY 2>/dev/null; then
447 STATUS="no"
448 else
449 STATUS="yes"
453 case "\$arg" in
454 start)
455 if [ "\$STATUS" = "yes" ] ; then
456 echo "Monkey is running... (PID=\$PIDMONKEY)"
457 exit 1
459 if ! test -x \$BINMONKEY ; then
460 echo "Error: I can't run binary file"
461 exit 1
462 else
463 if \$BINMONKEY -D 2>/dev/null ; then
464 echo "Running Monkey -> OK"
465 exit 0
469 stop)
470 if [ "\$STATUS" = "no" ]; then
471 echo "Monkey is not running."
472 exit 1
474 kill -9 \$PIDMONKEY
475 rm -rf \$PIDFILE > /dev/null
476 echo "Monkey stopped (\$PIDMONKEY)"
477 exit 0
479 restart)
480 if [ "\$STATUS" = "yes" ]; then
481 if ! kill \$PIDMONKEY > /dev/null ; then
482 killall -9 monkey
483 else
484 echo -n "Stopping Monkey... "
486 else
487 echo -n "Monkey is not running... "
489 if ! test -x \$BINMONKEY ; then
490 echo "Error: I can't run binary file"
491 exit 1
492 else
493 \$BINMONKEY -D > /dev/null
494 echo "Restarting -> OK"
495 exit 0
499 echo "Use : banana [start|stop|restart|help]"
500 exit 1
502 esac
503 done
504 echo "Use : banana [start|stop|restart|help]"
506 exit 0
508 chmod 755 bin/banana
511 #---------------------------#
512 # End Functions
513 #---------------------------#
516 #---------------------------#
517 # Starting configure
518 #---------------------------#
519 aux=`pwd`
521 prefix="$aux"
522 bindir="$aux/bin"
523 cgibin="$aux/cgi-bin"
524 sysconfdir="$aux/conf"
525 datadir="$aux/htdocs"
526 logdir="$aux/logs"
527 plugdir=""
529 for arg in $*; do
530 case "$arg" in
531 -*=*)
532 optarg=`echo "$arg" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
533 *) optarg= ;;
534 esac
536 case "$arg" in
537 --prefix*)
538 prefix=$optarg
539 bindir="$optarg/bin"
540 cgibin="$optarg/cgi-bin"
541 sysconfdir="$optarg/conf"
542 datadir="$optarg/htdocs"
543 logdir="$optarg/logs"
544 plugdir="$optarg/plugins"
546 --bindir*)
547 bindir=$optarg
549 --cgibin*)
550 cgibin=$optarg
552 --sysconfdir*)
553 sysconfdir=$optarg
555 --datadir*)
556 datadir=$optarg
558 --logdir*)
559 logdir=$optarg
561 --plugdir*)
562 plugdir=$optarg
564 --debug*)
565 debug=1
567 --trace*)
568 trace=1
570 --version*)
571 echo "Monkey HTTP Daemon v$VERSION"
572 echo "-------------------------"
573 echo "Copyright 2001-2010"
574 echo "Developed by Eduardo Silva Pereira"
575 echo "Monkey Home : http://www.monkey-project.com"
576 echo "Contact Email : edsiper@gmail.com"
577 echo
578 exit 1
581 echo "Usage: configure [--prefix=PREFIXDIR] [ --bindir=BINDIR]"
582 echo " [--sysconfdir=SYSCONFDIR] [--datadir=DATADIR]"
583 echo " [--logdir=LOGDIR] [--plugdir=PLUGDIR]"
584 echo
585 echo "Options: "
586 echo " --help Display this help and exit"
587 echo " --version Display version information and exit"
588 echo " --debug Compile Monkey with debugging symbols"
589 echo " --trace Compile Monkey with trace messages (don't use in production)"
590 echo
591 echo " --prefix=PREFIX Install Monkey under PREFIX directory"
592 echo " --bindir=BINDIR Install Monkey binaries under BINDIR directory"
593 echo " --sysconfdir=SYSCONFDIR Install Monkey conf files under SYSCONFDIR dir"
594 echo " --datadir=DATADIR Install Monkey data dir files under DATADIR directory"
595 echo " --logdir=LOGDIR Install Monkey log files under LOGDIR directory"
596 echo " --plugdir=PLUGDIR Target directory for Monkey plugins"
597 echo
598 exit 1
600 esac
601 done
603 echo "********************************************"
604 echo " Monkey HTTP Daemon v$VERSION "
605 echo "* http://www.monkey-project.com *"
606 echo "* ---------------------------------------- *"
607 echo "* We need beta testers, developers and *"
608 echo "* translators!, if you want to contribute *"
609 echo "* to this wonderful project contact us ! *"
610 echo "* *"
611 echo "* irc.freenode.net #monkeyd *"
612 echo "* *"
613 echo "* Thanks for use Monkey!!! *"
614 echo "* *"
615 echo "********************************************"
616 echo "System : $SYSINFO"
618 lang="en"
621 # Configure environment
622 if test -z "$CC" ; then
623 gcc_path=`which gcc`
624 if test -x "$gcc_path" ; then
625 CC="gcc"
626 else
627 echo "I'm a Monkey not a compiler! how do you suppose to compile me ? Install a compiler"
628 exit 1
632 if test -z "$STRIP" ; then
633 STRIP="strip"
636 if test -z "$debug" ; then
637 CFLAGS="$CFLAGS -O2 -Wall"
638 else
639 CFLAGS="$CFLAGS -g -Wall"
642 if [ $trace ] ; then
643 DEFS="-DTRACE"
646 # Starting main function
647 main prefix lang bindir cgibin sysconfdir datadir logdir plugdir modules SYSNAME VERSION
648 exit 0