Skip to content
This repository was archived by the owner on May 26, 2025. It is now read-only.

Commit c39a9ad

Browse files
author
Andrewerr
committed
Build-system fixes
1 parent 6e7bd66 commit c39a9ad

24 files changed

+266
-162
lines changed

Buildfile

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
BASEDIR=`pwd`
2+
CC="gcc"
3+
CFLAGS="-Wall -I${BASEDIR}/library/libddos2"
4+
LD="ld"
5+
LD_FLAGS="-ldl"
6+
OBJ_DIR="obj/"
7+
BIN_DIR="bin/"
8+
LIB_DIR="lib/"
9+
MODULES_DIR="modules/"
10+
MODULES_BIN="bin/modules/"
11+
EXECUTABLE="ddos2"
12+
13+
declare -a SOURCES=("message" "array" "hashtable" "cache" "commons" "network" "module" "arguments" "main")
14+
declare -a MODULES=("mod_a" "mod_udp")
15+
16+
cd $BASEDIR
17+
18+
target_check(){
19+
require_command $CC
20+
require_command $LD
21+
}
22+
target_clean(){
23+
info "Cleaning up."
24+
exec "rm -rf ${OBJ_DIR}"
25+
exec "rm -rf ${BIN_DIR}"
26+
exec "rm -rf ${LIB_DIR}"
27+
success "Cleaned."
28+
}
29+
30+
target_library(){
31+
change_dir "library/libddos2"
32+
exec "./build.sh release" #TODO:In debug – set debug target
33+
leave_dir
34+
}
35+
36+
target_library-debug(){
37+
change_dir "library/libddos2"
38+
exec "./build.sh debug"
39+
leave_dir
40+
}
41+
42+
target_debug(){
43+
target_check
44+
CC="gcc-9"
45+
require_command $CC
46+
info "Building debug."
47+
require_directory $OBJ_DIR
48+
require_directory $BIN_DIR
49+
require_directory $MODULES_BIN
50+
leave_dir
51+
for file in "${SOURCES[@]}"
52+
do
53+
exec "${CC} -c ${CFLAGS} -fsanitize=leak -fsanitize=address -fsanitize=undefined src/${file}.c -o ${OBJ_DIR}${file}.o"
54+
done
55+
change_dir $OBJ_DIR
56+
objects=$(printf " %s.o" "${SOURCES[@]}")
57+
exec "${CC} ${LD_FLAGS} -lasan -lubsan -o ${BASEDIR}/${BIN_DIR}${EXECUTABLE} ${objects}"
58+
leave_dir
59+
success "Succesfully built debug."
60+
}
61+
62+
target_release(){
63+
info "Building release."
64+
require_directory $OBJ_DIR
65+
require_directory $BIN_DIR
66+
require_directory $MODULES_BIN
67+
for file in "${SOURCES[@]}"
68+
do
69+
exec "${CC} -c ${CFLAGS} -Ofast src/${file}.c -o ${OBJ_DIR}${file}.o"
70+
done
71+
change_dir $OBJ_DIR
72+
objects=$(printf " %s.o" "${SOURCES[@]}")
73+
exec "${CC} ${LD_FLAGS} -o ${BASEDIR}/${BIN_DIR}${EXECUTABLE} ${objects}"
74+
leave_dir
75+
success "Succesfully built release."
76+
}
77+
78+
target_modules(){
79+
target_library
80+
info "Building modules."
81+
require_directory $BIN_DIR
82+
require_directory $MODULES_BIN
83+
for module in "${MODULES[@]}"
84+
do
85+
change_dir $MODULES_DIR
86+
change_dir $module
87+
exec "./build.sh all"
88+
leave_dir
89+
done
90+
success "Succesfully built modules."
91+
}
92+
93+
94+
95+
target_all(){
96+
target_release
97+
target_modules
98+
}
99+
100+
target_all-debug(){
101+
target_library-debug
102+
target_debug
103+
target_modules
104+
}
105+
106+
target_test(){
107+
target_all
108+
exec "./bin/ddos2 --module mod_a --test"
109+
}

build.sh

Lines changed: 1 addition & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -135,113 +135,7 @@ if [[ $1 == "-h" ]]; then
135135
exit 0
136136
fi
137137

