forked from monkey/monkey
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure
executable file
·1351 lines (1173 loc) · 33.1 KB
/
configure
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
#
# Monkey HTTP Server
# ==================
# Copyright 2001-2014 Monkey Software LLC <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
__MONKEY__="1"
__MONKEY_MINOR__="6"
__MONKEY_PATCHLEVEL__="0"
__MONKEY_GIT__="release"
VERSION="1.6.0"
SONAME="libmonkey.so.$__MONKEY__.$__MONKEY_MINOR__"
SYSNAME=`uname -s`
SYSINFO=`uname -sr`
INCDIR="src/include/"
BOLD="\033[1m"
END_COLOR="\033[0m"
GREEN="\033[0;32m"
YELLOW="\033[1;33m"
RED="\033[0;31m"
BLUE="\033[0;34m"
# Bash colors
txtblk='\e[0;30m' # Black - Regular
txtred='\e[0;31m' # Red
txtgrn='\e[0;32m' # Green
txtylw='\e[0;33m' # Yellow
txtblu='\e[0;34m' # Blue
txtpur='\e[0;35m' # Purple
txtcyn='\e[0;36m' # Cyan
txtwht='\e[0;37m' # White
bldblk='\e[1;30m' # Black - Bold
bldred='\e[1;31m' # Red
bldgrn='\e[1;32m' # Green
bldylw='\e[1;33m' # Yellow
bldblu='\e[1;34m' # Blue
bldpur='\e[1;35m' # Purple
bldcyn='\e[1;36m' # Cyan
bldwht='\e[1;37m' # White
unkblk='\e[4;30m' # Black - Underline
undred='\e[4;31m' # Red
undgrn='\e[4;32m' # Green
undylw='\e[4;33m' # Yellow
undblu='\e[4;34m' # Blue
undpur='\e[4;35m' # Purple
undcyn='\e[4;36m' # Cyan
undwht='\e[4;37m' # White
bakblk='\e[40m' # Black - Background
bakred='\e[41m' # Red
bakgrn='\e[42m' # Green
bakylw='\e[43m' # Yellow
bakblu='\e[44m' # Blue
bakpur='\e[45m' # Purple
bakcyn='\e[46m' # Cyan
bakwht='\e[47m' # White
txtrst='\e[0m' # Text Reset
# Create configuration files under 'conf/'
make_conf()
{
cat $base_path/$INCDIR/config.path $base_path/lang/$lang/mconf \
$base_path/lang/$lang/sites/default > makeconf.sh
sed -i "s/#PORT#/$default_port/g" makeconf.sh
sed -i "s/#USER#/$default_user/g" makeconf.sh
sed -i 's|#PIDFILE#|'$pidfile'|g' makeconf.sh
chmod 755 makeconf.sh
./makeconf.sh
rm makeconf.sh
rm $base_path/$INCDIR/config.path
}
local_dirs()
{
bin="bin"
logs="logs"
sites="conf/sites"
if [ ! -d $bin ]; then
mkdir -p $bin
fi
if [ ! -d $logs ]; then
mkdir -p $logs
fi
if [ ! -d $sites ]; then
mkdir -p $sites
fi
}
abspath() {
{ [[ "$1" =~ ^/ ]] && echo "$1" || echo "$(pwd)/$1"; } | sed -r ':. s#(/|^)\./#\1#g; t .; :: s#[^/]{1,}/\.\./##; t :'
}
# Main function
main()
{
local_dirs
dir=0
actual_path=`pwd`
# Check if build path is the same or a separate one
base_path=$(dirname $(abspath $0))
if [ "$base_path" != "$actual_path" ]; then
build_sep=1
fi
if [ "$prefix" != "$actual_path" ]; then
dir=1
fi
if [ "$bindir" != "$actual_path/bin" ]; then
dir=1
fi
if [ "$sysconfdir" != "$actual_path/conf" ]; then
dir=1
fi
if [ "$datadir" != "$actual_path/htdocs" ]; then
dir=1
fi
if [ "$logdir" != "$actual_path/logs" ]; then
dir=1
fi
if [ "$mandir" != "$actual_path/man" ]; then
dir=1
fi
echo
echo -e "\033[1m=== Checking dependencies ===\033[0m"
# Check for accept4()
if [ $only_accept4 -eq 1 ]; then
check_generic "accept4() function" "sys/socket.h" "accept4(0, 0, 0, 0)" ""
if [ $result = -1 ]; then
exit 1
fi
elif [ $only_accept -eq 1 ]; then
echo -n "+ Using generic accept()............ "
echo -en $GREEN$BOLD"Yes"$END_COLOR"\n"
DEFS="$DEFS -DACCEPT_GENERIC"
else
check_generic "accept4() function" "sys/socket.h" "accept4(0, 0, 0, 0)" ""
if [ $result -ne 0 ]; then
DEFS="$DEFS -DACCEPT_GENERIC"
fi
fi
if [ $platform == "generic" ]; then
check_generic "pthread headers" "pthread.h" "pthread_t self = pthread_self()" "-lpthread"
fi
if test -z $no_backtrace ; then
check_generic "backtrace support" "execinfo.h" ""
if [ $result -ne 0 ]; then
no_backtrace=1
fi
fi
if test $linux_trace ; then
check_generic "Linux Trace Toolkit (UST)" "lttng/tracepoint.h"
if [ $result -ne 0 ]; then
echo
echo -n "Error: Linux Trace Toolkit (lttng) is not available "
echo "in your system"
echo
exit 1
fi
fi
echo
echo -e "\033[1m=== Plugins included ===\033[0m"
find $base_path/plugins/ -name Makefile -exec rm {} \;
create_makefile_plugins $base_path $plugdir $prefix $bindir $mandir \
$sysconfdir $datadir $logdir $sysconfdir $datadir \
$logdir $mandir $enabled_plugins $disabled_plugins
echo
echo -e "\033[1m=== Creating Makefiles and scripts ===\033[0m"
echo "+ Creating conf/monkey.conf"
create_conf $base_path $prefix
make_conf $base_path $lang $default_port $default_user $pidfile
echo "+ Creating src/Makefile"
create_makefile2 base_path mod_libs mod_obj make_script platform \
malloc_libc malloc_jemalloc
echo "+ Creating plugins/Make.common"
create_plugins_make_common base_path bindir
echo "+ Creating src/include/mk_info.h"
create_info base_path sysconfdir \
SYSNAME __MONKEY__ __MONKEY_MINOR__ __MONKEY_PATCHLEVEL__ \
cmd uname
echo "+ Creating bin/banana script"
create_banana_script bindir logdir default_port
create_monkey_systemd_script bindir logdir default_port systemddir
echo -e "+ Creating Makefile"
if [ "$dir" = 0 ]; then
create_makefile1 bindir malloc_jemalloc
else
create_makefile1_install prefix bindir mandir sysconfdir \
datadir logdir malloc_jemalloc
fi
# if the memory allocator is jemalloc, lets start configuring the dependency
if [ $malloc_jemalloc -eq 1 ]; then
echo
echo -e "\033[1m=== Configuring Memory Allocator ===\033[0m"
cd deps/jemalloc
./configure $JEMALLOC_OPTS \
--with-jemalloc-prefix=je_ \
--enable-cc-silence \
CFLAGS="-std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops " \
LDFLAGS="" > jemalloc.config 2>&1
if [ $? -eq 0 ]; then
echo "+ Jemalloc configured"
else
cat jemalloc.config
echo
echo "check more details with: $ cat deps/jemalloc/config.log"
exit 1
fi
cd ../../
fi
echo
echo -e "\033[1m=== Monkey Configuration ===\033[0m"
echo -e "Platform\t= $platform"
echo -e "Compiler\t= $CC"
echo -e "CFLAGS\t\t= $CFLAGS"
echo -e "LDFLAGS\t\t= $LDFLAGS"
if [ "$DEFS" != "" ]; then
echo -e "DEFS\t\t= $DEFS"
fi
echo
echo -en "Shared library\t= "
[ -n "$sharedlib" ] && echo "enabled" || echo "disabled"
echo -en "Relaxed plugins\t= "
[ -n "$relaxed_plugins" ] && echo "enabled" || echo "disabled"
echo
echo -e "Prefix\t\t= $prefix"
echo -e "Bindir\t\t= $bindir"
echo -e "Libdir\t\t= $libdir"
echo -e "Incdir\t\t= $incdir"
echo -e "Sysconfdir\t= $sysconfdir"
echo -e "Datadir\t\t= $datadir"
echo -e "Mandir\t\t= $mandir"
echo -e "Logdir\t\t= $logdir"
echo -e "PidFile\t\t= $pidfile"
if [ "$plugdir" != "" ]; then
echo -e "Plugdir\t\t= $plugdir"
fi
echo -e "Systemddir\t= $systemddir"
echo
echo "--"
echo -en "$GREEN Monkey $END_COLOR configuration is$YELLOW done!$END_COLOR, to build type 'make"
if [ "$dir" = 1 ]; then
echo -n " && make install' "
else
echo "' "
fi
echo -n "Have fun! ;)"
echo
echo "#ifndef MK_ENV_H" > src/include/mk_env.h
echo "#define MK_ENV_H" >> src/include/mk_env.h
echo "#define CC \"${CC}\"" >> src/include/mk_env.h
echo "#endif" >> src/include/mk_env.h
}
# Test if compiling a file with a given feature will work.
# $1: Description of the feature
# $2: List of needed #includes, separated by spaces
# $3: A function call, e.g. "printf("Hello, world\n")
# $4: A list of libraries, e.g. "-lrt -lpthread"
check_generic() {
printf "+ Checking for %s ... " "$1"
echo -n "" > check.c
for inc in $2; do
printf "#include <%s>\n" "$inc" >> check.c
done
printf "int main(int argc, char *argv) { %s; return 0; }\n" "$3" >> check.c
$CC -D_GNU_SOURCE -Wimplicit -Werror $4 check.c &> configure.log
if [ $? -ne 0 ]; then
result=-1
echo -en $RED$BOLD"No"$END_COLOR"\n"
else
result=0
echo -en $GREEN$BOLD"Yes"$END_COLOR"\n"
fi
rm -f check.c configure.log a.out
}
# Create Makefile
create_makefile1()
{
if [ $malloc_jemalloc -eq 1 ]; then
$deps="deps/jemalloc"
else
$deps=""
fi
cat > Makefile << EOF
# Monkey HTTP Daemon: Makefile
# ============================
all:
@\$(MAKE) -s -C $deps src all
@\$(MAKE) -s -C plugins all
@echo "done"
plugins:
@\$(MAKE) -s -C plugins all
monkeyversion:
@echo $VERSION
help:
@echo "Make help:"
@echo " plugins - Build webserver's plugins"
@echo " monkeyversion - Output the webserver's version"
@echo " clean - Remove generated binary files"
@echo " distclean - Clean plus configuration and Make files"
@echo " "
@echo "Execute 'make' to build the webserver."
clean:
@(cd src; \$(MAKE) clean)
@(cd plugins; \$(MAKE) clean)
distclean:
@(cd src; \$(MAKE) distclean)
EOF
}
# This function check if the plugin must be compiled/installed
# or not based in the following rules:
#
# #1 -> --enable-plugins
# #2 -> --disable-plugins
# #3 -> Plugin spec: MANDATORY, OPTIONAL, DISABLED & EXPERIMENTAL
#
# return values: 0 = No
# 1 = Yes
skip_plugin() {
#echo "skip_plugin($entry) '$enabled_plugins' '$disabled_plugins'"
en_wildcard=0
if [ "$enabled_plugins" == '*' ]; then
en_wildcard=1
fi
di_wildcard=0
if [ "$disabled_plugins" == '*' ]; then
di_wildcard=1
fi
IFS=","
set -- $enabled_plugins
en_array=$@
set -- $disabled_plugins
di_array=$@
unset IFS
enabled=0
disabled=0
for e in $en_array;
do
if [ "$entry" == "$e" ]; then
enabled=1
break
fi
done
for d in $di_array;
do
if [ "$entry" == "$d" ]; then
disabled=1
break
fi
done
path="plugins/$entry"
if ! test -d $path; then
return 1
fi
# does it contains a proper Makefile.in ?
if test ! -e $path/Makefile.in ; then
return 1
fi
# Check enable wildcard */
if [ $en_wildcard -eq 1 ] && [ $disabled -eq 0 ]; then
return 0
fi
# Check disable wildcard */
if [ $di_wildcard -eq 1 ] && [ $enabled -eq 0 ]; then
return 1
fi
# disabled and not enforced
if [ $disabled -eq 1 ] && [ $enabled -eq 0 ]; then
return 1
fi
if [ $disabled -eq 0 ] && [ $enabled -eq 1 ]; then
return 0
fi
# Disabled by spec and not enforced
if test -e $path/DISABLED && [ $enabled -eq 0 ] ; then
return 1
fi
# Experimental and not enforced
if test -e $path/EXPERIMENTAL && [ $enabled -eq 1 ]; then
return 1
fi
# Optional plugin and not disabled
if test -e $path/OPTIONAL && [ $disabled -eq 0 ]; then
return 0
fi
# Mandatory plugin and not disabled
if test -e $path/MANDATORY && [ $disabled -eq 0 ]; then
return 0
fi
# Return True by default
return 1
}
create_makefile1_install()
{
# memory allocator
if [ $malloc_jemalloc -eq 1 ]; then
all_deps="$all_deps jemalloc"
else
deps=""
fi
# remove old data
rm -rf plugins.conf plugins.list
touch plugins.conf
for e in conf/plugins/*
do
entry=`echo $e | awk -F "/" '{print $3}'`
skip_plugin $entry $enabled_plugins $disabled_plugins
if [ $? == 1 ]; then
continue
fi
echo -e "\tcp -r conf/plugins/$entry \${SYSCONFDIR}/plugins/" >> plugins.conf
done
plgconf=`cat plugins.conf`
for e in plugins/*
do
entry=`echo $e | awk -F "/" '{print $2}'`
skip_plugin $entry $enabled_plugins $disabled_plugins
if [ $? == 1 ]; then
continue
fi
echo -e "\tinstall -m 644 plugins/$entry/*.so \${PLUGINDIR}/" >> plugins.list
done
plglist=`cat plugins.list`
if [ -n "$sharedlib" ]; then
incinstall=" install -m 644 src/include/public/libmonkey.h \$(INCDIR)"
fi
ins_systemd=""
if [ $systemddir ]; then
ins_systemd=" install -d \$(SYSTEMDDIR)
install -m 644 monkey.service \$(SYSTEMDDIR)"
fi
cat > Makefile <<EOF
# Monkey HTTP Daemon: Makefile
# ============================
export monkey_root=\$(CURDIR)
PREFIX=\$(DESTDIR)${prefix}
BINDIR=\$(DESTDIR)${bindir}
LIBDIR=\$(DESTDIR)${libdir}
INCDIR=\$(DESTDIR)${incdir}
MANDIR=\$(DESTDIR)${mandir}
SYSCONFDIR=\$(DESTDIR)${sysconfdir}
DATADIR=\$(DESTDIR)${datadir}
LOGDIR=\$(DESTDIR)${logdir}
SYSTEMDDIR=$systemddir
PLUGINDIR=\$(DESTDIR)${plugdir}
VERSION=$VERSION
all: monkey.pc $all_deps
@\$(MAKE) -s -C $base_path/src all
@\$(MAKE) -s -C plugins all
@echo " DONE"
jemalloc:
@echo " CC jemalloc [all]"
@\$(MAKE) -s -C deps/jemalloc
clean:
@(cd src; \$(MAKE) clean)
@(cd plugins; \$(MAKE) clean)
@rm -f monkey.pc
distclean:
@(cd src; \$(MAKE) distclean)
install:
\$(MAKE) -C src all
install -d \$(BINDIR)
install -d \$(LIBDIR)/pkgconfig
install -d \$(INCDIR)
install -d \$(MANDIR)/man1
install -d \$(MANDIR)/man3
install -d \$(SYSCONFDIR)
install -d \${SYSCONFDIR}/sites
install -d \${SYSCONFDIR}/plugins
install -d \${DATADIR}
install -d \${DATADIR}/imgs
install -d \${DATADIR}/php
install -d \${DATADIR}/docs
install -d \${LOGDIR}
install -d \${PLUGINDIR}
install -m 755 bin/* \$(BINDIR)
install -m 644 ./conf/*.* \$(SYSCONFDIR)
install -m 644 src/include/*.h \$(INCDIR)
$ins_systemd
$plgconf
$plglist
install -m 644 ./conf/sites/* \${SYSCONFDIR}/sites
install -m 644 ./man/*.1 \$(MANDIR)/man1
install -m 644 ./man/*.3 \$(MANDIR)/man3
$incinstall
-install -m 644 src/$SONAME \$(LIBDIR)
-install -m 644 monkey.pc \$(LIBDIR)/pkgconfig
-ln -sf $SONAME \$(LIBDIR)/libmonkey.so
install -m 644 ./htdocs/index.html \$(DATADIR)
install -m 644 ./htdocs/404.html \$(DATADIR)
install -m 644 ./htdocs/favicon.ico \$(DATADIR)
install -d \$(DATADIR)/imgs
install -m 644 ./htdocs/imgs/monkey_logo.png \$(DATADIR)/imgs
install -m 644 ./htdocs/imgs/info_pic.jpg \$(DATADIR)/imgs
install -d \$(DATADIR)/css
install -m 644 ./htdocs/css/bootstrap.min.css \$(DATADIR)/css
@echo
@echo " Running Monkey :"
@echo " ----------------"
@echo
@echo " # $bindir/monkey"
@echo
@echo " For more help use '-h' option"
@echo
monkey.pc:
@sed -e "s@PREFIX@$prefix@" -e "s@LIBDIR@$libdir@" -e "s@INCDIR@$incdir@" \
-e "s@VERSION@$VERSION@" monkey.pc.in > monkey.pc
EOF
}
# Create monkey/src/Makefile
create_makefile2()
{
if [ $platform == "generic" ]; then
libs="$libs -pthread"
elif [ $platform == "android" ]; then
libs="$libs "
fi
if [ -n "$sharedlib" ]; then
alltarget="../bin/monkey lib"
else
alltarget="../bin/monkey"
fi
if [ $malloc_jemalloc -eq 1 ]; then
extra="../deps/jemalloc/lib/libjemalloc.a"
extraso="-Wl,--whole-archive ../deps/jemalloc/lib/libjemalloc_pic.a -Wl,--no-whole-archive"
libs="$libs -lm"
fi
p=`pwd`/src
cat > $base_path/src/Makefile<<EOF
_PATH = \$(patsubst \$(monkey_root)/%, %, \$(CURDIR))
CC = @echo " CC \$(_PATH)/\$@"; $CC
CC_QUIET= @echo -n; $CC
CFLAGS = $CFLAGS
DEFS += $DEFS
LIBDEFS = -DSHAREDLIB -fPIC \$(DEFS)
INCDIR = ./include
LDFLAGS = $LDFLAGS
DESTDIR = ../bin/monkey
LIBS = -ldl $libs
OBJ = monkey.o mk_method.o mk_mimetype.o mk_vhost.o mk_request.o \\
mk_header.o mk_config.o mk_signals.o \\
mk_user.o mk_utils.o mk_epoll.o mk_scheduler.o \\
mk_string.o mk_memory.o mk_connection.o mk_iov.o mk_http.o \\
mk_file.o mk_socket.o mk_clock.o mk_cache.o \\
mk_server.o mk_kernel.o mk_rbtree.o mk_plugin.o mk_lib.o
LIBOBJ = \$(OBJ:.o=.lo)
.PHONY: clean distclean lib
all: $alltarget
lib: $SONAME
-include \$(OBJ:.o=.d)
../bin/monkey: \$(OBJ)
\$(CC_QUIET) \$(CFLAGS) \$(DEFS) \$(LDFLAGS) -o $p/\$@ \$(OBJ) $mod_obj $extra \$(LIBS)
$SONAME: \$(LIBOBJ)
\$(CC_QUIET) \$(CFLAGS) \$(LIBDEFS) \$(LDFLAGS) -Wl,-soname,$SONAME -shared -o \$@ $extraso \$(LIBOBJ) $mod_obj \$(LIBS)
ln -sf $SONAME libmonkey.so
\$(LIBOBJ): \$(OBJ)
clean:
rm -rf *.[od] $SONAME libmonkey.so *.lo
rm -rf ../bin/monkey
distclean:
rm -rf *.o ../bin/* Makefile \\
../Makefile ../conf/monkey.conf \\
../conf/sites/* include/mk_info.h ../logs/*
find ../plugins -name Makefile -exec rm {} \;
.c.o:
\$(CC) -c \$(CFLAGS) \$(DEFS) -I\$(INCDIR) \$<
\$(CC_QUIET) -MM -MP \$(CFLAGS) \$(DEFS) -I\$(INCDIR) \$*.c -o $p/\$*.d > /dev/null &2>&1
%.lo : %.c
\$(CC) -c -o $p/\$@ \$(CFLAGS) \$(LIBDEFS) -I\$(INCDIR) \$<
EOF
}
create_makefile_plugins()
{
#dir=`pwd`
dir=$basepath
makefile="plugins/Makefile"
plugins_load="conf/plugins.load"
echo -n > $plugins_load
echo "# Monkey Plugins Loader" >> $plugins_load
echo "# =====================" >> $plugins_load
echo "# Monkey plugins are extended functionalities for Monkey," >> $plugins_load
echo "# the main directive to load a plugin is LoadPlugin plus" >> $plugins_load
echo "# the absolute path for the desired plugin." >> $plugins_load
echo "#" >> $plugins_load
echo "# Please check the following list of available plugins:" >> $plugins_load
echo "" >> $plugins_load
echo "[PLUGINS]" >> $plugins_load
echo "" >> $plugins_load
if [ $platform == "android" ]; then
if test -z $disabled_plugins; then
disabled_plugins="cheetah,palm,logger,cgi"
fi
fi
for plugin_dir in $base_path/plugins/*;
do
# Skip non-directories
if ! test -d "$plugin_dir" ; then
continue
fi
# Get plugin name and check if we should skip it
entry=`echo $plugin_dir | awk -F "/" '{print $NF}'`
skip_plugin $entry $enabled_plugins $disabled_plugins
disabled=$?
if [ $disabled == 1 ]; then
continue
fi
echo $entry
comment=" "
for i in $entry; do name=`echo -n "${i:0:1}" | tr "[:lower:]" "[:upper:]"`;
echo -e "+ ${name}${i:1}";
done
echo "----->"$plugin_dir
# Create Makefile
MAKE_ALL="${MAKE_ALL}\t@(cd $entry && \$(MAKE) && cd ..)\n"
MAKE_CLEAN="${MAKE_CLEAN}\t@(cd $entry && \$(MAKE) clean && cd ..)\n"
for d in `find $plugin_dir -xtype d`
do
if [ -f "${d}/Makefile.in" ];
then
sed -e "s|\$CC|$CC|" -e "s|\$CFLAGS|$CFLAGS|" -e "s|\$LDFLAGS|$LDFLAGS|" -e "s|\$DEFS|$DEFS|" $d/Makefile.in > $d/Makefile
fi
done
# Add details to plugins.load using ABOUT file
if test -e $plugin_dir/ABOUT ; then
cat $plugin_dir/ABOUT | sed -e 's/^/ # /' >> $plugins_load
echo " #" >> $plugins_load
else
echo " #" >> $plugins_load
fi
if ! test -e $plugin_dir/MANDATORY ; then
comment=" # "
fi
if [ "$plugdir" != "$aux/plugins" ]; then
echo "${comment}Load $plugdir/monkey-$entry.so" >> $plugins_load
else
echo "${comment}Load $dir/$plugin_dir/monkey-$entry.so" >> $plugins_load
fi
echo "" >> $plugins_load
# Copy specific plugin configuration files
echo $base_path/$plugin_dir/conf
if test -e $base_path/$plugin_dir/conf ; then
target="conf/$plugin_dir/"
mkdir -p $target
cp -r $base_path/$plugin_dir/conf/* $target/
# Replace configuration variables:
find $target/* -xtype f -exec sed -i "s,#PREFIX#,$prefix," {} ';'
find $target/* -xtype f -exec sed -i "s,#BINDIR#,$bindir," {} ';'
find $target/* -xtype f -exec sed -i "s,#LIBDIR#,$libdir," {} ';'
find $target/* -xtype f -exec sed -i "s,#MANDIR#,$mandir," {} ';'
find $target/* -xtype f -exec sed -i "s,#SYSCONFDIR#,$sysconfdir," {} ';'
find $target/* -xtype f -exec sed -i "s,#DATADIR#,$datadir," {} ';'
find $target/* -xtype f -exec sed -i "s,#LOGDIR#,$logdir," {} ';'
find $target/* -xtype f -exec sed -i "s,#PIDFILE#,$pidfile," {} ';'
find $target/* -xtype f -exec sed -i "s,#PLUGDIR#,$plugdir," {} ';'
fi
# Distribute binary scripts provided by plugins
if test -e $plugin_dir/bin ; then
cp -r $plugin_dir/bin/* bin/
fi
done
echo "all:" > $base_path/$makefile
echo -e $MAKE_ALL >> $base_path/$makefile
echo "" >> $base_path/$makefile
echo "clean:" >> $base_path/$makefile
echo -e $MAKE_CLEAN >> $base_path/$makefile
# Add 'install' option to Makefile if plugdir was specified
if [ "$plugdir" != "" ]; then
echo -e "\ninstall:" >> $base_path/$makefile
echo -e "\tinstall -d $plugdir" >> $base_path/$makefile
for plugin_dir in plugins/*;
do
# Get plugin name and check if we should skip it
entry=`echo $plugin_dir | awk -F "/" '{print $2}'`
skip_plugin $entry $enabled_plugins $disabled_plugins
disabled=$?
if [ $disabled == 1 ]; then
continue
fi
echo -e "\tinstall -m 644 $dir/$plugin_dir/monkey-$entry.so $plugdir/" >> $makefile
done
fi
}
# Create plugins/Make.common
create_plugins_make_common()
{
LIBS=''
if [ $malloc_jemalloc == 1 ]; then
LIBS=`pwd`/deps/jemalloc/lib/libjemalloc.a
fi
cat > $base_path/plugins/Make.common <<EOF
_PATH = \$(patsubst \$(monkey_root)/%, %, \$(CURDIR))
INC_EXTRA = "./"
INCDIR = ../../src/include -I\$(INC_EXTRA)
MONKEY_OBJECTS = \$(wildcard ../../src/*.o)
MONKEY_OBJECTS_N = \$(filter-out ../../src/monkey.o, \$(MONKEY_OBJECTS))
MONKEY_BIN_DIR = $bindir
LIBS = $LIBS
.c.o:
\$(CC) \$(CFLAGS) \$(DEFS) -I\$(INCDIR) -fPIC -c $<
\$(CC_QUIET) -MM -MP \$(CFLAGS) \$(DEFS) -I\$(INCDIR) -I\$(INC_EXTRA) \$*.c -o \$*.d > /dev/null &2>&1
clean:
rm -rf *.[od] *~ *.*so* \$(MONKEY_BIN_DIR)/mk_*
EOF
}
# Creando include/mk_info.h
create_info()
{
cat > $base_path/$INCDIR/mk_info.h <<EOF
#ifndef MK_INFO_H
#define MK_INFO_H
#define OS "$SYSNAME"
#define __MONKEY__ $__MONKEY__
#define __MONKEY_MINOR__ $__MONKEY_MINOR__
#define __MONKEY_PATCHLEVEL__ $__MONKEY_PATCHLEVEL__
#define MONKEY_VERSION (__MONKEY__ * 10000 \\
__MONKEY_MINOR__ * 100 \\
__MONKEY_PATCHLEVEL__)
#define VERSION "$__MONKEY__.$__MONKEY_MINOR__.$__MONKEY_PATCHLEVEL__"
#define MK_BUILD_CMD "$cmd"
#define MK_BUILD_UNAME "$uname"
#define MONKEY_PATH_CONF "$sysconfdir"
#define PLUGDIR "$plugdir"
#endif
EOF
sed -i -e "s@#define MONKEY__.*@#define MONKEY__ $__MONKEY__@" \
-e "s@#define MONKEY_MINOR__.*@#define MONKEY_MINOR__ $__MONKEY_MINOR__@" \
-e "s@#define MONKEY_PATCHLEVEL__.*@#define MONKEY_PATCHLEVEL__ $__MONKEY_PATCHLEVEL__@" \
$base_path/$INCDIR/public/libmonkey.h
}
create_conf()
{
cat > $base_path/$INCDIR/config.path <<EOF
#!/bin/sh
prefix=$prefix
bindir=$bindir
libdir=$libdir
incdir=$incdir
sysconfdir=$sysconfdir
datadir=$datadir
logdir=$logdir
EOF
}
create_monkey_systemd_script()
{
if [ $systemddir ]; then
echo "+ Creating systemd.service unit file"
cat > monkey.service << EOF
[Unit]
Description=Monkey HTTP Server
Requires=network.target
After=network.target
[Service]
Type=fork
ExecStart=$bindir/monkey -D
PIDFile=$pidfile.$default_port
Restart=always
[Install]
WantedBy=multi-user.target
EOF
fi
}
create_banana_script()
{
cat > bin/banana << EOF
#!/bin/sh
#
# Monkey HTTP Daemon - Banana Script
# -----------------------------------
# This script allow you to control monkey. Written by Eduardo Silva
# ----------------------------
# Date : 2002/09/01.
# ----------------------------
#
# Use: ./banana OPTION
#
# Options available to banana:
#
# start -> start monkey
# restart -> restart monkey
# stop -> stop monkey if this is running
# status -> check if monkey is running
# help -> what do u think ?
CONFDIR="$sysconfdir"
BINMONKEY="$bindir/monkey"
PORT=\$(sed -n '/^[ \t]*Port/s/^.* //p' "\$CONFDIR/monkey.conf")
PIDFILE=\$(sed -n '/^[ \t]*PidFile/s/^.* //p' "\$CONFDIR/monkey.conf")."\$PORT"
for arg in \$*; do
case "\$arg" in
-*=*) optarg=\`echo "\$arg" | sed 's/[-_a-zA-Z0-9]*=//'\` ;;
*) optarg= ;;
esac
if ! test -f \$PIDFILE ; then
STATUS="no"
else
PIDMONKEY=\`cat \$PIDFILE\`
if ! kill -0 \$PIDMONKEY 2>/dev/null; then
STATUS="no"
else
STATUS="yes"
fi
fi
case "\$arg" in
start)
if [ "\$STATUS" = "yes" ] ; then
echo "Monkey is running... (PID=\$PIDMONKEY)"
exit 1
fi
if ! test -x \$BINMONKEY ; then
echo "Error: I can't run binary file"
exit 1
else
if \$BINMONKEY -D 2>/dev/null ; then
echo "Running Monkey -> OK"
exit 0
fi
fi
;;
stop)
if [ "\$STATUS" = "no" ]; then
echo "Monkey is not running."
exit 1
fi
kill -9 \$PIDMONKEY
rm -rf \$PIDFILE > /dev/null
echo "Monkey stopped (\$PIDMONKEY)"
exit 0
;;
restart)
if [ "\$STATUS" = "yes" ]; then
if ! kill \$PIDMONKEY > /dev/null ; then
killall -9 monkey
else
echo -n "Stopping Monkey... "
fi
else
echo -n "Monkey is not running... "
fi
if ! test -x \$BINMONKEY ; then
echo "Error: I can't run binary file"
exit 1
else
\$BINMONKEY -D > /dev/null
echo "Restarting -> OK"
exit 0
fi
;;
status)
if [ "\$STATUS" = "yes" ]; then
echo "Monkey is running... (PID=\$PIDMONKEY)"