Skip to content

Commit 23234ea

Browse files
authored
Prevent make all from thinking it needs to run twice (#443)
The dependencies/ordering of the building of the .bc files were subtly incorrect. This meant that running `make clean` followed by `make build` would work, but then the next time `make build` was run, the whole build would erroneously run again, rather than detecting everything was up to date. In particular, the 'out/sqlite3.bc' file would get built, and THEN the extensions would get built. However, when the extensions got built, only then would it copy the extensions.c file into the sqlite-src/amalgamation folder, thus updating that the sqlite-src/amalgamation folder timestamp. The next time `make` was run, `out/sqlite3.bc` would detect that the `sqlite-src/amalgamation` folder was newer than the sqlite3.bc file, and it would get rebuilt, thus cascading into a full rebuild.
1 parent fed1af8 commit 23234ea

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

Makefile

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,10 @@ out/sqlite3.bc: sqlite-src/$(SQLITE_AMALGAMATION)
149149
# Generate llvm bitcode
150150
$(EMCC) $(CFLAGS) -c sqlite-src/$(SQLITE_AMALGAMATION)/sqlite3.c -o $@
151151

152-
out/extension-functions.bc: sqlite-src/$(SQLITE_AMALGAMATION)/$(EXTENSION_FUNCTIONS)
152+
# Since the extension-functions.c includes other headers in the sqlite_amalgamation, we declare that this depends on more than just extension-functions.c
153+
out/extension-functions.bc: sqlite-src/$(SQLITE_AMALGAMATION)
153154
mkdir -p out
155+
# Generate llvm bitcode
154156
$(EMCC) $(CFLAGS) -s LINKABLE=1 -c sqlite-src/$(SQLITE_AMALGAMATION)/extension-functions.c -o $@
155157

156158
# TODO: This target appears to be unused. If we re-instatate it, we'll need to add more files inside of the JS folder
@@ -168,18 +170,20 @@ cache/$(EXTENSION_FUNCTIONS):
168170

169171
## sqlite-src
170172
.PHONY: sqlite-src
171-
sqlite-src: sqlite-src/$(SQLITE_AMALGAMATION) sqlite-src/$(EXTENSION_FUNCTIONS)
173+
sqlite-src: sqlite-src/$(SQLITE_AMALGAMATION) sqlite-src/$(SQLITE_AMALGAMATION)/$(EXTENSION_FUNCTIONS)
172174

173-
sqlite-src/$(SQLITE_AMALGAMATION): cache/$(SQLITE_AMALGAMATION).zip
174-
mkdir -p sqlite-src
175+
sqlite-src/$(SQLITE_AMALGAMATION): cache/$(SQLITE_AMALGAMATION).zip sqlite-src/$(SQLITE_AMALGAMATION)/$(EXTENSION_FUNCTIONS)
176+
mkdir -p sqlite-src/$(SQLITE_AMALGAMATION)
175177
echo '$(SQLITE_AMALGAMATION_ZIP_SHA1) ./cache/$(SQLITE_AMALGAMATION).zip' > cache/check.txt
176178
sha1sum -c cache/check.txt
177-
rm -rf $@
179+
# We don't delete the sqlite_amalgamation folder. That's a job for clean
180+
# Also, the extension functions get copied here, and if we get the order of these steps wrong,
181+
# this step could remove the extension functions, and that's not what we want
178182
unzip -u 'cache/$(SQLITE_AMALGAMATION).zip' -d sqlite-src/
179183
touch $@
180184

181185
sqlite-src/$(SQLITE_AMALGAMATION)/$(EXTENSION_FUNCTIONS): cache/$(EXTENSION_FUNCTIONS)
182-
mkdir -p sqlite-src
186+
mkdir -p sqlite-src/$(SQLITE_AMALGAMATION)
183187
echo '$(EXTENSION_FUNCTIONS_SHA1) ./cache/$(EXTENSION_FUNCTIONS)' > cache/check.txt
184188
sha1sum -c cache/check.txt
185189
cp 'cache/$(EXTENSION_FUNCTIONS)' $@
@@ -188,5 +192,4 @@ sqlite-src/$(SQLITE_AMALGAMATION)/$(EXTENSION_FUNCTIONS): cache/$(EXTENSION_FUNC
188192
.PHONY: clean
189193
clean:
190194
rm -f out/* dist/* cache/*
191-
rm -rf sqlite-src/ c/
192-
195+
rm -rf sqlite-src/

0 commit comments

Comments
 (0)