138-
BASEDIR=`pwd`
139-
CC="gcc"
140-
CFLAGS="-Wall -I${BASEDIR}/library/libddos2"
141-
LD="ld"
142-
LD_FLAGS="-ldl"
143-
OBJ_DIR="obj/"
144-
BIN_DIR="bin/"
145-
LIB_DIR="lib/"
146-
MODULES_DIR="modules/"
147-
MODULES_BIN="bin/modules/"
148-
EXECUTABLE="ddos2"
149-
150-
declare -a SOURCES=("message" "array" "hashtable" "cache" "commons" "network" "module" "arguments" "main")
151-
declare -a MODULES=("mod_a" "mod_udp")
152-
153-
target_check(){
154-
require_command $CC
155-
require_command $LD
156-
}
157-
target_clean(){
158-
info "Cleaning up."
159-
exec "rm -rf ${OBJ_DIR}"
160-
exec "rm -rf ${BIN_DIR}"
161-
exec "rm -rf ${LIB_DIR}"
162-
success "Cleaned."
163-
}
164-
165-
target_library(){
166-
change_dir "library/libddos2"
167-
exec "./build.sh release" #TODO:In debug – set debug target
168-
leave_dir
169-
}
170-
171-
target_library-debug(){
172-
change_dir "library/libddos2"
173-
exec "./build.sh debug"
174-
leave_dir
175-
}
176-
177-
target_debug(){
178-
target_check
179-
CC="gcc-9"
180-
require_command $CC
181-
info "Building debug."
182-
require_directory $OBJ_DIR
183-
require_directory $BIN_DIR
184-
require_directory $MODULES_BIN
185-
leave_dir
186-
for file in "${SOURCES[@]}"
187-
do
188-
exec "${CC} -c ${CFLAGS} -fsanitize=leak -fsanitize=address -fsanitize=undefined ${file}.c -o ${OBJ_DIR}${file}.o"
189-
done
190-
change_dir $OBJ_DIR
191-
objects=$(printf " %s.o" "${SOURCES[@]}")
192-
exec "${CC} ${LD_FLAGS} -lasan -lubsan -o ${BASEDIR}/${BIN_DIR}${EXECUTABLE} ${objects}"
193-
leave_dir
194-
success "Succesfully built debug."
195-
}
196-
197-
target_release(){
198-
info "Building release."
199-
require_directory $OBJ_DIR
200-
require_directory $BIN_DIR
201-
require_directory $MODULES_BIN
202-
for file in "${SOURCES[@]}"
203-
do
204-
exec "${CC} -c ${CFLAGS} -Ofast ${file}.c -o ${OBJ_DIR}${file}.o"
205-
done
206-
change_dir $OBJ_DIR
207-
objects=$(printf " %s.o" "${SOURCES[@]}")
208-
exec "${CC} ${LD_FLAGS} -o ${BASEDIR}/${BIN_DIR}${EXECUTABLE} ${objects}"
209-
leave_dir
210-
success "Succesfully built release."
211-
}
212-
213-
target_modules(){
214-
target_library
215-
info "Building modules."
216-
require_directory $BIN_DIR
217-
require_directory $MODULES_BIN
218-
for module in "${MODULES[@]}"
219-
do
220-
change_dir $MODULES_DIR
221-
change_dir $module
222-
exec "./build.sh all"
223-
leave_dir
224-
done
225-
success "Succesfully built modules."
226-
}
227-
228-
229-
230-
target_all(){
231-
target_release
232-
target_modules
233-
}
234-
235-
target_all-debug(){
236-
target_library-debug
237-
target_debug
238-
target_modules
239-
}
240-
241-
target_test(){
242-
target_all
243-
exec "./bin/ddos2 --module mod_a --test"
244-
}
138+
source Buildfile
245139

246140
if [[ `type -t "target_${1}"` == "function" ]]; then
247141
eval "target_${1}"

modules/mod_a/Buildfile

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
BASEDIR=`pwd`
2+
CC="gcc"
3+
CFLAGS="-c -fPIC -I../../library/include/"
4+
LD="ld"
5+
LD_FLAGS="-shared -ldl"
6+
OBJ_DIR="../../obj/"
7+
BIN_DIR="../../bin/modules/"
8+
LIB_DIR="../../lib/"
9+
EXECUTABLE="mod_a.so"
10+
11+
declare -a SOURCES=("mod_a" "test" "tests/udp")
12+
13+
target_configure(){
14+
info "Performing pre-build configuration and checks"
15+
check_ld_flag "-shared"
16+
code=$?
17+
if [ ! $code -eq 0 ]; then
18+
warn "ld does not support shared. Will try to use gcc instead of ld"
19+
LD="gcc"
20+
fi
21+
}
22+
target_all(){
23+
target_configure
24+
info "Building mod_a."
25+
require_directory $OBJ_DIR
26+
require_directory "${OBJ_DIR}/tests"
27+
require_directory $BIN_DIR
28+
require_directory $LIB_DIR
29+
for file in "${SOURCES[@]}"
30+
do
31+
exec "${CC} ${CFLAGS} ${file}.c -o ${OBJ_DIR}${file}.o"
32+
done
33+
change_dir $OBJ_DIR
34+
objects=$(printf " %s.o" "${SOURCES[@]}")
35+
exec "${LD} ${LD_FLAGS} -L${BASEDIR}/${LIB_DIR} -o ${BASEDIR}/${BIN_DIR}${EXECUTABLE} ${objects} -lddos2 -lc"
36+
leave_dir
37+
success "Succesfully built mod_a."
38+
}

modules/mod_a/build.sh

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/bin/bash
22
cd $(dirname `which $0`)
33

4+
BASEDIR=`pwd`
5+
46
# Colors
57
if test -t 1; then
68
bold=$(tput bold)
@@ -60,6 +62,44 @@ leave_dir(){
6062
cd $BASEDIR
6163
}
6264

