Add compiler name and version to welcome message
[MonkeyD.git] / configure
blobde7b3b74905497460afc60bd7adda38b01d4f983
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-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 # Create configuration files under 'conf/'
56 make_conf()
58 cat $INCDIR/config.path lang/"$*"/mconf lang/"$*"/sites/default > makeconf.sh
59 chmod 755 makeconf.sh
60 ./makeconf.sh
61 rm makeconf.sh
62 rm $INCDIR/config.path
63 cp lang/"$*"/INSTALL ./
64 cp lang/"$*"/README ./
67 local_dirs()
69 bin="bin"
70 logs="logs"
71 sites="conf/sites"
73 if [ ! -d $bin ]; then
74 mkdir $bin
77 if [ ! -d $logs ]; then
78 mkdir $logs
81 if [ ! -d $sites ]; then
82 mkdir $sites
87 main()
89 local_dirs
90 dir=0
91 actual_path=`pwd`
93 if [ "$prefix" != "$actual_path" ]; then
94 dir=1
97 if [ "$bindir" != "$actual_path/bin" ]; then
98 dir=1
101 if [ "$cgibin" != "$actual_path/cgi-bin" ]; then
102 dir=1
105 if [ "$sysconfdir" != "$actual_path/conf" ]; then
106 dir=1
109 if [ "$datadir" != "$actual_path/htdocs" ]; then
110 dir=1
113 if [ "$logdir" != "$actual_path/logs" ]; then
114 dir=1
117 echo
118 echo "Checking dependencies"
119 echo "====================="
120 echo
121 messages_$lang "7"
122 check_lib lang
124 echo
125 echo "Creating Makefiles and scripts"
126 echo "=============================="
127 echo
129 messages_$lang "1"
130 create_conf prefix bindir cgibin sysconfdir datadir logdir
132 make_conf $lang
133 messages_$lang "2"
135 if [ "$dir" = 0 ]; then
136 create_makefile1 bindir
137 else
138 create_makefile1_install prefix bindir cgibin sysconfdir datadir logdir
141 messages_$lang "3"
142 create_makefile2 mod_libs mod_defs mod_obj make_script add_obj_mod cheetah_obj
144 messages_$lang "4"
145 create_info sysconfdir SYSNAME VERSION
147 messages_$lang "5"
148 create_banana_script bindir logdir
149 echo
150 messages_$lang "6"
152 if [ "$dir" = 1 ]; then
153 echo -n " && make install' "
154 else
155 echo "' "
157 echo
159 create_makefile_plugins $plugdir
161 echo "#define CC \"${CC}\"" > src/include/env.h
164 # Check pthreads lib
165 check_lib()
167 cat > check.c <<EOF
168 #include <pthread.h>
169 int main(){ return 0;}
172 libtest=`gcc check.c -lpthread &>configure.log`
173 libstatus=`cat configure.log`
174 if test -n "$libstatus" ; then
175 echo "no"
176 rm -fr check* configure.log
177 exit 1
179 echo "yes"
180 rm -fr check* configure.log a.out
184 # Create Makefile
185 create_makefile1()
187 cat > Makefile << EOF
188 # Monkey HTTP Daemon: Makefile
189 # ============================
190 default:
191 @(cd src; make all)
192 @echo
193 @echo " Running Monkey :"
194 @echo " ----------------"
195 @echo
196 @echo " # $bindir/monkey"
197 @echo
198 @echo " For more help use '-h' option."
199 @echo
201 plugins:
202 @(cd plugins; make all)
204 clean:
205 @(cd src; make clean)
206 distclean:
207 @(cd src; make distclean)
211 create_makefile1_install()
214 # Look for plugins and create list
215 for entry in plugins/*
217 if [ -d $entry ]; then
218 echo "\tinstall -s -m 644 $entry/*.so \${PLUGINDIR}" >> plugins.list
220 done;
221 plglist=`cat plugins.list`
222 rm -rf plugins.list
224 # Look for plugins configuration
225 for entry in conf/plugins/*
227 if [ -d $entry ]; then
228 echo "\tcp -r $entry \${SYSCONFDIR}/plugins/" >> plugins.conf
230 done;
231 plgconf=`cat plugins.conf`
232 rm -rf plugins.conf
234 cat > Makefile <<EOF
235 # Monkey HTTP Daemon: Makefile
236 # ============================
237 PREFIX=${prefix}
238 BINDIR=${bindir}
239 CGIBIN=${cgibin}
240 SYSCONFDIR=${sysconfdir}
241 DATADIR=${datadir}
242 LOGDIR=${logdir}
243 PLUGINDIR=${plugdir}
245 default:
246 @(cd src; make all)
247 clean:
248 @(cd src; make clean)
249 distclean:
250 @(cd src; make distclean)
252 install:
253 make -C src all
254 install -d \$(BINDIR)
255 install -d \$(CGIBIN)
256 install -d \$(SYSCONFDIR)
257 install -d \${SYSCONFDIR}/sites
258 install -d \${SYSCONFDIR}/plugins
259 install -d \$(DATADIR)
260 install -d \${DATADIR}/imgs
261 install -d \${DATADIR}/php
262 install -d \${DATADIR}/docs
263 install -d \${LOGDIR}
264 install -d \${PLUGINDIR}
265 install -s -m 755 bin/monkey \$(BINDIR)
266 install -m 755 bin/banana \$(BINDIR)
267 install -m 755 ./cgi-bin/* \$(CGIBIN)
268 install -m 600 ./conf/*.* \$(SYSCONFDIR)
269 $plgconf
270 install -m 600 ./conf/sites/* \${SYSCONFDIR}/sites
271 $plglist
272 install -m 644 ./htdocs/*.* \$(DATADIR)
273 install -m 644 ./htdocs/imgs/*.* \${DATADIR}/imgs
274 install -m 644 ./htdocs/php/*.* \${DATADIR}/php
275 install -m 644 ./htdocs/docs/*.* \${DATADIR}/docs
276 @echo
277 @echo " Running Monkey :"
278 @echo " ----------------"
279 @echo
280 @echo " # $bindir/monkey"
281 @echo
282 @echo " For more help use '-h' option"
283 @echo
288 # Create monkey/src/Makefile
289 create_makefile2()
292 if test -z $CC ; then
293 CC="gcc"
295 if test -z $STRIP ; then
296 STRIP="strip "
299 ##### Internal options ####
300 # just for remember that one time we support this :_(
301 # ---------------------------------------------------
302 #if [ "$disable_sendfile" = "on" ]; then
303 # internal_options="-DDISABLE_SENDFILE_SYSCALL"
306 cat > src/Makefile<<EOF
307 CC = $CC
308 DEFS = $mod_defs $internal_options
309 CFLAGS = $CFLAGS \$(DEFS) -g -O2 -Wall
310 INCDIR = ./include
311 LDFLAGS =
312 DESTDIR = ../bin/monkey
313 LIBS = -ldl -lpthread $mod_libs $MORE_LIBS
314 OBJ = monkey.o method.o mimetype.o request.o \\
315 header.o config.o logfile.o signals.o \\
316 user.o utils.o chars.o epoll.o scheduler.o \\
317 str.o memory.o connection.o iov.o http.o \\
318 file.o socket.o clock.o cache.o worker.o \\
319 server.o plugin.o \\
320 $add_obj_mod
322 all: ../bin/monkey
324 ../bin/monkey: \$(OBJ)
325 @echo "Compiling Monkey"
326 @echo "================"
327 \$(CC) \$(CFLAGS) \$(LIBS) \$(LDFLAGS) -o \$@ \$(OBJ) $mod_obj
328 $STRIP ../bin/monkey
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/*\\
342 @(cd extras && ./cleanmods.sh && cd ..)
344 .c.o:
345 \$(CC) -c \$(CFLAGS) -I\$(INCDIR) \$<
349 create_makefile_plugins()
351 cd plugins
352 cat > Makefile <<EOF
353 all:
355 dir=`pwd`
356 plugins_load="../conf/plugins.load"
357 echo -n > $plugins_load
358 echo "# Monkey plugins are loaded on run, by default all " >> $plugins_load
359 echo "# plugins are disabled, if you want to enable" >> $plugins_load
360 echo "# one, just remove the comment character for each line" >> $plugins_load
361 echo "" >> $plugins_load
363 list=`echo */ "" | sed "s/\/ /\n/g"`
364 for i in $list;
366 echo " @(cd $i && make && cd ..)" >> Makefile;
368 if [ "$plugdir" != "" ]; then
369 echo "#LoadPlugin $plugdir/monkey-$i.so" >> ../conf/plugins.load
370 else
371 echo "#LoadPlugin $dir/$i/monkey-$i.so" >> ../conf/plugins.load
373 done
375 # Add 'install' option to make file if plugdir was specified
376 if [ "$plugdir" != "" ]; then
377 echo "\ninstall:" >> Makefile
378 echo "\tinstall -d $plugdir" >> Makefile
380 list=`echo */ "" | sed "s/\/ /\n/g"`
381 for i in $list;
383 echo "\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"
528 for arg in $*; do
529 case "$arg" in
530 -*=*)
531 optarg=`echo "$arg" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
532 *) optarg= ;;
533 esac
535 case "$arg" in
536 --prefix*)
537 prefix=$optarg
538 bindir="$optarg/bin"
539 cgibin="$optarg/cgi-bin"
540 sysconfdir="$optarg/conf"
541 datadir="$optarg/htdocs"
542 logdir="$optarg/logs"
544 --bindir*)
545 bindir=$optarg
547 --cgibin*)
548 cgibin=$optarg
550 --sysconfdir*)
551 sysconfdir=$optarg
553 --datadir*)
554 datadir=$optarg
556 --logdir*)
557 logdir=$optarg
559 --lang*)
560 lang=$optarg
562 --plugdir*)
563 plugdir=$optarg
565 --version*)
566 echo "Monkey HTTP Daemon v$VERSION"
567 echo "-------------------------"
568 echo "Copyright 2001-2010"
569 echo "Developed by Eduardo Silva Pereira"
570 echo "Monkey Home : http://www.monkey-project.com"
571 echo "Contact Email : edsiper@gmail.com"
572 echo
573 exit 1
576 echo "Usage: configure [--prefix=PREFIXDIR] [--lang=LANGUAGE] [ --bindir=BINDIR]"
577 echo " [--cgibin=CGIBINDIR] [--sysconfdir=SYSCONFDIR]"
578 echo " [--datadir=DATADIR] [--logdir=LOGDIR] [--plugdir=PLUGDIR]"
579 echo
580 echo "Options: "
581 echo " --help Display this help and exit"
582 echo " --version Display version information and exit"
583 echo
584 echo " --prefix=PREFIX Install Monkey under PREFIX directory"
585 echo " --bindir=BINDIR Install Monkey binaries under BINDIR directory"
586 echo " --cgibin=CGIBINDIR Install Monkey cgi-bin under CGIBIN directory"
587 echo " --sysconfdir=SYSCONFDIR Install Monkey conf files under SYSCONFDIR dir"
588 echo " --datadir=DATADIR Install Monkey data dir files under DATADIR directory"
589 echo " --logdir=LOGDIR Install Monkey log files under LOGDIR directory"
590 echo " --plugdir=PLUGDIR Target directory for Monkey plugins"
591 echo
592 exit 1
594 esac
595 done
597 echo "********************************************"
598 echo " Monkey HTTP Daemon v$VERSION "
599 echo "* http://www.monkey-project.com *"
600 echo "* ---------------------------------------- *"
601 echo "* We need beta testers, developers and *"
602 echo "* translators!, if u want help to this *"
603 echo "* project, email me : *"
604 echo "* *"
605 echo "* edsiper@gmail.com *"
606 echo "* *"
607 echo "* Thanks for use Monkey!!! *"
608 echo "* *"
609 echo "********************************************"
610 echo "System : $SYSINFO"
612 lang="en"
614 # starting main function
615 main prefix lang bindir cgibin sysconfdir datadir logdir plugdir modules SYSNAME VERSION
616 exit 0