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+ # Define the list of modules
60+ modules=" bitcoin_core rust_bitcoin rust_miniscript btcd embit lnd ldk nlightning"
61+
62+ # Full clean: runs `make clean` in all module directories
63+ full_clean () {
64+ echo " Performing full clean..."
65+ for module in $modules ; do
66+ $module " make clean"
67+ done
68+ }
69+
70+ # Clean based on CXXFLAGS
71+ clean_selected_by_cxxflags () {
72+ echo " Performing clean based on CXXFLAGS=$CXXFLAGS ..."
73+ for module in $modules ; do
74+ module_name=$( echo " $module " | tr ' [:lower:]' ' [:upper:]' )
75+ if echo " $CXXFLAGS " | grep -q " $module_name " ; then
76+ $module " make clean"
77+ fi
78+ done
79+ }
80+
81+ # Selective clean based on CLEAN_BUILD flags
82+ select_clean () {
83+ echo " Performing selective clean based on CLEAN_BUILD=$CLEAN_BUILD ..."
84+ for module in $modules ; do
85+ module_name=$( echo " $module " | tr ' [:lower:]' ' [:upper:]' )
86+ if echo " $CLEAN_BUILD " | grep -q " $module_name " ; then
87+ $module " make clean"
88+ fi
89+ done
90+ }
91+
92+ # Determine which clean to perform
93+ if [ -n " $CLEAN_BUILD " ]; then
94+ case " $CLEAN_BUILD " in
95+ FULL)
96+ full_clean
97+ ;;
98+ CLEAN)
99+ clean_selected_by_cxxflags
100+ ;;
101+ * )
102+ select_clean
103+ ;;
104+ esac
105+ else
106+ echo " No CLEAN_BUILD option specified. Skipping clean step."
107+ fi
108+
109+ # Builds modules based on flags
110+ echo " Compiling selected modules with CXXFLAGS=$CXXFLAGS ..."
111+
112+ for module in $modules ; do
113+ module_name=$( echo " $module " | tr ' [:lower:]' ' [:upper:]' )
114+ if echo " $CXXFLAGS " | grep -q " $module_name " ; then
115+ case " $module " in
116+ rust_bitcoin|rust_miniscript|ldk)
117+ $module " rustup default nightly && make cargo && make"
118+ ;;
119+ * )
120+ $module " make"
121+ ;;
122+ esac
123+ fi
124+ done
125+
126+ # Returns to the root and performs the final build of the project
127+ echo " Compiling the main project in the root..."
128+ make || { echo " Error: Failed to compile the main project" ; exit 1; }
129+
130+ echo " Build completed successfully!"
0 commit comments