pre-threading improves (Felipe)
[MonkeyD.git] / configure
blobdb59b3af29be45d5120b3da92dd5e37b2b4dc59e
1 #!/bin/sh
3 # Monkey HTTP Daemon
4 # ------------------
5 # Copyright (C) 2001-2007, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 VERSION="-git"
22 SYSNAME=`uname -s`
23 SYSINFO=`uname -sr`
25 INFOMODS="extras/inf/"
26 INCDIR="src/include/"
28 messages_en()
30 case "$*" in
31 "1")
32 echo "+ Creating conf/monkey.conf"
34 "2")
35 echo "+ Creating Makefile"
37 "3")
38 echo "+ Creating src/Makefile"
40 "4")
41 echo "+ Creating src/include/info.h"
43 "5")
44 echo "+ Creating banana script"
46 "6")
47 echo -n "Configuration done, just type 'make"
49 "7")
50 echo -n "+ Checking for Pthreads lib.........."
52 esac
55 messages_es()
57 case "$*" in
58 "1")
59 echo "+ Creando conf/monkey.conf"
61 "2")
62 echo "+ Creando Makefile"
64 "3")
65 echo "+ Creando src/Makefile"
67 "4")
68 echo "+ Creando src/include/info.h"
70 "5")
71 echo "+ Creando banana script"
73 "6")
74 echo -n "Configuracion completa, tipee 'make"
76 "7")
77 echo -n "+ Checkeando Pthreads lib.........."
79 esac
82 messages_fr()
84 case "$*" in
85 "1")
86 echo "+ Creating conf/monkey.conf"
88 "2")
89 echo "+ Creating Makefile"
91 "3")
92 echo "+ Creating src/Makefile"
94 "4")
95 echo "+ Creating src/include/info.h"
97 "5")
98 echo "+ Creating banana script"
100 "6")
101 echo -n "Configuration done, just type 'make"
103 "7")
104 echo -n "+ Checking for Pthreads lib.........."
106 esac
109 make_conf()
111 cat $INCDIR/config.path lang/"$*"/mconf lang/"$*"/sites/default > makeconf.sh
112 chmod 755 makeconf.sh
113 ./makeconf.sh
114 rm makeconf.sh
115 rm $INCDIR/config.path
116 cp lang/"$*"/monkey.deny conf/
117 cp lang/"$*"/INSTALL ./
118 cp lang/"$*"/README ./
121 local_dirs()
123 bin="bin"
124 logs="logs"
125 sites="conf/sites"
127 if [ ! -d $bin ]; then
128 mkdir $bin
131 if [ ! -d $logs ]; then
132 mkdir $logs
135 if [ ! -d $sites ]; then
136 mkdir $sites
141 main()
143 local_dirs
144 dir=0
145 actual_path=`pwd`
146 rm -rf src/extras/inf/*
148 # Checking loaded modules
149 if [ "$modules" = "on" ]; then
150 add_obj_mod="modules.o"
151 echo "Modules loaded :"
153 cat > $INCDIR/modules.h <<EOF
154 char **MOD_Read_Config(char *mod_name);
155 char *MOD_get_ptr_value(char **ptr, char *var);
159 ##### MOD_MYSQL #####
160 if [ "$mod_mysql" = "on" ]; then
161 echo "* MySQL Module -> Running mod_mysql configure"
162 cd src/extras/mod_mysql && ./configure
163 cd ../../../
166 echo
169 if test -f src/extras/inf/libmod.info ; then
170 mod_libs=`cat src/extras/inf/libmod.info`
172 if test -f src/extras/inf/obj.info ; then
173 mod_obj=`cat src/extras/inf/obj.info`
175 if test -f src/extras/inf/defs.info ; then
176 mod_defs=`cat src/extras/inf/defs.info`
179 if test -f src/extras/inf/make_script.info ; then
180 make_script=`cat src/extras/inf/make_script.info`
183 # end check
185 echo "Language : $lang"
186 echo
188 if [ "$prefix" != "$actual_path" ]; then
189 dir=1
192 if [ "$bindir" != "$actual_path/bin" ]; then
193 dir=1
196 if [ "$cgibin" != "$actual_path/cgi-bin" ]; then
197 dir=1
200 if [ "$sysconfdir" != "$actual_path/conf" ]; then
201 dir=1
204 if [ "$datadir" != "$actual_path/htdocs" ]; then
205 dir=1
208 if [ "$logdir" != "$actual_path/logs" ]; then
209 dir=1
212 messages_$lang "7"
213 check_lib lang
215 messages_$lang "1"
216 create_conf prefix bindir cgibin sysconfdir datadir logdir
218 make_conf $lang
219 messages_$lang "2"
221 if [ "$dir" = 0 ]; then
222 create_makefile1 bindir
223 else
224 create_makefile1_install prefix bindir cgibin sysconfdir datadir logdir
227 messages_$lang "3"
228 create_makefile2 mod_libs mod_defs mod_obj make_script add_obj_mod
230 messages_$lang "4"
231 create_info sysconfdir SYSNAME VERSION
233 messages_$lang "5"
234 create_banana_script bindir logdir
236 echo
237 messages_$lang "6"
239 if [ "$dir" = 1 ]; then
240 echo -n " && make install' "
241 else
242 echo "' "
244 echo
247 # Checkea biblioteca PTHREADS
248 check_lib()
250 cat > check.c <<EOF
251 #include <pthread.h>
252 int main(){ return 0;}
255 libtest=`gcc check.c -lpthread &>configure.log`
256 libstatus=`cat configure.log`
257 if test -n "$libstatus" ; then
258 echo "no"
259 rm -fr check* configure.log
260 exit 1
262 echo "yes"
263 rm -fr check* configure.log a.out
267 # Creando Makefile
268 create_makefile1()
270 cat > Makefile << EOF
271 # Monkey HTTP Daemon: Makefile
272 # ============================
273 default:
274 @(cd src; make all)
275 @echo
276 @echo " Running Monkey :"
277 @echo " ----------------"
278 @echo
279 @echo " # $bindir/monkey"
280 @echo
281 @echo " For more help use '-h' option."
282 @echo
283 clean:
284 @(cd src; make clean)
285 distclean:
286 @(cd src; make distclean)
290 create_makefile1_install()
292 cat > Makefile <<EOF
293 # Monkey HTTP Daemon: Makefile
294 # ============================
295 PREFIX=${prefix}
296 BINDIR=${bindir}
297 CGIBIN=${cgibin}
298 SYSCONFDIR=${sysconfdir}
299 DATADIR=${datadir}
300 LOGDIR=${logdir}
302 default:
303 @(cd src; make all)
304 clean:
305 @(cd src; make clean)
306 distclean:
307 @(cd src; make distclean)
309 install:
310 make -C src all
311 install -d \$(BINDIR)
312 install -d \$(CGIBIN)
313 install -d \$(SYSCONFDIR)
314 install -d \$(DATADIR)
315 install -d \${DATADIR}/imgs
316 install -d \${DATADIR}/php
317 install -d \${DATADIR}/docs
318 install -d \${LOGDIR}
319 install -s -m 755 bin/monkey \$(BINDIR)
320 install -m 755 bin/banana \$(BINDIR)
321 install -m 755 ./cgi-bin/* \$(CGIBIN)
322 install -m 600 ./conf/*.* \$(SYSCONFDIR)
323 install -m 644 ./htdocs/*.* \$(DATADIR)
324 install -m 644 ./htdocs/imgs/*.* \${DATADIR}/imgs
325 install -m 644 ./htdocs/php/*.* \${DATADIR}/php
326 install -m 644 ./htdocs/docs/*.* \${DATADIR}/docs
327 @echo
328 @echo " Running Monkey :"
329 @echo " ----------------"
330 @echo
331 @echo " # $bindir/monkey"
332 @echo
333 @echo " For more help use '-h' option"
334 @echo
339 # Creando src/Makefile
340 create_makefile2()
343 if [ $SYSNAME = "SunOS" ]; then
344 MORE_LIBS="-lsocket"
347 if test -z $CC ; then
348 CC="gcc"
350 if test -z $STRIP ; then
351 STRIP="strip"
354 ##### Internal options ####
355 if [ "$disable_sendfile" = "on" ]; then
356 internal_options="-DDISABLE_SENDFILE_SYSCALL"
359 cat > src/Makefile<<EOF
360 CC = $CC
361 DEFS = $mod_defs $internal_options
362 CFLAGS = \$(DEFS) -g -O2 -Wall
363 INCDIR = ./include
364 LDFLAGS =
365 DESTDIR = ../bin/monkey
366 LIBS = -lpthread $mod_libs $MORE_LIBS
367 OBJ = monkey.o method.o mimetype.o request.o \\
368 vhost.o config.o logfile.o signals.o \\
369 dir_html.o deny.o cgi.o user.o utils.o \\
370 process.o chars.o mk_net.o mk_thread.o mk_common.o $add_obj_mod
372 all: modules ../bin/monkey
374 modules:
375 $make_script
377 ../bin/monkey: \$(OBJ)
378 \$(CC) \$(CFLAGS) \$(LIBS) \$(LDFLAGS) -o \$@ \$(OBJ) $mod_obj
379 $STRIP ../bin/monkey
381 clean:
382 rm -rf *.o
383 rm -rf ../bin/monkey
385 distclean:
386 rm -rf *.o ../bin/* Makefile \\
387 ../Makefile ../conf/monkey.conf \\
388 ../conf/monkey.deny ../conf/sites/* include/info.h ../logs/*\\
389 extras/inf/*
390 @(cd extras && ./cleanmods.sh && cd ..)
392 .c.o:
393 \$(CC) -c \$(CFLAGS) -I\$(INCDIR) \$<
397 # Creando include/info.h
398 create_info()
400 cat > $INCDIR/info.h <<EOF
401 #define OS "$SYSNAME"
402 #define VERSION "$VERSION" /* Version de Monkey */
403 #define MONKEY_PATH_CONF "$sysconfdir"
407 create_conf()
409 cat > $INCDIR/config.path <<EOF
410 #!/bin/sh
411 prefix=$prefix
412 bindir=$bindir
413 cgibin=$cgibin
414 sysconfdir=$sysconfdir
415 datadir=$datadir
416 logdir=$logdir
420 create_banana_script()
422 cat > bin/banana << EOF
423 #!/bin/sh
425 # Monkey HTTP Daemon - Banana Script
426 # -----------------------------------
427 # This script allow you to control monkey. Written by Eduardo Silva
428 # ----------------------------
429 # Date : 2002/09/01.
430 # ----------------------------
432 # Use: ./banana OPTION
434 # Options available to banana:
436 # start -> start monkey
437 # restart -> restart monkey
438 # stop -> stop monkey if this is running
439 # help -> what do u think ?
441 PIDFILE="$logdir/monkey.pid"
442 BINMONKEY="$bindir/monkey"
444 for arg in \$*; do
445 case "\$arg" in
446 -*=*) optarg=\`echo "\$arg" | sed 's/[-_a-zA-Z0-9]*=//'\` ;;
447 *) optarg= ;;
448 esac
450 if ! test -f \$PIDFILE ; then
451 STATUS="no"
452 else
453 PIDMONKEY=\`cat \$PIDFILE\`
454 if ! kill -0 \$PIDMONKEY 2>/dev/null; then
455 STATUS="no"
456 else
457 STATUS="yes"
461 case "\$arg" in
462 start)
463 if [ "\$STATUS" == "yes" ] ; then
464 echo "Monkey is running... (PID=\$PIDMONKEY)"
465 exit 1
467 if ! test -x \$BINMONKEY ; then
468 echo "Error: I can't run binary file"
469 exit 1
470 else
471 if \$BINMONKEY -D 2>/dev/null ; then
472 echo "Running Monkey -> OK"
473 exit 0
477 stop)
478 if [ "\$STATUS" == "no" ]; then
479 echo "Monkey is not running."
480 exit 1
482 kill \$PIDMONKEY
483 rm -rf \$PIDFILE > /dev/null
484 echo "Monkey stopped (\$PIDMONKEY)"
485 exit 0
487 restart)
488 if [ "\$STATUS" == "yes" ]; then
489 if ! kill \$PIDMONKEY > /dev/null ; then
490 killall -9 monkey
491 else
492 echo -n "Stopping Monkey... "
494 else
495 echo -n "Monkey is not running... "
497 if ! test -x \$BINMONKEY ; then
498 echo "Error: I can't run binary file"
499 exit 1
500 else
501 \$BINMONKEY -D > /dev/null
502 echo "Restarting -> OK"
503 exit 0
507 echo "Use : banana [start|stop|restart|help]"
508 exit 1
510 esac
511 done
512 echo "Use : banana [start|stop|restart|help]"
514 exit 0
516 chmod 755 bin/banana
519 #---------------------------#
520 # End Functions
521 #---------------------------#
524 #---------------------------#
525 # Starting configure
526 #---------------------------#
527 aux=`pwd`
529 prefix="$aux"
530 bindir="$aux/bin"
531 cgibin="$aux/cgi-bin"
532 sysconfdir="$aux/conf"
533 datadir="$aux/htdocs"
534 logdir="$aux/logs"
536 rm -rf src/extras/*.info
537 touch $INCDIR/modules.h
539 for arg in $*; do
540 case "$arg" in
541 -*=*)
542 optarg=`echo "$arg" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
543 *) optarg= ;;
544 esac
546 case "$arg" in
547 --prefix*)
548 prefix=$optarg
549 bindir="$optarg/bin"
550 cgibin="$optarg/cgi-bin"
551 sysconfdir="$optarg/conf"
552 datadir="$optarg/htdocs"
553 logdir="$optarg/logs"
555 --bindir*)
556 bindir=$optarg
558 --cgibin*)
559 cgibin=$optarg
561 --sysconfdir*)
562 sysconfdir=$optarg
564 --datadir*)
565 datadir=$optarg
567 --logdir*)
568 logdir=$optarg
570 --lang*)
571 lang=$optarg
573 --disable-sendfile*)
574 disable_sendfile="on"
576 --load-mod_mysql*)
577 modules="on"
578 mod_mysql="on"
580 --version*)
581 echo "Monkey HTTP Daemon v$VERSION"
582 echo "-------------------------"
583 echo "Copyright 2001-2002"
584 echo "Developed by Eduardo Silva"
585 echo "Monkey Home : http://monkeyd.sf.net"
586 echo "Contact Email : edsiper@users.sf.net"
587 echo
588 exit 1
591 echo "Usage: configure [--prefix=PREFIXDIR] [--lang=LANGUAGE] [ --bindir=BINDIR]"
592 echo " [--cgibin=CGIBINDIR] [--sysconfdir=SYSCONFDIR]"
593 echo " [--datadir=DATADIR] [--logdir=LOGDIR]"
594 echo
595 echo "Options : "
596 echo " --help Display this help and exit"
597 echo " --version Display version information and exit"
598 echo
599 echo " --prefix=PREFIX Install Monkey under PREFIX directory"
600 echo " --bindir=BINDIR Install Monkey binaries under BINDIR directory"
601 echo " --cgibin=CGIBINDIR Install Monkey cgi-bin under CGIBIN directory"
602 echo " --sysconfdir=SYSCONFDIR Install Monkey conf files under SYSCONFDIR dir"
603 echo " --datadir=DATADIR Install Monkey data dir files under DATADIR directory"
604 echo " --logdir=LOGDIR Install Monkey log files under LOGDIR directory"
605 echo " --lang=[en|es] Language to configuration files (default English)"
606 echo
607 echo "Internal options :"
608 echo
609 echo " --disable-sendfile Do not use the sendfile() system call"
610 echo
611 echo "Modules :"
612 echo " All modules are optional features, neither of them are loaded by default,"
613 echo " the available modules are:"
614 echo
615 echo " --load-mod_mysql Load MySQL Support (read MODULES file for details)."
616 echo
617 exit 1
619 esac
620 done
622 echo "********************************************"
623 echo " Monkey HTTP Daemon v$VERSION "
624 echo "* (http://monkeyd.sf.net) *"
625 echo "* ---------------------------------------- *"
626 echo "* We need beta testers, developers and *"
627 echo "* translators!, if u want help to this *"
628 echo "* project, email me : *"
629 echo "* *"
630 echo "* edsiper@users.sourceforge.net *"
631 echo "* *"
632 echo "* Thanks for use Monkey!!! *"
633 echo "* *"
634 echo "********************************************"
635 echo "System : $SYSINFO"
637 if [ -z "$lang" ]; then
638 echo
639 echo "+ Choose configure language: "
640 echo " -> [en] English"
641 echo " -> [es] Spanish"
642 echo " -> [fr] French"
643 echo
644 echo -n " -> Option (default English) : "
645 lang="en"
646 read lang
647 echo
649 if [ -z "$lang" ]; then
650 lang="en"
653 if [ $lang != "es" ] && [ $lang != "en" ] && [ $lang != "fr" ]; then
654 echo " -> Error: Language not available"
655 exit 1
660 # starting main function
661 main prefix lang bindir cgibin sysconfdir datadir logdir modules mod_mysql SYSNAME VERSION
662 exit 0