content-type support
[lnanohttp.git] / make
blobdf7cc158e3f74e9da64c437f272806411e25e205
1 #!/bin/sh
3 # stolen from ffmpeg configure like a pig
4 # this is brutal and stupid... then easy and explicit
6 # Prevent locale nonsense from breaking basic text processing.
7 LC_ALL=C
8 export LC_ALL
10 #-------------------------------------------------------------------------------
11 #uppercase S tells gcc assembler to run the pre-preprocessor
12 #lowercase s tells gcc assembler _NOT_ to run the pre-preprocessor
14 ulinux_target_arch_asm_srcs='
15 ulinux/arch/sysc.S
16 ulinux/arch/utils/endian.S
19 ulinux_c_srcs='
20 ulinux/utils/mem.c
21 ulinux/utils/ascii/string/vsprintf.c
23 #-------------------------------------------------------------------------------
26 #-------------------------------------------------------------------------------
27 lnanohttp_bin_ulinux_objs='
28 sysc.o
29 endian.o
30 mem.o
31 vsprintf.o
33 lnanohttp_bin_srcs='
34 lnanohttp.c
36 #-------------------------------------------------------------------------------
39 clean_do(){
40 files="
41 $lnanohttp_bin_ulinux_objs
44 for src_file in $lnanohttp_bin_srcs
46 obj=${src_file%.c}
47 obj=${obj}.o
48 files="$obj $files"
49 done
51 rm -f $files
52 rm -f ulinux/arch
53 rmdir ulinux
54 exit 0
57 ################################################################################
59 # find source path
60 if test -f make; then
61 src_path=.
62 else
63 src_path=$(cd $(dirname "$0"); pwd)
64 echo "$src_path" | grep -q '[[:blank:]]' &&
65 die "Out of tree builds are impossible with whitespace in source path."
66 test -e "$src_path/config.h" &&
67 die "Out of tree builds are impossible with config.h in source dir."
70 is_in(){
71 value=$1
72 shift
73 for var in $*; do
74 [ $var = $value ] && return 0
75 done
76 return 1
79 append(){
80 var=$1
81 shift
82 eval "$var=\"\$$var $*\""
85 die(){
86 echo "$0"
87 exit 1
90 die_unknown(){
91 echo "Unknown option \"$1\"."
92 echo "See $0 --help for available options."
93 exit 1
96 set_default(){
97 for opt; do
98 eval : \${$opt:=\$${opt}_default}
99 done
102 CMDLINE_SET='
103 arch
106 bin_ccld_tmpl
109 #command line, set defaults
110 arch_default=$(uname -m | sed -e s/i.86/x86/ -e s/parisc64/parisc/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/ -e s/sh.*/sh/)
111 asm_default='gcc -c'
112 cc_default='gcc -Wall -Wextra -Wno-missing-field-initializers -c -fpic -O0'
113 bin_ccld_tmpl_default="ld -Bstatic -nostdlib \$objects $(gcc -print-libgcc-file-name)"
115 #(tinycc + binutils) toolchain
116 ##asm_default='as'
117 ##cc_default='/home/sylvain/local/tinycc/bin/tcc -c'
118 ##bin_ccld_tmpl_default="ld \$objects"
120 set_default $CMDLINE_SET
122 show_help(){
123 cat <<EOF
124 Usage: make [options] [operations]
126 Operations: [default is to build the http server binary]:
127 clean clean build products
130 Options: [defaults in brackets after descriptions]
132 Help options:
133 --help print this message
135 Advanced options (experts only):
136 --arch=ARCH use ulinux target ARCH [$arch_default]
137 --asm=ASM use target arch assembler command line ASM [$asm_default]
138 --cc=CC use target arch C compiler command line CC [$cc_default]
139 --bin-ccld-tmpl=BIN_CCLD_TMPL use linker command line template BIN_CCLD_TMPL for target arch binary [$bin_ccld_tmpl_default]
141 exit 0
144 for opt do
145 optval="${opt#*=}"
146 case "$opt" in
147 clean) clean_do
149 --help|-h) show_help
152 optname="${opt%%=*}"
153 optname="${optname#--}"
154 optname=$(echo "$optname" | sed 's/-/_/g')
155 if is_in $optname $CMDLINE_SET; then
156 eval $optname='$optval'
157 elif is_in $optname $CMDLINE_APPEND; then
158 append $optname "$optval"
159 else
160 die_unknown $opt
163 esac
164 done
167 #-------------------------------------------------------------------------------
168 #configure our ultra-thin linux user API abstraction layer
169 rm -f ulinux/arch
170 mkdir -p ulinux
171 ln -f -s $src_path/ulinux/archs/$arch ulinux/arch
172 #-------------------------------------------------------------------------------
175 #-------------------------------------------------------------------------------
176 #assemble src files
177 target_arch_asm_srcs="
178 $ulinux_target_arch_asm_srcs
181 for src_file in $target_arch_asm_srcs
183 obj=${src_file%.S}
184 obj=${obj}.o
185 echo ASM $src_file
186 $asm -o $(basename $obj) $src_file
187 done
188 #-------------------------------------------------------------------------------
191 #-------------------------------------------------------------------------------
192 #C compile src files
193 c_srcs="
194 $ulinux_c_srcs
195 $lnanohttp_bin_srcs
197 for src_file in $c_srcs
199 obj=${src_file%.c}
200 obj=${obj}.o
201 echo CC $src_file
202 $cc -o $(basename $obj) -I./ -I$src_path $src_path/$src_file
203 c_objs="$obj $c_objs"
204 done
205 #-------------------------------------------------------------------------------
208 #-------------------------------------------------------------------------------
209 #link the lnanohttp binary
210 for src_file in $lnanohttp_bin_srcs
212 obj=${src_file%.c}
213 obj=${obj}.o
214 lnanohttp_bin_objs="$obj $lnanohttp_bin_objs"
215 done
216 lnanohttp_bin_objs="$lnanohttp_bin_objs $lnanohttp_bin_ulinux_objs"
218 echo BIN_CCLD lnanohttp
219 #resolve the template
220 objects=$lnanohttp_bin_objs
221 eval bin_ccld=\"$bin_ccld_tmpl\"
222 $bin_ccld -o lnanohttp
223 #-------------------------------------------------------------------------------