QA: Add protocol_02 test
[MonkeyD.git] / configure
blob3b9248f7a672ccdf9848a6ae88aef0c19facc7b8
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.10.3"
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 ##### Internal options ####
279 # just for remember that one time we support this :_(
280 # ---------------------------------------------------
281 #if [ "$disable_sendfile" = "on" ]; then
282 # internal_options="-DDISABLE_SENDFILE_SYSCALL"
285 cat > src/Makefile<<EOF
286 CC = $CC
287 CFLAGS = $CFLAGS
288 DEFS = $DEFS
289 INCDIR = ./include
290 LDFLAGS =
291 DESTDIR = ../bin/monkey
292 LIBS = -ldl -lpthread $mod_libs $MORE_LIBS
293 OBJ = monkey.o method.o mimetype.o request.o \\
294 header.o config.o logfile.o signals.o \\
295 user.o utils.o chars.o epoll.o scheduler.o \\
296 str.o memory.o connection.o iov.o http.o \\
297 file.o socket.o clock.o cache.o worker.o \\
298 server.o plugin.o \\
299 $add_obj_mod
301 all: ../bin/monkey
303 ../bin/monkey: \$(OBJ)
304 @echo
305 @echo "Compiling Monkey"
306 @echo "================"
307 \$(CC) \$(CFLAGS) \$(DEFS) \$(LIBS) \$(LDFLAGS) -o \$@ \$(OBJ) $mod_obj
308 @echo
309 @echo "Compiling Plugins"
310 @echo "================="
311 @(cd ../plugins && make all && cd ..)
313 clean:
314 rm -rf *.o
315 rm -rf ../bin/monkey
317 distclean:
318 rm -rf *.o ../bin/* Makefile \\
319 ../Makefile ../conf/monkey.conf \\
320 ../conf/sites/* include/info.h ../logs/*\\
322 .c.o:
323 \$(CC) -c \$(CFLAGS) \$(DEFS) -I\$(INCDIR) \$<
327 create_makefile_plugins()
329 cd plugins
330 cat > Makefile <<EOF
331 all:
333 dir=`pwd`
334 plugins_load="../conf/plugins.load"
335 echo -n > $plugins_load
336 echo "# Monkey plugins are loaded on run, by default all " >> $plugins_load
337 echo "# plugins are disabled, if you want to enable" >> $plugins_load
338 echo "# one, just remove the comment character for each line" >> $plugins_load
339 echo "" >> $plugins_load
341 list=`echo */ "" | sed "s/\/ /\n/g"`
342 for i in $list;
344 if test -e $i/DISABLED ; then
345 continue
348 echo " @(cd $i && make && cd ..)" >> Makefile;
350 if [ "$plugdir" != "" ]; then
351 echo "#LoadPlugin $plugdir/monkey-$i.so" >> ../conf/plugins.load
352 else
353 echo "#LoadPlugin $dir/$i/monkey-$i.so" >> ../conf/plugins.load
355 done
357 # Add 'install' option to make file if plugdir was specified
358 if [ "$plugdir" != "" ]; then
359 echo -e "\ninstall:" >> Makefile
360 echo -e "\tinstall -d $plugdir" >> Makefile
362 list=`echo */ "" | sed "s/\/ /\n/g"`
363 for i in $list;
365 echo -e "\tinstall -m 644 $dir/$i/monkey-$i.so $plugdir/" >> Makefile
366 done
368 cd ..
371 # Creando include/info.h
372 create_info()
374 cat > $INCDIR/info.h <<EOF
375 #define OS "$SYSNAME"
376 #define VERSION "$VERSION" /* Version de Monkey */
377 #define MONKEY_PATH_CONF "$sysconfdir"
381 create_conf()
383 cat > $INCDIR/config.path <<EOF
384 #!/bin/sh
385 prefix=$prefix
386 bindir=$bindir
387 cgibin=$cgibin
388 sysconfdir=$sysconfdir
389 datadir=$datadir
390 logdir=$logdir
394 create_banana_script()
396 cat > bin/banana << EOF
397 #!/bin/sh
399 # Monkey HTTP Daemon - Banana Script
400 # -----------------------------------
401 # This script allow you to control monkey. Written by Eduardo Silva
402 # ----------------------------
403 # Date : 2002/09/01.
404 # ----------------------------
406 # Use: ./banana OPTION
408 # Options available to banana:
410 # start -> start monkey
411 # restart -> restart monkey
412 # stop -> stop monkey if this is running
413 # help -> what do u think ?
415 PIDFILE="$logdir/monkey.pid"
416 BINMONKEY="$bindir/monkey"
418 for arg in \$*; do
419 case "\$arg" in
420 -*=*) optarg=\`echo "\$arg" | sed 's/[-_a-zA-Z0-9]*=//'\` ;;
421 *) optarg= ;;
422 esac
424 if ! test -f \$PIDFILE ; then
425 STATUS="no"
426 else
427 PIDMONKEY=\`cat \$PIDFILE\`
428 if ! kill -0 \$PIDMONKEY 2>/dev/null; then
429 STATUS="no"
430 else
431 STATUS="yes"
435 case "\$arg" in
436 start)
437 if [ "\$STATUS" = "yes" ] ; then
438 echo "Monkey is running... (PID=\$PIDMONKEY)"
439 exit 1
441 if ! test -x \$BINMONKEY ; then
442 echo "Error: I can't run binary file"
443 exit 1
444 else
445 if \$BINMONKEY -D 2>/dev/null ; then
446 echo "Running Monkey -> OK"
447 exit 0
451 stop)
452 if [ "\$STATUS" = "no" ]; then
453 echo "Monkey is not running."
454 exit 1
456 kill -9 \$PIDMONKEY
457 rm -rf \$PIDFILE > /dev/null
458 echo "Monkey stopped (\$PIDMONKEY)"
459 exit 0
461 restart)
462 if [ "\$STATUS" = "yes" ]; then
463 if ! kill \$PIDMONKEY > /dev/null ; then
464 killall -9 monkey
465 else
466 echo -n "Stopping Monkey... "
468 else
469 echo -n "Monkey is not running... "
471 if ! test -x \$BINMONKEY ; then
472 echo "Error: I can't run binary file"
473 exit 1
474 else
475 \$BINMONKEY -D > /dev/null
476 echo "Restarting -> OK"
477 exit 0
481 echo "Use : banana [start|stop|restart|help]"
482 exit 1
484 esac
485 done
486 echo "Use : banana [start|stop|restart|help]"
488 exit 0
490 chmod 755 bin/banana
493 #---------------------------#
494 # End Functions
495 #---------------------------#
498 #---------------------------#
499 # Starting configure
500 #---------------------------#
501 aux=`pwd`
503 prefix="$aux"
504 bindir="$aux/bin"
505 cgibin="$aux/cgi-bin"
506 sysconfdir="$aux/conf"
507 datadir="$aux/htdocs"
508 logdir="$aux/logs"
509 plugdir=""
511 for arg in $*; do
512 case "$arg" in
513 -*=*)
514 optarg=`echo "$arg" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
515 *) optarg= ;;
516 esac
518 case "$arg" in
519 --prefix*)
520 prefix=$optarg
521 bindir="$optarg/bin"
522 cgibin="$optarg/cgi-bin"
523 sysconfdir="$optarg/conf"
524 datadir="$optarg/htdocs"
525 logdir="$optarg/logs"
526 plugdir="$optarg/plugins"
528 --bindir*)
529 bindir=$optarg
531 --cgibin*)
532 cgibin=$optarg
534 --sysconfdir*)
535 sysconfdir=$optarg
537 --datadir*)
538 datadir=$optarg
540 --logdir*)
541 logdir=$optarg
543 --plugdir*)
544 plugdir=$optarg
546 --debug*)
547 debug=1
549 --trace*)
550 trace=1
552 --version*)
553 echo "Monkey HTTP Daemon v$VERSION"
554 echo "-------------------------"
555 echo "Copyright 2001-2010"
556 echo "Developed by Eduardo Silva Pereira"
557 echo "Monkey Home : http://www.monkey-project.com"
558 echo "Contact Email : edsiper@gmail.com"
559 echo
560 exit 1
563 echo "Usage: configure [--prefix=PREFIXDIR] [ --bindir=BINDIR]"
564 echo " [--sysconfdir=SYSCONFDIR] [--datadir=DATADIR]"
565 echo " [--logdir=LOGDIR] [--plugdir=PLUGDIR]"
566 echo
567 echo "Options: "
568 echo " --help Display this help and exit"
569 echo " --version Display version information and exit"
570 echo " --debug Compile Monkey with debugging symbols"
571 echo " --trace Compile Monkey with trace messages (don't use in production)"
572 echo
573 echo " --prefix=PREFIX Install Monkey under PREFIX directory"
574 echo " --bindir=BINDIR Install Monkey binaries under BINDIR directory"
575 echo " --sysconfdir=SYSCONFDIR Install Monkey conf files under SYSCONFDIR dir"
576 echo " --datadir=DATADIR Install Monkey data dir files under DATADIR directory"
577 echo " --logdir=LOGDIR Install Monkey log files under LOGDIR directory"
578 echo " --plugdir=PLUGDIR Target directory for Monkey plugins"
579 echo
580 exit 1
582 esac
583 done
585 echo "********************************************"
586 echo " Monkey HTTP Daemon v$VERSION "
587 echo "* http://www.monkey-project.com *"
588 echo "* ---------------------------------------- *"
589 echo "* We need beta testers, developers and *"
590 echo "* translators!, if u want help to this *"
591 echo "* project, email us : *"
592 echo "* *"
593 echo "* monkeyd@googlegroups.com *"
594 echo "* *"
595 echo "* Thanks for use Monkey!!! *"
596 echo "* *"
597 echo "********************************************"
598 echo "System : $SYSINFO"
600 lang="en"
603 # Configure environment
604 if test -z "$CC" ; then
605 CC="gcc"
608 if test -z "$STRIP" ; then
609 STRIP="strip"
612 if test -z "$debug" ; then
613 CFLAGS="-O2 -Wall"
614 else
615 CFLAGS="-g -Wall"
618 if [ $trace ] ; then
619 DEFS="-DTRACE"
622 # Starting main function
623 main prefix lang bindir cgibin sysconfdir datadir logdir plugdir modules SYSNAME VERSION
624 exit 0