65+
require_ld_flag(){
66+
cd /tmp/
67+
echo "int main(void){ return 0; }" >> /tmp/main.c
68+
gcc -c /tmp/main.c -o /tmp/main.o
69+
ld ${1} /tmp/main.o > /dev/null
70+
code=$?
71+
if [ ! $code -eq 0 ]; then
72+
error "Checking ld has flag ${1}...${red}${bold}FAIL${normal}"
73+
rm -rf /tmp/main.*
74+
rm -rf /tmp/a.out
75+
exit -1
76+
fi
77+
info "Checking ld has flag ${1}...${green}${bold}OK${normal}"
78+
rm -rf /tmp/main.*
79+
rm -rf /tmp/a.out
80+
cd $BASEDIR
81+
}
82+
83+
check_ld_flag(){
84+
cd /tmp/
85+
echo "int main(void){ return 0; }" >> /tmp/main.c
86+
gcc -c /tmp/main.c -o /tmp/main.o
87+
ld ${1} /tmp/main.o >> /dev/null 2>&1
88+
code=$?
89+
if [ ! $code -eq 0 ]; then
90+
info "Checking ld has flag ${1}...${red}${bold}No${normal}"
91+
rm -rf /tmp/main.*
92+
rm -rf /tmp/a.out
93+
cd $BASEDIR
94+
return -1
95+
fi
96+
info "Checking ld has flag ${1}...${green}${bold}Yes${normal}"
97+
rm -rf /tmp/main.*
98+
rm -rf /tmp/a.out
99+
cd $BASEDIR
100+
return 0
101+
}
102+
63103
if [ $# -eq 0 ]; then
64104
error "Please specify target. Use -h option for help."
65105
exit -1
@@ -72,34 +112,7 @@ if [[ $1 == "-h" ]]; then
72112
exit 0
73113
fi
74114

75-
BASEDIR=`pwd`
76-
CC="gcc"
77-
CFLAGS="-c -fPIC -I../../library/include/"
78-
LD="ld"
79-
LD_FLAGS="-ldl"
80-
OBJ_DIR="../../obj/"
81-
BIN_DIR="../../bin/modules/"
82-
LIB_DIR="../../lib/"
83-
EXECUTABLE="mod_a.so"
84-
85-
declare -a SOURCES=("mod_a" "test" "tests/udp")
86-
87-
target_all(){
88-
info "Building mod_a."
89-
require_directory $OBJ_DIR
90-
require_directory "${OBJ_DIR}/tests"
91-
require_directory $BIN_DIR
92-
require_directory $LIB_DIR
93-
for file in "${SOURCES[@]}"
94-
do
95-
exec "${CC} ${CFLAGS} ${file}.c -o ${OBJ_DIR}${file}.o"
96-
done
97-
change_dir $OBJ_DIR
98-
objects=$(printf " %s.o" "${SOURCES[@]}")
99-
exec "${LD} ${LD_FLAGS} -shared -L${BASEDIR}/${LIB_DIR} -o ${BASEDIR}/${BIN_DIR}${EXECUTABLE} ${objects} -lddos2 -lc"
100-
leave_dir
101-
success "Succesfully built mod_a."
102-
}
115+
source Buildfile
103116

104117
if [[ `type -t "target_${1}"` == "function" ]]; then
105118
eval "target_${1}"

modules/mod_udp/Buildfile

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
BASEDIR=`pwd`
2+
CC="gcc"
3+
CFLAGS="-c -fPIC -I../../library/include/"
4+
LD="ld"
5+
LD_FLAGS="-ldl"
6+
OBJ_DIR="../../obj/"
7+
BIN_DIR="../../bin/modules/"
8+
LIB_DIR="../../lib/"
9+
EXECUTABLE="mod_udp.so"
10+
11+
declare -a SOURCES=("util" "socket" "interface" "mod_udp")
12+
13+
target_configure(){
14+
info "Performing pre-build configuration and checks"
15+
check_ld_flag "-shared"
16+
code=$?
17+
if [ ! $code -eq 0 ]; then
18+
warn "ld does not support shared. Will try to use gcc instead of ld"
19+
LD="gcc"
20+
fi
21+
}
22+
23+
target_all(){
24+
target_configure
25+
info "Building mod_udp."
26+
require_directory $OBJ_DIR
27+
require_directory $BIN_DIR
28+
require_directory $LIB_DIR
29+
for file in "${SOURCES[@]}"
30+
do
31+
exec "${CC} ${CFLAGS} ${file}.c -o ${OBJ_DIR}${file}.o"
32+
done
33+
change_dir $OBJ_DIR
34+
objects=$(printf " %s.o" "${SOURCES[@]}")
35+
exec "${LD} ${LD_FLAGS} -shared -L${BASEDIR}/${LIB_DIR} -o ${BASEDIR}/${BIN_DIR}${EXECUTABLE} ${objects} -lddos2 -lc"
36+
leave_dir
37+
success "Succesfully built mod_udp."
38+
}

0 commit comments

Comments
 (0)