Monkey 0.10.0-rc2
[MonkeyD.git] / configure
blob04c44e28dfa21fbcf5d13be659e4a946a4f6e478
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-rc2"
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()
213 # Look for plugins and create list
214 for entry in plugins/*
216 if [ -d $entry ]; then
217 echo "\tinstall -s -m 644 $entry/*.so \${PLUGINDIR}" >> plugins.list
219 done;
220 plglist=`cat plugins.list`
221 rm -rf plugins.list
223 # Look for plugins configuration
224 for entry in conf/plugins/*
226 if [ -d $entry ]; then
227 echo "\tcp -r $entry \${SYSCONFDIR}/plugins/" >> plugins.conf
229 done;
230 plgconf=`cat plugins.conf`
231 rm -rf plugins.conf
233 cat > Makefile <<EOF
234 # Monkey HTTP Daemon: Makefile
235 # ============================
236 PREFIX=${prefix}
237 BINDIR=${bindir}
238 CGIBIN=${cgibin}
239 SYSCONFDIR=${sysconfdir}
240 DATADIR=${datadir}
241 LOGDIR=${logdir}
242 PLUGINDIR=${plugdir}
244 default:
245 @(cd src; make all)
246 clean:
247 @(cd src; make clean)
248 distclean:
249 @(cd src; make distclean)
251 install:
252 make -C src all
253 install -d \$(BINDIR)
254 install -d \$(CGIBIN)
255 install -d \$(SYSCONFDIR)
256 install -d \${SYSCONFDIR}/sites
257 install -d \${SYSCONFDIR}/plugins
258 install -d \$(DATADIR)
259 install -d \${DATADIR}/imgs
260 install -d \${DATADIR}/php
261 install -d \${DATADIR}/docs
262 install -d \${LOGDIR}
263 install -d \${PLUGINDIR}
264 install -s -m 755 bin/monkey \$(BINDIR)
265 install -m 755 bin/banana \$(BINDIR)
266 install -m 755 ./cgi-bin/* \$(CGIBIN)
267 install -m 600 ./conf/*.* \$(SYSCONFDIR)
268 $plgconf
269 install -m 600 ./conf/sites/* \${SYSCONFDIR}/sites
270 $plglist
271 install -m 644 ./htdocs/*.* \$(DATADIR)
272 install -m 644 ./htdocs/imgs/*.* \${DATADIR}/imgs
273 install -m 644 ./htdocs/php/*.* \${DATADIR}/php
274 install -m 644 ./htdocs/docs/*.* \${DATADIR}/docs
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
287 # Create monkey/src/Makefile
288 create_makefile2()
291 if test -z $CC ; then
292 CC="gcc"
295 if test -z $debug ; then
296 CFLAGS="-O2 -Wall"
297 else
298 CFLAGS="-g -Wall"
301 if [ $trace ] ; then
302 DEFS="-DTRACE"
305 ##### Internal options ####
306 # just for remember that one time we support this :_(
307 # ---------------------------------------------------
308 #if [ "$disable_sendfile" = "on" ]; then
309 # internal_options="-DDISABLE_SENDFILE_SYSCALL"
312 cat > src/Makefile<<EOF
313 CC = $CC
314 CFLAGS = $CFLAGS $DEFS
315 INCDIR = ./include
316 LDFLAGS =
317 DESTDIR = ../bin/monkey
318 LIBS = -ldl -lpthread $mod_libs $MORE_LIBS
319 OBJ = monkey.o method.o mimetype.o request.o \\
320 header.o config.o logfile.o signals.o \\
321 user.o utils.o chars.o epoll.o scheduler.o \\
322 str.o memory.o connection.o iov.o http.o \\
323 file.o socket.o clock.o cache.o worker.o \\
324 server.o plugin.o \\
325 $add_obj_mod
327 all: ../bin/monkey
329 ../bin/monkey: \$(OBJ)
330 @echo "Compiling Monkey"
331 @echo "================"
332 \$(CC) \$(CFLAGS) \$(LIBS) \$(LDFLAGS) -o \$@ \$(OBJ) $mod_obj
333 @echo
334 @echo "Compiling Plugins"
335 @echo "================="
336 @(cd ../plugins && make all && cd ..)
338 clean:
339 rm -rf *.o
340 rm -rf ../bin/monkey
342 distclean:
343 rm -rf *.o ../bin/* Makefile \\
344 ../Makefile ../conf/monkey.conf \\
345 ../conf/sites/* include/info.h ../logs/*\\
347 .c.o:
348 \$(CC) -c \$(CFLAGS) -I\$(INCDIR) \$<
352 create_makefile_plugins()
354 cd plugins
355 cat > Makefile <<EOF
356 all:
358 dir=`pwd`
359 plugins_load="../conf/plugins.load"
360 echo -n > $plugins_load
361 echo "# Monkey plugins are loaded on run, by default all " >> $plugins_load
362 echo "# plugins are disabled, if you want to enable" >> $plugins_load
363 echo "# one, just remove the comment character for each line" >> $plugins_load
364 echo "" >> $plugins_load
366 list=`echo */ "" | sed "s/\/ /\n/g"`
367 for i in $list;
369 if test -e $i/DISABLED ; then
370 continue
373 echo " @(cd $i && make && cd ..)" >> Makefile;
375 if [ "$plugdir" != "" ]; then
376 echo "#LoadPlugin $plugdir/monkey-$i.so" >> ../conf/plugins.load
377 else
378 echo "#LoadPlugin $dir/$i/monkey-$i.so" >> ../conf/plugins.load
380 done
382 # Add 'install' option to make file if plugdir was specified
383 if [ "$plugdir" != "" ]; then
384 echo "\ninstall:" >> Makefile
385 echo "\tinstall -d $plugdir" >> Makefile
387 list=`echo */ "" | sed "s/\/ /\n/g"`
388 for i in $list;
390 echo "\tinstall -m 644 $dir/$i/monkey-$i.so $plugdir/" >> Makefile
391 done
393 cd ..
396 # Creando include/info.h
397 create_info()
399 cat > $INCDIR/info.h <<EOF
400 #define OS "$SYSNAME"
401 #define VERSION "$VERSION" /* Version de Monkey */
402 #define MONKEY_PATH_CONF "$sysconfdir"
406 create_conf()
408 cat > $INCDIR/config.path <<EOF
409 #!/bin/sh
410 prefix=$prefix
411 bindir=$bindir
412 cgibin=$cgibin
413 sysconfdir=$sysconfdir
414 datadir=$datadir
415 logdir=$logdir
419 create_banana_script()
421 cat > bin/banana << EOF
422 #!/bin/sh
424 # Monkey HTTP Daemon - Banana Script
425 # -----------------------------------
426 # This script allow you to control monkey. Written by Eduardo Silva
427 # ----------------------------
428 # Date : 2002/09/01.
429 # ----------------------------
431 # Use: ./banana OPTION
433 # Options available to banana:
435 # start -> start monkey
436 # restart -> restart monkey
437 # stop -> stop monkey if this is running
438 # help -> what do u think ?
440 PIDFILE="$logdir/monkey.pid"
441 BINMONKEY="$bindir/monkey"
443 for arg in \$*; do
444 case "\$arg" in
445 -*=*) optarg=\`echo "\$arg" | sed 's/[-_a-zA-Z0-9]*=//'\` ;;
446 *) optarg= ;;
447 esac
449 if ! test -f \$PIDFILE ; then
450 STATUS="no"
451 else
452 PIDMONKEY=\`cat \$PIDFILE\`
453 if ! kill -0 \$PIDMONKEY 2>/dev/null; then
454 STATUS="no"
455 else
456 STATUS="yes"
460 case "\$arg" in
461 start)
462 if [ "\$STATUS" = "yes" ] ; then
463 echo "Monkey is running... (PID=\$PIDMONKEY)"
464 exit 1
466 if ! test -x \$BINMONKEY ; then
467 echo "Error: I can't run binary file"
468 exit 1
469 else
470 if \$BINMONKEY -D 2>/dev/null ; then
471 echo "Running Monkey -> OK"
472 exit 0
476 stop)
477 if [ "\$STATUS" = "no" ]; then
478 echo "Monkey is not running."
479 exit 1
481 kill -9 \$PIDMONKEY
482 rm -rf \$PIDFILE > /dev/null
483 echo "Monkey stopped (\$PIDMONKEY)"
484 exit 0
486 restart)
487 if [ "\$STATUS" = "yes" ]; then
488 if ! kill \$PIDMONKEY > /dev/null ; then
489 killall -9 monkey
490 else
491 echo -n "Stopping Monkey... "
493 else
494 echo -n "Monkey is not running... "
496 if ! test -x \$BINMONKEY ; then
497 echo "Error: I can't run binary file"
498 exit 1
499 else
500 \$BINMONKEY -D > /dev/null
501 echo "Restarting -> OK"
502 exit 0
506 echo "Use : banana [start|stop|restart|help]"
507 exit 1
509 esac
510 done
511 echo "Use : banana [start|stop|restart|help]"
513 exit 0
515 chmod 755 bin/banana
518 #---------------------------#
519 # End Functions
520 #---------------------------#
523 #---------------------------#
524 # Starting configure
525 #---------------------------#
526 aux=`pwd`
528 prefix="$aux"
529 bindir="$aux/bin"
530 cgibin="$aux/cgi-bin"
531 sysconfdir="$aux/conf"
532 datadir="$aux/htdocs"
533 logdir="$aux/logs"
535 for arg in $*; do
536 case "$arg" in
537 -*=*)
538 optarg=`echo "$arg" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
539 *) optarg= ;;
540 esac
542 case "$arg" in
543 --prefix*)
544 prefix=$optarg
545 bindir="$optarg/bin"
546 cgibin="$optarg/cgi-bin"
547 sysconfdir="$optarg/conf"
548 datadir="$optarg/htdocs"
549 logdir="$optarg/logs"
551 --bindir*)
552 bindir=$optarg
554 --cgibin*)
555 cgibin=$optarg
557 --sysconfdir*)
558 sysconfdir=$optarg
560 --datadir*)
561 datadir=$optarg
563 --logdir*)
564 logdir=$optarg
566 --lang*)
567 lang=$optarg
569 --plugdir*)
570 plugdir=$optarg
572 --debug*)
573 debug=1
575 --trace*)
576 trace=1
578 --version*)
579 echo "Monkey HTTP Daemon v$VERSION"
580 echo "-------------------------"
581 echo "Copyright 2001-2010"
582 echo "Developed by Eduardo Silva Pereira"
583 echo "Monkey Home : http://www.monkey-project.com"
584 echo "Contact Email : edsiper@gmail.com"
585 echo
586 exit 1
589 echo "Usage: configure [--prefix=PREFIXDIR] [--lang=LANGUAGE] [ --bindir=BINDIR]"
590 echo " [--cgibin=CGIBINDIR] [--sysconfdir=SYSCONFDIR]"
591 echo " [--datadir=DATADIR] [--logdir=LOGDIR] [--plugdir=PLUGDIR]"
592 echo
593 echo "Options: "
594 echo " --help Display this help and exit"
595 echo " --version Display version information and exit"
596 echo " --debug Compile Monkey with debugging symbols"
597 echo " --trace Compile Monkey with trace messages (don't use in production)"
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 " --plugdir=PLUGDIR Target directory for Monkey plugins"
606 echo
607 exit 1
609 esac
610 done
612 echo "********************************************"
613 echo " Monkey HTTP Daemon v$VERSION "
614 echo "* http://www.monkey-project.com *"
615 echo "* ---------------------------------------- *"
616 echo "* We need beta testers, developers and *"
617 echo "* translators!, if u want help to this *"
618 echo "* project, email me : *"
619 echo "* *"
620 echo "* edsiper@gmail.com *"
621 echo "* *"
622 echo "* Thanks for use Monkey!!! *"
623 echo "* *"
624 echo "********************************************"
625 echo "System : $SYSINFO"
627 lang="en"
629 # starting main function
630 main prefix lang bindir cgibin sysconfdir datadir logdir plugdir modules SYSNAME VERSION
631 exit 0