Monkey 0.10.0-rc4
[MonkeyD.git] / configure
blob3538d9ecfb75cfd370f926130fe708b5b2bc0d14
1 #!/bin/sh
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.0-rc4"
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
62 cp lang/"$*"/INSTALL ./
63 cp lang/"$*"/README ./
66 local_dirs()
68 bin="bin"
69 logs="logs"
70 sites="conf/sites"
72 if [ ! -d $bin ]; then
73 mkdir $bin
76 if [ ! -d $logs ]; then
77 mkdir $logs
80 if [ ! -d $sites ]; then
81 mkdir $sites
86 main()
88 local_dirs
89 dir=0
90 actual_path=`pwd`
92 if [ "$prefix" != "$actual_path" ]; then
93 dir=1
96 if [ "$bindir" != "$actual_path/bin" ]; then
97 dir=1
100 if [ "$cgibin" != "$actual_path/cgi-bin" ]; then
101 dir=1
104 if [ "$sysconfdir" != "$actual_path/conf" ]; then
105 dir=1
108 if [ "$datadir" != "$actual_path/htdocs" ]; then
109 dir=1
112 if [ "$logdir" != "$actual_path/logs" ]; then
113 dir=1
116 echo
117 echo "Checking dependencies"
118 echo "====================="
119 echo
120 messages_$lang "7"
121 check_lib lang
123 echo
124 echo "Creating Makefiles and scripts"
125 echo "=============================="
126 echo
128 messages_$lang "1"
129 create_conf prefix bindir cgibin sysconfdir datadir logdir
131 make_conf $lang
132 messages_$lang "2"
134 if [ "$dir" = 0 ]; then
135 create_makefile1 bindir
136 else
137 create_makefile1_install prefix bindir cgibin sysconfdir datadir logdir
140 messages_$lang "3"
141 create_makefile2 mod_libs mod_obj make_script add_obj_mod cheetah_obj
143 messages_$lang "4"
144 create_info sysconfdir SYSNAME VERSION
146 messages_$lang "5"
147 create_banana_script bindir logdir
148 echo
149 messages_$lang "6"
151 if [ "$dir" = 1 ]; then
152 echo -n " && make install' "
153 else
154 echo "' "
156 echo
158 create_makefile_plugins $plugdir
160 echo "#define CC \"${CC}\"" > src/include/env.h
163 # Check pthreads lib
164 check_lib()
166 cat > check.c <<EOF
167 #include <pthread.h>
168 int main(){ return 0;}
171 libtest=`gcc check.c -lpthread &>configure.log`
172 libstatus=`cat configure.log`
173 if test -n "$libstatus" ; then
174 echo "no"
175 rm -fr check* configure.log
176 exit 1
178 echo "yes"
179 rm -fr check* configure.log a.out
183 # Create Makefile
184 create_makefile1()
186 cat > Makefile << EOF
187 # Monkey HTTP Daemon: Makefile
188 # ============================
189 default:
190 @(cd src; make all)
191 @echo
192 @echo " Running Monkey :"
193 @echo " ----------------"
194 @echo
195 @echo " # $bindir/monkey"
196 @echo
197 @echo " For more help use '-h' option."
198 @echo
200 plugins:
201 @(cd plugins; make all)
203 clean:
204 @(cd src; make clean)
205 distclean:
206 @(cd src; make distclean)
210 create_makefile1_install()
212 # Look for plugins and create list
213 for entry in plugins/*
215 if [ -d $entry ]; then
216 echo -e "\tinstall -s -m 644 $entry/*.so \${PLUGINDIR}" >> plugins.list
218 done;
219 plglist=`cat plugins.list`
220 rm -rf plugins.list
222 # Look for plugins configuration
223 for entry in conf/plugins/*
225 if [ -d $entry ]; then
226 echo -e "\tcp -r $entry \${SYSCONFDIR}/plugins/" >> plugins.conf
228 done;
229 plgconf=`cat plugins.conf`
230 rm -rf plugins.conf
232 cat > Makefile <<EOF
233 # Monkey HTTP Daemon: Makefile
234 # ============================
235 PREFIX=${prefix}
236 BINDIR=${bindir}
237 CGIBIN=${cgibin}
238 SYSCONFDIR=${sysconfdir}
239 DATADIR=${datadir}
240 LOGDIR=${logdir}
241 PLUGINDIR=${plugdir}
243 default:
244 @(cd src; make all)
245 clean:
246 @(cd src; make clean)
247 distclean:
248 @(cd src; make distclean)
250 install:
251 make -C src all
252 install -d \$(BINDIR)
253 install -d \$(CGIBIN)
254 install -d \$(SYSCONFDIR)
255 install -d \${SYSCONFDIR}/sites
256 install -d \${SYSCONFDIR}/plugins
257 install -d \$(DATADIR)
258 install -d \${DATADIR}/imgs
259 install -d \${DATADIR}/php
260 install -d \${DATADIR}/docs
261 install -d \${LOGDIR}
262 install -d \${PLUGINDIR}
263 install -s -m 755 bin/monkey \$(BINDIR)
264 install -m 755 bin/banana \$(BINDIR)
265 install -m 600 ./conf/*.* \$(SYSCONFDIR)
266 $plgconf
267 install -m 600 ./conf/sites/* \${SYSCONFDIR}/sites
268 $plglist
269 install -m 644 ./htdocs/*.* \$(DATADIR)
270 install -m 644 ./htdocs/imgs/*.* \${DATADIR}/imgs
271 @echo
272 @echo " Running Monkey :"
273 @echo " ----------------"
274 @echo
275 @echo " # $bindir/monkey"
276 @echo
277 @echo " For more help use '-h' option"
278 @echo
283 # Create monkey/src/Makefile
284 create_makefile2()
287 if test -z $CC ; then
288 CC="gcc"
291 if test -z $debug ; then
292 CFLAGS="-O2 -Wall"
293 else
294 CFLAGS="-g -Wall"
297 if [ $trace ] ; then
298 DEFS="-DTRACE"
301 ##### Internal options ####
302 # just for remember that one time we support this :_(
303 # ---------------------------------------------------
304 #if [ "$disable_sendfile" = "on" ]; then
305 # internal_options="-DDISABLE_SENDFILE_SYSCALL"
308 cat > src/Makefile<<EOF
309 CC = $CC
310 CFLAGS = $CFLAGS $DEFS
311 INCDIR = ./include
312 LDFLAGS =
313 DESTDIR = ../bin/monkey
314 LIBS = -ldl -lpthread $mod_libs $MORE_LIBS
315 OBJ = monkey.o method.o mimetype.o request.o \\
316 header.o config.o logfile.o signals.o \\
317 user.o utils.o chars.o epoll.o scheduler.o \\
318 str.o memory.o connection.o iov.o http.o \\
319 file.o socket.o clock.o cache.o worker.o \\
320 server.o plugin.o \\
321 $add_obj_mod
323 all: ../bin/monkey
325 ../bin/monkey: \$(OBJ)
326 @echo "Compiling Monkey"
327 @echo "================"
328 \$(CC) \$(CFLAGS) \$(LIBS) \$(LDFLAGS) -o \$@ \$(OBJ) $mod_obj
329 @echo
330 @echo "Compiling Plugins"
331 @echo "================="
332 @(cd ../plugins && make all && cd ..)
334 clean:
335 rm -rf *.o
336 rm -rf ../bin/monkey
338 distclean:
339 rm -rf *.o ../bin/* Makefile \\
340 ../Makefile ../conf/monkey.conf \\
341 ../conf/sites/* include/info.h ../logs/*\\
343 .c.o:
344 \$(CC) -c \$(CFLAGS) -I\$(INCDIR) \$<
348 create_makefile_plugins()
350 cd plugins
351 cat > Makefile <<EOF
352 all:
354 dir=`pwd`
355 plugins_load="../conf/plugins.load"
356 echo -n > $plugins_load
357 echo "# Monkey plugins are loaded on run, by default all " >> $plugins_load
358 echo "# plugins are disabled, if you want to enable" >> $plugins_load
359 echo "# one, just remove the comment character for each line" >> $plugins_load
360 echo "" >> $plugins_load
362 list=`echo */ "" | sed "s/\/ /\n/g"`
363 for i in $list;
365 if test -e $i/DISABLED ; then
366 continue
369 echo " @(cd $i && make && cd ..)" >> Makefile;
371 if [ "$plugdir" != "" ]; then
372 echo "#LoadPlugin $plugdir/monkey-$i.so" >> ../conf/plugins.load
373 else
374 echo "#LoadPlugin $dir/$i/monkey-$i.so" >> ../conf/plugins.load
376 done
378 # Add 'install' option to make file if plugdir was specified
379 if [ "$plugdir" != "" ]; then
380 echo -e "\ninstall:" >> Makefile
381 echo -e "\tinstall -d $plugdir" >> Makefile
383 list=`echo */ "" | sed "s/\/ /\n/g"`
384 for i in $list;
386 echo -e "\tinstall -m 644 $dir/$i/monkey-$i.so $plugdir/" >> Makefile
387 done
389 cd ..
392 # Creando include/info.h
393 create_info()
395 cat > $INCDIR/info.h <<EOF
396 #define OS "$SYSNAME"
397 #define VERSION "$VERSION" /* Version de Monkey */
398 #define MONKEY_PATH_CONF "$sysconfdir"
402 create_conf()
404 cat > $INCDIR/config.path <<EOF
405 #!/bin/sh
406 prefix=$prefix
407 bindir=$bindir
408 cgibin=$cgibin
409 sysconfdir=$sysconfdir
410 datadir=$datadir
411 logdir=$logdir
415 create_banana_script()
417 cat > bin/banana << EOF
418 #!/bin/sh
420 # Monkey HTTP Daemon - Banana Script
421 # -----------------------------------
422 # This script allow you to control monkey. Written by Eduardo Silva
423 # ----------------------------
424 # Date : 2002/09/01.
425 # ----------------------------
427 # Use: ./banana OPTION
429 # Options available to banana:
431 # start -> start monkey
432 # restart -> restart monkey
433 # stop -> stop monkey if this is running
434 # help -> what do u think ?
436 PIDFILE="$logdir/monkey.pid"
437 BINMONKEY="$bindir/monkey"
439 for arg in \$*; do
440 case "\$arg" in
441 -*=*) optarg=\`echo "\$arg" | sed 's/[-_a-zA-Z0-9]*=//'\` ;;
442 *) optarg= ;;
443 esac
445 if ! test -f \$PIDFILE ; then
446 STATUS="no"
447 else
448 PIDMONKEY=\`cat \$PIDFILE\`
449 if ! kill -0 \$PIDMONKEY 2>/dev/null; then
450 STATUS="no"
451 else
452 STATUS="yes"
456 case "\$arg" in
457 start)
458 if [ "\$STATUS" = "yes" ] ; then
459 echo "Monkey is running... (PID=\$PIDMONKEY)"
460 exit 1
462 if ! test -x \$BINMONKEY ; then
463 echo "Error: I can't run binary file"
464 exit 1
465 else
466 if \$BINMONKEY -D 2>/dev/null ; then
467 echo "Running Monkey -> OK"
468 exit 0
472 stop)
473 if [ "\$STATUS" = "no" ]; then
474 echo "Monkey is not running."
475 exit 1
477 kill -9 \$PIDMONKEY
478 rm -rf \$PIDFILE > /dev/null
479 echo "Monkey stopped (\$PIDMONKEY)"
480 exit 0
482 restart)
483 if [ "\$STATUS" = "yes" ]; then
484 if ! kill \$PIDMONKEY > /dev/null ; then
485 killall -9 monkey
486 else
487 echo -n "Stopping Monkey... "
489 else
490 echo -n "Monkey is not running... "
492 if ! test -x \$BINMONKEY ; then
493 echo "Error: I can't run binary file"
494 exit 1
495 else
496 \$BINMONKEY -D > /dev/null
497 echo "Restarting -> OK"
498 exit 0
502 echo "Use : banana [start|stop|restart|help]"
503 exit 1
505 esac
506 done
507 echo "Use : banana [start|stop|restart|help]"
509 exit 0
511 chmod 755 bin/banana
514 #---------------------------#
515 # End Functions
516 #---------------------------#
519 #---------------------------#
520 # Starting configure
521 #---------------------------#
522 aux=`pwd`
524 prefix="$aux"
525 bindir="$aux/bin"
526 cgibin="$aux/cgi-bin"
527 sysconfdir="$aux/conf"
528 datadir="$aux/htdocs"
529 logdir="$aux/logs"
530 plugdir="$aux/plugins"
532 for arg in $*; do
533 case "$arg" in
534 -*=*)
535 optarg=`echo "$arg" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
536 *) optarg= ;;
537 esac
539 case "$arg" in
540 --prefix*)
541 prefix=$optarg
542 bindir="$optarg/bin"
543 cgibin="$optarg/cgi-bin"
544 sysconfdir="$optarg/conf"
545 datadir="$optarg/htdocs"
546 logdir="$optarg/logs"
547 plugdir="$optarg/plugins"
549 --bindir*)
550 bindir=$optarg
552 --cgibin*)
553 cgibin=$optarg
555 --sysconfdir*)
556 sysconfdir=$optarg
558 --datadir*)
559 datadir=$optarg
561 --logdir*)
562 logdir=$optarg
564 --plugdir*)
565 plugdir=$optarg
567 --debug*)
568 debug=1
570 --trace*)
571 trace=1
573 --version*)
574 echo "Monkey HTTP Daemon v$VERSION"
575 echo "-------------------------"
576 echo "Copyright 2001-2010"
577 echo "Developed by Eduardo Silva Pereira"
578 echo "Monkey Home : http://www.monkey-project.com"
579 echo "Contact Email : edsiper@gmail.com"
580 echo
581 exit 1
584 echo "Usage: configure [--prefix=PREFIXDIR] [ --bindir=BINDIR]"
585 echo " [--sysconfdir=SYSCONFDIR] [--datadir=DATADIR]"
586 echo " [--logdir=LOGDIR] [--plugdir=PLUGDIR]"
587 echo
588 echo "Options: "
589 echo " --help Display this help and exit"
590 echo " --version Display version information and exit"
591 echo " --debug Compile Monkey with debugging symbols"
592 echo " --trace Compile Monkey with trace messages (don't use in production)"
593 echo
594 echo " --prefix=PREFIX Install Monkey under PREFIX directory"
595 echo " --bindir=BINDIR Install Monkey binaries under BINDIR directory"
596 echo " --sysconfdir=SYSCONFDIR Install Monkey conf files under SYSCONFDIR dir"
597 echo " --datadir=DATADIR Install Monkey data dir files under DATADIR directory"
598 echo " --logdir=LOGDIR Install Monkey log files under LOGDIR directory"
599 echo " --plugdir=PLUGDIR Target directory for Monkey plugins"
600 echo
601 exit 1
603 esac
604 done
606 echo "********************************************"
607 echo " Monkey HTTP Daemon v$VERSION "
608 echo "* http://www.monkey-project.com *"
609 echo "* ---------------------------------------- *"
610 echo "* We need beta testers, developers and *"
611 echo "* translators!, if u want help to this *"
612 echo "* project, email us : *"
613 echo "* *"
614 echo "* monkeyd@googlegroups.com *"
615 echo "* *"
616 echo "* Thanks for use Monkey!!! *"
617 echo "* *"
618 echo "********************************************"
619 echo "System : $SYSINFO"
621 lang="en"
623 # starting main function
624 main prefix lang bindir cgibin sysconfdir datadir logdir plugdir modules SYSNAME VERSION
625 exit 0