Fossil SCM

Initial *incomplete* attempt at integrating compile_commands.json support, for code editors which support it. This is a copy/paste port from the libfossil tree, but lacks one final piece which is difficult to emulate in POSIX make (as opposed to GNU make). Build file changes only, no code changes.

stephan 2023-06-18 11:16 trunk
Commit 492787465dd7ebd6f3da7097e17ba5a8515daa18dcc195e6166aa1dfea9e2c8a
--- Makefile.in
+++ Makefile.in
@@ -83,10 +83,14 @@
8383
# https://emscripten.org/docs/getting_started/downloads.html
8484
EMSDK_HOME = @EMSDK_HOME@
8585
EMSDK_ENV = @EMSDK_ENV@
8686
EMCC_OPT = @EMCC_OPT@
8787
EMCC_WRAPPER = $(SRCDIR_tools)/emcc.sh
88
+
89
+# MAKE_COMPILATION_DB (yes/no) determines whether or not the
90
+# compile_commands.json file will be generated.
91
+MAKE_COMPILATION_DB = @MAKE_COMPILATION_DB@
8892
8993
.PHONY: all tags
9094
9195
include $(SRCDIR)/main.mk
9296
9397
--- Makefile.in
+++ Makefile.in
@@ -83,10 +83,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
@@ -83,10 +83,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 # MAKE_COMPILATION_DB (yes/no) determines whether or not the
90 # compile_commands.json file will be generated.
91 MAKE_COMPILATION_DB = @MAKE_COMPILATION_DB@
92
93 .PHONY: all tags
94
95 include $(SRCDIR)/main.mk
96
97
+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
+26 -2
--- src/main.mk
+++ src/main.mk
@@ -2115,21 +2115,45 @@
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
+compile-commands-no:
2130
+compile-commands-yes: compile_commands.json
2131
+all: compile-commands-$(MAKE_COMPILATION_DB)
2132
+compile-commands-args-no =
2133
+compile-commands-args-yes = -MJ $(compile-commands-file)
2134
+compile-commands-args = compile-commands-args-$(MAKE_COMPILATION_DB)
2135
+compile-commands-dir = compile_commands
2136
+compile-commands-mkdir = $(SRCDIR)/$(compile-commands-dir)
2137
+CFLAGS += $(compile-commands-args)
2138
+$(compile-commands-mkdir): $(compile-commands-dir)
2139
+ mkdir -p $@
2140
+compile_commands.json: $(compile-commands-mkdir)
2141
+ @-rm -f $@
2142
+ sed -e '1s/^/[\'$$'\n''/' -e '$$s/,$$/\'$$'\n'']/' $(compile-commands-dir)/*.o.json > $@+
2143
+ @if test -s $@+; then mv $@+ $@; else rm -f $@+; fi
2144
+
2145
+# We don't (yet?) have a way to replicate this part of the
2146
+# compile_commands.json build in posix make unless we generate
2147
+# separate build rules for the compile-commands case:
2148
+#
2149
+# compdb_file = $(TOP_SRCDIR_REL)/$(compdb_dir)/$(subst /,-,[email protected])
2150
+# compdb_args = -MJ $(compdb_file)
2151
+# CFLAGS += $(compdb_args)
2152
+
21292153
#
21302154
# The list of all the targets that do not correspond to real files. This stops
21312155
# 'make' from getting confused when someone makes an error in a rule.
21322156
#
21332157
2134
-.PHONY: all install test clean
2158
+.PHONY: all install test clean compile-commands-no compile-commands-yes
21352159
21362160
--- src/main.mk
+++ src/main.mk
@@ -2115,21 +2115,45 @@
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,45 @@
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 compile-commands-no:
2130 compile-commands-yes: compile_commands.json
2131 all: compile-commands-$(MAKE_COMPILATION_DB)
2132 compile-commands-args-no =
2133 compile-commands-args-yes = -MJ $(compile-commands-file)
2134 compile-commands-args = compile-commands-args-$(MAKE_COMPILATION_DB)
2135 compile-commands-dir = compile_commands
2136 compile-commands-mkdir = $(SRCDIR)/$(compile-commands-dir)
2137 CFLAGS += $(compile-commands-args)
2138 $(compile-commands-mkdir): $(compile-commands-dir)
2139 mkdir -p $@
2140 compile_commands.json: $(compile-commands-mkdir)
2141 @-rm -f $@
2142 sed -e '1s/^/[\'$$'\n''/' -e '$$s/,$$/\'$$'\n'']/' $(compile-commands-dir)/*.o.json > $@+
2143 @if test -s $@+; then mv $@+ $@; else rm -f $@+; fi
2144
2145 # We don't (yet?) have a way to replicate this part of the
2146 # compile_commands.json build in posix make unless we generate
2147 # separate build rules for the compile-commands case:
2148 #
2149 # compdb_file = $(TOP_SRCDIR_REL)/$(compdb_dir)/$(subst /,-,[email protected])
2150 # compdb_args = -MJ $(compdb_file)
2151 # CFLAGS += $(compdb_args)
2152
2153 #
2154 # The list of all the targets that do not correspond to real files. This stops
2155 # 'make' from getting confused when someone makes an error in a rule.
2156 #
2157
2158 .PHONY: all install test clean compile-commands-no compile-commands-yes
2159
2160
--- tools/makemake.tcl
+++ tools/makemake.tcl
@@ -574,16 +574,40 @@
574574
-sEXPORT_NAME=initPikchrModule <<<NEXT_LINE>>>
575575
--minify 0
576576
@chmod -x $(SRCDIR_extsrc)/pikchr.wasm
577577
wasm: $(SRCDIR_extsrc)/pikchr.js
578578
579
+compile-commands-no:
580
+compile-commands-yes: compile_commands.json
581
+all: compile-commands-$(MAKE_COMPILATION_DB)
582
+compile-commands-args-no =
583
+compile-commands-args-yes = -MJ $(compile-commands-file)
584
+compile-commands-args = compile-commands-args-$(MAKE_COMPILATION_DB)
585
+compile-commands-dir = compile_commands
586
+compile-commands-mkdir = $(SRCDIR)/$(compile-commands-dir)
587
+CFLAGS += $(compile-commands-args)
588
+$(compile-commands-mkdir): $(compile-commands-dir)
589
+ mkdir -p $@
590
+compile_commands.json: $(compile-commands-mkdir)
591
+ @-rm -f $@
592
+ sed -e '1s/^/[\'$$'\n''/' -e '$$s/,$$/\'$$'\n'']/' $(compile-commands-dir)/*.o.json > $@+
593
+ @if test -s $@+; then mv $@+ $@; else rm -f $@+; fi
594
+
595
+# We don't (yet?) have a way to replicate this part of the
596
+# compile_commands.json build in posix make unless we generate
597
+# separate build rules for the compile-commands case:
598
+#
599
+# compdb_file = $(TOP_SRCDIR_REL)/$(compdb_dir)/$(subst /,-,[email protected])
600
+# compdb_args = -MJ $(compdb_file)
601
+# CFLAGS += $(compdb_args)
602
+
579603
#
580604
# The list of all the targets that do not correspond to real files. This stops
581605
# 'make' from getting confused when someone makes an error in a rule.
582606
#
583607
584
-.PHONY: all install test clean
608
+.PHONY: all install test clean compile-commands-no compile-commands-yes
585609
}]
586610
587611
close $output_file
588612
#
589613
# End of the main.mk output
590614
--- tools/makemake.tcl
+++ tools/makemake.tcl
@@ -574,16 +574,40 @@
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,40 @@
574 -sEXPORT_NAME=initPikchrModule <<<NEXT_LINE>>>
575 --minify 0
576 @chmod -x $(SRCDIR_extsrc)/pikchr.wasm
577 wasm: $(SRCDIR_extsrc)/pikchr.js
578
579 compile-commands-no:
580 compile-commands-yes: compile_commands.json
581 all: compile-commands-$(MAKE_COMPILATION_DB)
582 compile-commands-args-no =
583 compile-commands-args-yes = -MJ $(compile-commands-file)
584 compile-commands-args = compile-commands-args-$(MAKE_COMPILATION_DB)
585 compile-commands-dir = compile_commands
586 compile-commands-mkdir = $(SRCDIR)/$(compile-commands-dir)
587 CFLAGS += $(compile-commands-args)
588 $(compile-commands-mkdir): $(compile-commands-dir)
589 mkdir -p $@
590 compile_commands.json: $(compile-commands-mkdir)
591 @-rm -f $@
592 sed -e '1s/^/[\'$$'\n''/' -e '$$s/,$$/\'$$'\n'']/' $(compile-commands-dir)/*.o.json > $@+
593 @if test -s $@+; then mv $@+ $@; else rm -f $@+; fi
594
595 # We don't (yet?) have a way to replicate this part of the
596 # compile_commands.json build in posix make unless we generate
597 # separate build rules for the compile-commands case:
598 #
599 # compdb_file = $(TOP_SRCDIR_REL)/$(compdb_dir)/$(subst /,-,[email protected])
600 # compdb_args = -MJ $(compdb_file)
601 # CFLAGS += $(compdb_args)
602
603 #
604 # The list of all the targets that do not correspond to real files. This stops
605 # 'make' from getting confused when someone makes an error in a rule.
606 #
607
608 .PHONY: all install test clean compile-commands-no compile-commands-yes
609 }]
610
611 close $output_file
612 #
613 # End of the main.mk output
614

Keyboard Shortcuts

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