Skip to content

Commit 7da78a3

Browse files
build: add auto_build.sh for modular compilation with optional clean
This script automates the build process based on CXXFLAGS-defined modules. It also offers an option to clean previous builds before compiling.
1 parent ad6f82a commit 7da78a3

File tree

1 file changed

+138
-0
lines changed

1 file changed

+138
-0
lines changed

auto_build.sh

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
#!/bin/bash
2+
3+
if [ -z "$CXXFLAGS" ]; then
4+
echo "Error: CXXFLAGS not defined. Example: CXXFLAGS=\"-DLDK -DLND\" ./auto_build.sh"
5+
exit 1
6+
fi
7+
8+
# Runs make clean to clean everything before starting
9+
echo "Cleaning previous builds..."
10+
make clean || { echo "Error: 'make clean' failed"; exit 1; }
11+
12+
# Function to execute a command in a module's directory
13+
execute_in_module() {
14+
local module_dir=$1
15+
local command=$2
16+
17+
if [ -d "$module_dir" ]; then
18+
echo "Executing in $module_dir: $command"
19+
(cd "$module_dir" && eval "$command") || { echo "Error: Failed to execute in $module_dir"; exit 1; }
20+
else
21+
echo "Error: Directory $module_dir does not exist"
22+
exit 1
23+
fi
24+
}
25+
26+
# Functions for each module
27+
bitcoin_core() {
28+
execute_in_module "modules/bitcoin" "$1"
29+
}
30+
31+
rust_bitcoin() {
32+
execute_in_module "modules/rustbitcoin" "$1"
33+
}
34+
35+
rust_miniscript() {
36+
execute_in_module "modules/rustminiscript" "$1"
37+
}
38+
39+
btcd() {
40+
execute_in_module "modules/btcd" "$1"
41+
}
42+
43+
embit() {
44+
execute_in_module "modules/embit" "$1"
45+
}
46+
47+
lnd() {
48+
execute_in_module "modules/lnd" "$1"
49+
}
50+
51+
ldk() {
52+
execute_in_module "modules/ldk" "$1"
53+
}
54+
55+
nlightning() {
56+
execute_in_module "modules/nlightning" "$1"
57+
}
58+
59+
clightning() {
60+
execute_in_module "modules/clightning" "$1"
61+
}
62+
63+
custom_mutator_bolt11() {
64+
execute_in_module "modules/bolt11mutator" "$1"
65+
}
66+
67+
# Define the list of modules
68+
modules="bitcoin_core rust_bitcoin rust_miniscript btcd embit lnd ldk nlightning clightning custom_mutator_bolt11"
69+
70+
# Full clean: runs `make clean` in all module directories
71+
full_clean() {
72+
echo "Performing full clean..."
73+
for module in $modules; do
74+
$module "make clean"
75+
done
76+
}
77+
78+
# Clean based on CXXFLAGS
79+
clean_selected_by_cxxflags() {
80+
echo "Performing clean based on CXXFLAGS=$CXXFLAGS..."
81+
for module in $modules; do
82+
module_name=$(echo "$module" | tr '[:lower:]' '[:upper:]')
83+
if echo "$CXXFLAGS" | grep -q "$module_name"; then
84+
$module "make clean"
85+
fi
86+
done
87+
}
88+
89+
# Selective clean based on CLEAN_BUILD flags
90+
select_clean() {
91+
echo "Performing selective clean based on CLEAN_BUILD=$CLEAN_BUILD..."
92+
for module in $modules; do
93+
module_name=$(echo "$module" | tr '[:lower:]' '[:upper:]')
94+
if echo "$CLEAN_BUILD" | grep -q "$module_name"; then
95+
$module "make clean"
96+
fi
97+
done
98+
}
99+
100+
# Determine which clean to perform
101+
if [ -n "$CLEAN_BUILD" ]; then
102+
case "$CLEAN_BUILD" in
103+
FULL)
104+
full_clean
105+
;;
106+
CLEAN)
107+
clean_selected_by_cxxflags
108+
;;
109+
*)
110+
select_clean
111+
;;
112+
esac
113+
else
114+
echo "No CLEAN_BUILD option specified. Skipping clean step."
115+
fi
116+
117+
# Builds modules based on flags
118+
echo "Compiling selected modules with CXXFLAGS=$CXXFLAGS..."
119+
120+
for module in $modules; do
121+
module_name=$(echo "$module" | tr '[:lower:]' '[:upper:]')
122+
if echo "$CXXFLAGS" | grep -q "$module_name"; then
123+
case "$module" in
124+
rust_bitcoin|rust_miniscript|ldk)
125+
$module "rustup default nightly && make cargo && make"
126+
;;
127+
*)
128+
$module "make"
129+
;;
130+
esac
131+
fi
132+
done
133+
134+
# Returns to the root and performs the final build of the project
135+
echo "Compiling the main project in the root..."
136+
make || { echo "Error: Failed to compile the main project"; exit 1; }
137+
138+
echo "Build completed successfully!"

0 commit comments

Comments
 (0)