Fossil SCM

merge build system compilation database generation Tested on OpenBSD 7.3-current and macOS Ventura 13.4 by me, and also on some Linux machines by stephan@ This automatically generates a compile_commands.json file on machines that support the -MJ clang compiler option, which can be consumed by language server clients.

mark 2023-06-22 08:46 trunk merge
Commit 91f0f00f5df1622760eff5e8a68de1cc72c6abc67ba57efdcb1cbb07514daf62
--- Makefile.in
+++ Makefile.in
@@ -7,10 +7,11 @@
77
#### The toplevel directory of the source tree. Fossil can be built
88
# in a directory that is separate from the source tree. Just change
99
# the following to point from the build directory to the src/ folder.
1010
#
1111
SRCDIR = @srcdir@/src
12
+TOPDIR = @srcdir@
1213
#### Upstream source files included directly in this repository.
1314
#
1415
SRCDIR_extsrc = @srcdir@/extsrc
1516
#### In-tree tools such as code generators and translators:
1617
#
@@ -83,10 +84,14 @@
8384
# https://emscripten.org/docs/getting_started/downloads.html
8485
EMSDK_HOME = @EMSDK_HOME@
8586
EMSDK_ENV = @EMSDK_ENV@
8687
EMCC_OPT = @EMCC_OPT@
8788
EMCC_WRAPPER = $(SRCDIR_tools)/emcc.sh
89
+
90
+# MAKE_COMPILATION_DB (yes/no) determines whether or not the
91
+# compile_commands.json file will be generated.
92
+MAKE_COMPILATION_DB = @MAKE_COMPILATION_DB@
8893
8994
.PHONY: all tags
9095
9196
include $(SRCDIR)/main.mk
9297
9398
--- Makefile.in
+++ Makefile.in
@@ -7,10 +7,11 @@
7 #### The toplevel directory of the source tree. Fossil can be built
8 # in a directory that is separate from the source tree. Just change
9 # the following to point from the build directory to the src/ folder.
10 #
11 SRCDIR = @srcdir@/src
 
