20
20
#
21
21
22
22
HERE=` dirname $0 `
23
+ PATH=" $HERE :$PATH "
23
24
24
- . " $HERE / mfutil"
25
+ . mfutil
25
26
26
27
GITREPO=https://github.com/MarlinFirmware/Configurations.git
27
28
STAT_FILE=./.pio/.buildall
@@ -55,7 +56,7 @@ LIMIT=1000
55
56
while getopts ' aB:b:ce:fdhl:no:pr:sv-:' OFLAG; do
56
57
case " ${OFLAG} " in
57
58
a) ARCHIVE=1 ; bugout " Archiving" ;;
58
- B) OPATH =${OPTARG%/ } ; bugout " Base: $OPATH " ;;
59
+ B) CBASE =${OPTARG%/ } ; bugout " Base: $CBASE " ;;
59
60
b) BRANCH=$OPTARG ; bugout " Branch: $BRANCH " ;;
60
61
f) NOFAIL=1 ; bugout " Continue on Fail" ;;
61
62
r) ISRES=1 ; FIRST_CONF=$OPTARG ; bugout " Resume: $FIRST_CONF " ;;
@@ -71,7 +72,7 @@ while getopts 'aB:b:ce:fdhl:no:pr:sv-:' OFLAG; do
71
72
-) ONAM=" ${OPTARG%% =* } " ; OVAL=" ${OPTARG#* =} "
72
73
case " $ONAM " in
73
74
archive) ARCHIVE=1 ; bugout " Archiving" ;;
74
- base) OPATH =${OVAL%/ } ; bugout " Base: $OPATH " ;;
75
+ base) CBASE =${OVAL%/ } ; bugout " Base: $CBASE " ;;
75
76
branch) BRANCH=$OVAL ; bugout " Branch: $BRANCH " ;;
76
77
nofail) NOFAIL=1 ; bugout " Continue on Fail" ;;
77
78
resume) ISRES=1 ; FIRST_CONF=$OVAL ; bugout " Resume: $FIRST_CONF " ;;
@@ -131,45 +132,47 @@ else
131
132
git diff --quiet || { echo " The working copy is modified. Commit or stash changes before proceeding." ; exit ; }
132
133
fi
133
134
134
- # Create a temporary folder inside .pio
135
- if [[ -n $OPATH ]]; then
136
- [[ -d " $OPATH " ]] || { echo " Given base -B $OPATH not found." ; exit ; }
135
+ # Check for the given base path
136
+ if [[ -n $CBASE ]]; then
137
+ CBASE=" ${CBASE/# \~ / $HOME } "
138
+ [[ -d " $CBASE " ]] || { echo " Given base -B $CBASE not found." ; exit ; }
137
139
else
138
140
# Make a Configurations temporary folder if needed
139
- OPATH =./.pio/build-$BRANCH
140
- [[ -d " $OPATH " ]] || mkdir -p " $OPATH "
141
+ CBASE =./.pio/build-$BRANCH
142
+ [[ -d " $CBASE " ]] || mkdir -p " $CBASE "
141
143
# Download the specified Configurations branch if needed
142
- if [[ ! -e " $OPATH /README.md" ]]; then
143
- echo " Fetching Configurations from GitHub to $OPATH "
144
- git clone --depth=1 --single-branch --branch " $BRANCH " $GITREPO " $OPATH " || { echo " Failed to clone the configuration repository" ; exit ; }
144
+ if [[ ! -e " $CBASE /README.md" ]]; then
145
+ echo " Fetching Configurations from GitHub to $CBASE "
146
+ git clone --depth=1 --single-branch --branch " $BRANCH " $GITREPO " $CBASE " || { echo " Failed to clone the configuration repository" ; exit ; }
145
147
fi
146
148
fi
147
149
148
150
# Build
149
151
echo -e " =====================\nProceed with builds...\n====================="
150
152
shopt -s nullglob
151
- shopt -s globstar
152
- IFS='
153
- '
154
- CONF_TREE=$( ls -d " $OPATH " /config/examples/** / | grep -vE " .+\.(\w+)$" )
155
- for CONF in $CONF_TREE ; do
153
+
154
+ # Get a list of all folders that contain a file matching "Configuration*.h"
155
+ find -ds " $CBASE " /config/examples -type d -name ' Configuration.h' -o -name ' Configuration_adv.h' -print0 | while IFS= read -r -d ' ' CONF; do
156
+
157
+ # Remove the file name and slash from the end of the path
158
+ CONF=${CONF%/* }
156
159
157
160
# Get a config's directory name
158
- DIR=${CONF# $OPATH / config/ examples/ }
161
+ DIR=${CONF# $CBASE / config/ examples/ }
159
162
160
163
# If looking for a config, skip others
161
- [[ $FIRST_CONF ]] && [[ $FIRST_CONF != $DIR && " $FIRST_CONF /" != $DIR ]] && continue
164
+ [[ $FIRST_CONF ]] && [[ $FIRST_CONF != $DIR && " $FIRST_CONF /" != $DIR ]] && { (( DEBUG )) && echo " [SKIP] $DIR " ; continue ; }
162
165
# Once found, stop looking
163
166
unset FIRST_CONF
164
167
165
168
# If skipping, don't build the found one
166
169
[[ $SKIP_CONF ]] && { unset SKIP_CONF ; continue ; }
167
170
168
- # At least one config file is required here
169
- compgen -G " ${ CONF} Configuration*.h " > /dev/null || continue
171
+ # Either Configuration.h or Configuration_adv.h must exist
172
+ [[ -f " $CONF " / Configuration.h || -f " $CONF " /Configuration_adv.h ]] || { echo " [NONE] $DIR " ; continue ; }
170
173
171
174
# Command arguments for 'build_example'
172
- CARGS=(" -b" " $OPATH " " -c" " $DIR " )
175
+ CARGS=(" -b" " $CBASE " " -c" " $DIR " )
173
176
174
177
# Exporting? Add -e argument
175
178
(( CEXPORT)) && CARGS+=(" -e" " $CEXPORT " )
@@ -189,16 +192,16 @@ for CONF in $CONF_TREE ; do
189
192
else
190
193
# Remember where we are in case of failure
191
194
echo " ${BRANCH} *${DIR} " > " $STAT_FILE "
192
- (( DEBUG)) && echo " \" $HERE / build_example\" ${CARGS[@]} "
195
+ (( DEBUG)) && echo " build_example ${CARGS[@]} "
193
196
# Invoke build_example
194
- " $HERE " / build_example " ${CARGS[@]} " || { echo " Failed to build $DIR " ; exit ; }
197
+ build_example " ${CARGS[@]} " || { echo " Failed to build $DIR " ; exit ; }
195
198
fi
196
199
197
- (( -- LIMIT )) || { echo " Limit reached " ; PAUSE=1 ; break ; }
198
-
199
- echo ; echo
200
+ echo
201
+ (( -- LIMIT )) || { echo " Specified limit reached " ; PAUSE=1 ; break ; }
202
+ echo
200
203
201
204
done
202
205
203
206
# Delete the build state if not paused early
204
- [[ $PAUSE ]] || rm " $STAT_FILE "
207
+ [[ $PAUSE ]] || rm -f " $STAT_FILE "
0 commit comments