12 #### Upstream source files included directly in this repository.
13 #
14 SRCDIR_extsrc = @srcdir@/extsrc
15 #### In-tree tools such as code generators and translators:
16 #
@@ -83,10 +84,14 @@
83 # https://emscripten.org/docs/getting_started/downloads.html
84 EMSDK_HOME = @EMSDK_HOME@
85 EMSDK_ENV = @EMSDK_ENV@
86 EMCC_OPT = @EMCC_OPT@
87 EMCC_WRAPPER = $(SRCDIR_tools)/emcc.sh
 
 
 
 
88
89 .PHONY: all tags
90
91 include $(SRCDIR)/main.mk
92
93
--- Makefile.in
+++ Makefile.in
@@ -7,10 +7,11 @@
7 #### The toplevel directory of the source tree. Fossil can be built
8 # in a directory that is separate from the source tree. Just change
9 # the following to point from the build directory to the src/ folder.
10 #
11 SRCDIR = @srcdir@/src
12 TOPDIR = @srcdir@
13 #### Upstream source files included directly in this repository.
14 #
15 SRCDIR_extsrc = @srcdir@/extsrc
16 #### In-tree tools such as code generators and translators:
17 #
@@ -83,10 +84,14 @@
84 # https://emscripten.org/docs/getting_started/downloads.html
85 EMSDK_HOME = @EMSDK_HOME@
86 EMSDK_ENV = @EMSDK_ENV@
87 EMCC_OPT = @EMCC_OPT@
88 EMCC_WRAPPER = $(SRCDIR_tools)/emcc.sh
89
90 # MAKE_COMPILATION_DB (yes/no) determines whether or not the
91 # compile_commands.json file will be generated.
92 MAKE_COMPILATION_DB = @MAKE_COMPILATION_DB@
93
94 .PHONY: all tags
95
96 include $(SRCDIR)/main.mk
97
98
+32
--- auto.def
+++ auto.def
@@ -29,10 +29,12 @@
2929
fusefs=1 => {Disable the Fuse Filesystem}
3030
fossil-debug=0 => {Build with fossil debugging enabled}
3131
no-opt=0 => {Build without optimization}
3232
json=0 => {Build with fossil JSON API enabled}
3333
with-emsdk:path => {Directory containing the Emscripten SDK}
34
+ no-compile-commands=0 =>
35
+ "Disable compile_commands.json support even if detected (possibly incorrectly)."
3436
}
3537
3638
# Update the minimum required SQLite version number here, and also
3739
# in src/main.c near the sqlite3_libversion_number() call. Take care
3840
# that both places agree!
@@ -729,10 +731,40 @@
729731
define FOSSIL_HAVE_FUSEFS 1
730732
define-append LIBS -lfuse
731733
msg-result "FuseFS support enabled"
732734
}
733735
}
736
+
737
+########################################################################
738
+# Checks the compiler for compile_commands.json support. If passed an
739
+# argument it is assumed to be the name of an autosetup boolean config
740
+# option to explicitly DISABLE the compile_commands.json support.
741
+#
742
+# Returns 1 if supported, else 0. Defines MAKE_COMPILATION_DB to "yes"
743
+# if supported, "no" if not.
744
+proc check-compile-commands {{configOpt no-compile-commands}} {
745
+ msg-checking "compile_commands.json support... "
746
+ if {"" ne $configOpt && [opt-bool $configOpt]} {
747
+ msg-result "explicitly disabled"
748
+ define MAKE_COMPILATION_DB no
749
+ return 0
750
+ } else {
751
+ if {[cctest -lang c -cflags {/dev/null -MJ} -source {}]} {
752
+ # This test reportedly incorrectly succeeds on one of
753
+ # Martin G.'s older systems.
754
+ msg-result "compiler supports compile_commands.json"
755
+ define MAKE_COMPILATION_DB yes
756
+ return 1
757
+ } else {
758
+ msg-result "compiler does not support compile_commands.json"
759
+ define MAKE_COMPILATION_DB no
760
+ return 0
761
+ }
762
+ }
763
+}
764
+
765
+check-compile-commands
734766
735767
# Add -fsanitize compile and link options late: we don't want the C
736768
# checks above to run with those sanitizers enabled. It can not only
737769
# be pointless, it can actually break correct tests.
738770
set fsan [opt-val with-sanitizer]
739771
--- auto.def
+++ auto.def
@@ -29,10 +29,12 @@
29 fusefs=1 => {Disable the Fuse Filesystem}
30 fossil-debug=0 => {Build with fossil debugging enabled}
31 no-opt=0 => {Build without optimization}
32 json=0 => {Build with fossil JSON API enabled}
33 with-emsdk:path => {Directory containing the Emscripten SDK}
 
 
34 }
35
36 # Update the minimum required SQLite version number here, and also
37 # in src/main.c near the sqlite3_libversion_number() call. Take care
38 # that both places agree!
@@ -729,10 +731,40 @@
729 define FOSSIL_HAVE_FUSEFS 1
730 define-append LIBS -lfuse
731 msg-result "FuseFS support enabled"
732 }
733 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
734
735 # Add -fsanitize compile and link options late: we don't want the C
736 # checks above to run with those sanitizers enabled. It can not only
737 # be pointless, it can actually break correct tests.
738 set fsan [opt-val with-sanitizer]
739
--- auto.def
+++ auto.def
@@ -29,10 +29,12 @@
29 fusefs=1 => {Disable the Fuse Filesystem}
30 fossil-debug=0 => {Build with fossil debugging enabled}
31 no-opt=0 => {Build without optimization}
32 json=0 => {Build with fossil JSON API enabled}
33 with-emsdk:path => {Directory containing the Emscripten SDK}
34 no-compile-commands=0 =>
35 "Disable compile_commands.json support even if detected (possibly incorrectly)."
36 }
37
38 # Update the minimum required SQLite version number here, and also
39 # in src/main.c near the sqlite3_libversion_number() call. Take care
40 # that both places agree!
@@ -729,10 +731,40 @@
731 define FOSSIL_HAVE_FUSEFS 1
732 define-append LIBS -lfuse
733 msg-result "FuseFS support enabled"
734 }
735 }
736
737 ########################################################################
738 # Checks the compiler for compile_commands.json support. If passed an
739 # argument it is assumed to be the name of an autosetup boolean config
740 # option to explicitly DISABLE the compile_commands.json support.
741 #
742 # Returns 1 if supported, else 0. Defines MAKE_COMPILATION_DB to "yes"
743 # if supported, "no" if not.
744 proc check-compile-commands {{configOpt no-compile-commands}} {
745 msg-checking "compile_commands.json support... "
746 if {"" ne $configOpt && [opt-bool $configOpt]} {
747 msg-result "explicitly disabled"
748 define MAKE_COMPILATION_DB no
749 return 0
750 } else {
751 if {[cctest -lang c -cflags {/dev/null -MJ} -source {}]} {
752 # This test reportedly incorrectly succeeds on one of
753 # Martin G.'s older systems.
754 msg-result "compiler supports compile_commands.json"
755 define MAKE_COMPILATION_DB yes
756 return 1
757 } else {
758 msg-result "compiler does not support compile_commands.json"
759 define MAKE_COMPILATION_DB no
760 return 0
761 }
762 }
763 }
764
765 check-compile-commands
766
767 # Add -fsanitize compile and link options late: we don't want the C
768 # checks above to run with those sanitizers enabled. It can not only
769 # be pointless, it can actually break correct tests.
770 set fsan [opt-val with-sanitizer]
771
+44 -1
--- src/main.mk
+++ src/main.mk
@@ -2115,21 +2115,64 @@
21152115
$(OBJDIR)/cson_amalgamation.o: $(SRCDIR_extsrc)/cson_amalgamation.c
21162116
$(XTCC) -c $(SRCDIR_extsrc)/cson_amalgamation.c -o $@
21172117
21182118
$(SRCDIR_extsrc)/pikchr.js: $(SRCDIR_extsrc)/pikchr.c
21192119
$(EMCC_WRAPPER) -o $@ $(EMCC_OPT) --no-entry \
2120
- -sEXPORTED_RUNTIME_METHODS=cwrap,setValue,getValue,stackSave,stackRestore,stackAlloc \
2120
+ -sEXPORTED_RUNTIME_METHODS=cwrap,setValue,getValue,stackSave,stackRestore \
21212121
-sEXPORTED_FUNCTIONS=_pikchr $(SRCDIR_extsrc)/pikchr.c \
21222122
-sENVIRONMENT=web \
21232123
-sMODULARIZE \
21242124
-sEXPORT_NAME=initPikchrModule \
21252125
--minify 0
21262126
@chmod -x $(SRCDIR_extsrc)/pikchr.wasm
21272127
wasm: $(SRCDIR_extsrc)/pikchr.js
21282128
2129
+#
2130
+# compile_commands.json support...
2131
+#
2132
+# We have to avoid applying compile_commands support to the in-tree
2133
+# tools, as those compile with BCC, which may differ from TCC.
2134
+# e.g. BCC might be gcc (which does not support -MJ ...) while TCC is
2135
+# clang (which does).
2136
+#
2137
+# What follows is more verbose than strictly necessary because we're
2138
+# limited to POSIX make syntax.
2139
+all:
2140
+compile-commands-dir.yes = $(OBJDIR)
2141
+compile-commands-dir.no =
2142
+compile-commands-dir = $(compile-commands-dir.$(MAKE_COMPILATION_DB))
2143
+compile-command-args.yes = -MJ $(TOPDIR)/$(compile-commands-dir)/$(@F:.o=.o.json)
2144
+compile-command-args.no =
2145
+TCCFLAGS += $(compile-command-args.$(MAKE_COMPILATION_DB))
2146
+compile_commands.json = $(TOPDIR)/compile_commands.json
2147
+# compile_commands.json is a concatenation of the .o.json files
2148
+# generated by the compilation process via TCCFLAGS. We have a
2149
+# potential race condition in parallel builds, where a .o.json file is
2150
+# not yet written to completion before compile_commands.json is
2151
+# processed. How to resolve that in a way compatible with POSIX make
2152
+# is unclear.
2153
+#
2154
+# This obscure sed bit ensures that the resulting JSON array does not
2155
+# have a trailing comma.
2156
+$(compile_commands.json): $(OBJ)
2157
+ @-rm -f $@
2158
+ @{ echo '['; cat $(compile-commands-dir)/*.o.json | tr '\n' ' ' | sed -e 's/, $$//'; echo ']'; } > $@
2159
+ @echo "Generated $@"
2160
+compile-commands.no:
2161
+compile-commands.yes: $(compile_commands.json)
2162
+all: compile-commands.$(MAKE_COMPILATION_DB)
2163
+clean: compile-commands-clean
2164
+compile-commands-clean:
2165
+ rm -fr $(compile_commands.json)
2166
+
2167
+#
2168
+# End compile_commands.json support
2169
+#
2170
+
21292171
#
21302172
# The list of all the targets that do not correspond to real files. This stops
21312173
# 'make' from getting confused when someone makes an error in a rule.
21322174
#
21332175
21342176
.PHONY: all install test clean
2177
+.PHONY: compile-commands-clean compile-commands-dir
21352178
21362179
--- src/main.mk
+++ src/main.mk
@@ -2115,21 +2115,64 @@
2115 $(OBJDIR)/cson_amalgamation.o: $(SRCDIR_extsrc)/cson_amalgamation.c
2116 $(XTCC) -c $(SRCDIR_extsrc)/cson_amalgamation.c -o $@
2117
2118 $(SRCDIR_extsrc)/pikchr.js: $(SRCDIR_extsrc)/pikchr.c
2119 $(EMCC_WRAPPER) -o $@ $(EMCC_OPT) --no-entry \
2120 -sEXPORTED_RUNTIME_METHODS=cwrap,setValue,getValue,stackSave,stackRestore,stackAlloc \
2121 -sEXPORTED_FUNCTIONS=_pikchr $(SRCDIR_extsrc)/pikchr.c \
2122 -sENVIRONMENT=web \
2123 -sMODULARIZE \
2124 -sEXPORT_NAME=initPikchrModule \
2125 --minify 0
2126 @chmod -x $(SRCDIR_extsrc)/pikchr.wasm
2127 wasm: $(SRCDIR_extsrc)/pikchr.js
2128
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2129 #
2130 # The list of all the targets that do not correspond to real files. This stops
2131 # 'make' from getting confused when someone makes an error in a rule.
2132 #
2133
2134 .PHONY: all install test clean
 
2135
2136
--- src/main.mk
+++ src/main.mk
@@ -2115,21 +2115,64 @@
2115 $(OBJDIR)/cson_amalgamation.o: $(SRCDIR_extsrc)/cson_amalgamation.c
2116 $(XTCC) -c $(SRCDIR_extsrc)/cson_amalgamation.c -o $@
2117
2118 $(SRCDIR_extsrc)/pikchr.js: $(SRCDIR_extsrc)/pikchr.c
2119 $(EMCC_WRAPPER) -o $@ $(EMCC_OPT) --no-entry \
2120 -sEXPORTED_RUNTIME_METHODS=cwrap,setValue,getValue,stackSave,stackRestore \
2121 -sEXPORTED_FUNCTIONS=_pikchr $(SRCDIR_extsrc)/pikchr.c \
2122 -sENVIRONMENT=web \
2123 -sMODULARIZE \
2124 -sEXPORT_NAME=initPikchrModule \
2125 --minify 0
2126 @chmod -x $(SRCDIR_extsrc)/pikchr.wasm
2127 wasm: $(SRCDIR_extsrc)/pikchr.js
2128
2129 #
2130 # compile_commands.json support...
2131 #
2132 # We have to avoid applying compile_commands support to the in-tree
2133 # tools, as those compile with BCC, which may differ from TCC.
2134 # e.g. BCC might be gcc (which does not support -MJ ...) while TCC is
2135 # clang (which does).
2136 #
2137 # What follows is more verbose than strictly necessary because we're
2138 # limited to POSIX make syntax.
2139 all:
2140 compile-commands-dir.yes = $(OBJDIR)
2141 compile-commands-dir.no =
2142 compile-commands-dir = $(compile-commands-dir.$(MAKE_COMPILATION_DB))
2143 compile-command-args.yes = -MJ $(TOPDIR)/$(compile-commands-dir)/$(@F:.o=.o.json)
2144 compile-command-args.no =
2145 TCCFLAGS += $(compile-command-args.$(MAKE_COMPILATION_DB))
2146 compile_commands.json = $(TOPDIR)/compile_commands.json
2147 # compile_commands.json is a concatenation of the .o.json files
2148 # generated by the compilation process via TCCFLAGS. We have a
2149 # potential race condition in parallel builds, where a .o.json file is
2150 # not yet written to completion before compile_commands.json is
2151 # processed. How to resolve that in a way compatible with POSIX make
2152 # is unclear.
2153 #
2154 # This obscure sed bit ensures that the resulting JSON array does not
2155 # have a trailing comma.
2156 $(compile_commands.json): $(OBJ)
2157 @-rm -f $@
2158 @{ echo '['; cat $(compile-commands-dir)/*.o.json | tr '\n' ' ' | sed -e 's/, $$//'; echo ']'; } > $@
2159 @echo "Generated $@"
2160 compile-commands.no:
2161 compile-commands.yes: $(compile_commands.json)
2162 all: compile-commands.$(MAKE_COMPILATION_DB)
2163 clean: compile-commands-clean
2164 compile-commands-clean:
2165 rm -fr $(compile_commands.json)
2166
2167 #
2168 # End compile_commands.json support
2169 #
2170
2171 #
2172 # The list of all the targets that do not correspond to real files. This stops
2173 # 'make' from getting confused when someone makes an error in a rule.
2174 #
2175
2176 .PHONY: all install test clean
2177 .PHONY: compile-commands-clean compile-commands-dir
2178
2179
--- tools/makemake.tcl
+++ tools/makemake.tcl
@@ -574,16 +574,59 @@
574574
-sEXPORT_NAME=initPikchrModule <<<NEXT_LINE>>>
575575
--minify 0
576576
@chmod -x $(SRCDIR_extsrc)/pikchr.wasm
577577
wasm: $(SRCDIR_extsrc)/pikchr.js
578578
579
+#
580
+# compile_commands.json support...
581
+#
582
+# We have to avoid applying compile_commands support to the in-tree
583
+# tools, as those compile with BCC, which may differ from TCC.
584
+# e.g. BCC might be gcc (which does not support -MJ ...) while TCC is
585
+# clang (which does).
586
+#
587
+# What follows is more verbose than strictly necessary because we're
588
+# limited to POSIX make syntax.
589
+all:
590
+compile-commands-dir.yes = $(OBJDIR)
591
+compile-commands-dir.no =
592
+compile-commands-dir = $(compile-commands-dir.$(MAKE_COMPILATION_DB))
593
+compile-command-args.yes = -MJ $(TOPDIR)/$(compile-commands-dir)/$(@F:.o=.o.json)
594
+compile-command-args.no =
595
+TCCFLAGS += $(compile-command-args.$(MAKE_COMPILATION_DB))
596
+compile_commands.json = $(TOPDIR)/compile_commands.json
597
+# compile_commands.json is a concatenation of the .o.json files
598
+# generated by the compilation process via TCCFLAGS. We have a
599
+# potential race condition in parallel builds, where a .o.json file is
600
+# not yet written to completion before compile_commands.json is
601
+# processed. How to resolve that in a way compatible with POSIX make
602
+# is unclear.
603
+#
604
+# This obscure sed bit ensures that the resulting JSON array does not
605
+# have a trailing comma.
606
+$(compile_commands.json): $(OBJ)
607
+ @-rm -f $@
608
+ @{ echo '['; cat $(compile-commands-dir)/*.o.json | tr '\n' ' ' | sed -e 's/, $$//'; echo ']'; } > $@
609
+ @echo "Generated $@"
610
+compile-commands.no:
611
+compile-commands.yes: $(compile_commands.json)
612
+all: compile-commands.$(MAKE_COMPILATION_DB)
613
+clean: compile-commands-clean
614
+compile-commands-clean:
615
+ rm -fr $(compile_commands.json)
616
+
617
+#
618
+# End compile_commands.json support
619
+#
620
+
579621
#
580622
# The list of all the targets that do not correspond to real files. This stops
581623
# 'make' from getting confused when someone makes an error in a rule.
582624
#
583625
584626
.PHONY: all install test clean
627
+.PHONY: compile-commands-clean compile-commands-dir
585628
}]
586629
587630
close $output_file
588631
#
589632
# End of the main.mk output
590633
--- tools/makemake.tcl
+++ tools/makemake.tcl
@@ -574,16 +574,59 @@
574 -sEXPORT_NAME=initPikchrModule <<<NEXT_LINE>>>
575 --minify 0
576 @chmod -x $(SRCDIR_extsrc)/pikchr.wasm
577 wasm: $(SRCDIR_extsrc)/pikchr.js
578
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
579 #
580 # The list of all the targets that do not correspond to real files. This stops
581 # 'make' from getting confused when someone makes an error in a rule.
582 #
583
584 .PHONY: all install test clean
 
585 }]
586
587 close $output_file
588 #
589 # End of the main.mk output
590
--- tools/makemake.tcl
+++ tools/makemake.tcl
@@ -574,16 +574,59 @@
574 -sEXPORT_NAME=initPikchrModule <<<NEXT_LINE>>>
575 --minify 0
576 @chmod -x $(SRCDIR_extsrc)/pikchr.wasm
577 wasm: $(SRCDIR_extsrc)/pikchr.js
578
579 #
580 # compile_commands.json support...
581 #
582 # We have to avoid applying compile_commands support to the in-tree
583 # tools, as those compile with BCC, which may differ from TCC.
584 # e.g. BCC might be gcc (which does not support -MJ ...) while TCC is
585 # clang (which does).
586 #
587 # What follows is more verbose than strictly necessary because we're
588 # limited to POSIX make syntax.
589 all:
590 compile-commands-dir.yes = $(OBJDIR)
591 compile-commands-dir.no =
592 compile-commands-dir = $(compile-commands-dir.$(MAKE_COMPILATION_DB))
593 compile-command-args.yes = -MJ $(TOPDIR)/$(compile-commands-dir)/$(@F:.o=.o.json)
594 compile-command-args.no =
595 TCCFLAGS += $(compile-command-args.$(MAKE_COMPILATION_DB))
596 compile_commands.json = $(TOPDIR)/compile_commands.json
597 # compile_commands.json is a concatenation of the .o.json files
598 # generated by the compilation process via TCCFLAGS. We have a
599 # potential race condition in parallel builds, where a .o.json file is
600 # not yet written to completion before compile_commands.json is
601 # processed. How to resolve that in a way compatible with POSIX make
602 # is unclear.
603 #
604 # This obscure sed bit ensures that the resulting JSON array does not
605 # have a trailing comma.
606 $(compile_commands.json): $(OBJ)
607 @-rm -f $@
608 @{ echo '['; cat $(compile-commands-dir)/*.o.json | tr '\n' ' ' | sed -e 's/, $$//'; echo ']'; } > $@
609 @echo "Generated $@"
610 compile-commands.no:
611 compile-commands.yes: $(compile_commands.json)
612 all: compile-commands.$(MAKE_COMPILATION_DB)
613 clean: compile-commands-clean
614 compile-commands-clean:
615 rm -fr $(compile_commands.json)
616
617 #
618 # End compile_commands.json support
619 #
620
621 #
622 # The list of all the targets that do not correspond to real files. This stops
623 # 'make' from getting confused when someone makes an error in a rule.
624 #
625
626 .PHONY: all install test clean
627 .PHONY: compile-commands-clean compile-commands-dir
628 }]
629
630 close $output_file
631 #
632 # End of the main.mk output
633

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button