Fossil SCM

More work on compile_commands.json support. This does not work because the approach of extending CFLAGS with the -MJ flag is incompatible with the build process's use of different compilers for the in-tree tools vs the files compiled as part of the fossil binary. On systems with both gcc and clang, the former group may get built with cc (==gcc) yet inherit -MJ via CFLAGS, breaking the build. This approach appears to be a dead end, but checking it in for later analysis.

stephan 2023-06-18 13:58 compile_commands.json
Commit 0e6ad145d480dc3ff4bb37e30de11471bebbd870a41b965cd0732cb9c2e8be6b
--- 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
#
1718
--- 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 #
17
--- 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 #
18
+25 -20
--- src/main.mk
+++ src/main.mk
@@ -569,10 +569,20 @@
569569
$(OBJDIR)/winfile.o \
570570
$(OBJDIR)/winhttp.o \
571571
$(OBJDIR)/xfer.o \
572572
$(OBJDIR)/xfersetup.o \
573573
$(OBJDIR)/zip.o
574
+compile-commands-dir = compile_commands
575
+compile-commands-mkdir.yes = $(TOPDIR)/$(compile-commands-dir)
576
+compile-commands-mkdir.no =
577
+all: $(compile-commands-mkdir.$(MAKE_COMPILATION_DB))
578
+$(compile-commands-mkdir.no):
579
+$(compile-commands-mkdir.yes): $(compile-commands-dir)
580
+ mkdir -p $@
581
+#$(OBJ): $(compile-commands-mkdir)
582
+
583
+
574584
all: $(OBJDIR) $(APPNAME)
575585
576586
install: all
577587
mkdir -p $(INSTALLDIR)
578588
cp $(APPNAME) $(INSTALLDIR)
@@ -2124,36 +2134,31 @@
21242134
-sEXPORT_NAME=initPikchrModule \
21252135
--minify 0
21262136
@chmod -x $(SRCDIR_extsrc)/pikchr.wasm
21272137
wasm: $(SRCDIR_extsrc)/pikchr.js
21282138
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)
2139
+#
2140
+# compile_commands.json support...
2141
+#
2142
+compile-commands-file = $(TOPDIR)/$(compile-commands-dir)/$(@F:.o=.o.json)
2143
+compile-command-args.yes = -MJ $(compile-commands-file)
2144
+compile-command-args.no =
2145
+CFLAGS += $(compile-command-args.$(MAKE_COMPILATION_DB))
2146
+compile_commands.json:
21412147
@-rm -f $@
21422148
sed -e '1s/^/[\'$$'\n''/' -e '$$s/,$$/\'$$'\n'']/' $(compile-commands-dir)/*.o.json > $@+
21432149
@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)
2150
+compile-commands.no:
2151
+compile-commands.yes: compile_commands.json
2152
+all: $(compile-commands.$(MAKE_COMPILATION_DB))
2153
+
2154
+#
2155
+# End compile_commands.json support
2156
+#
21522157
21532158
#
21542159
# The list of all the targets that do not correspond to real files. This stops
21552160
# 'make' from getting confused when someone makes an error in a rule.
21562161
#
21572162
21582163
.PHONY: all install test clean compile-commands-no compile-commands-yes
21592164
21602165
--- src/main.mk
+++ src/main.mk
@@ -569,10 +569,20 @@
569 $(OBJDIR)/winfile.o \
570 $(OBJDIR)/winhttp.o \
571 $(OBJDIR)/xfer.o \
572 $(OBJDIR)/xfersetup.o \
573 $(OBJDIR)/zip.o
 
 
 
 
 
 
 
 
 
 
574 all: $(OBJDIR) $(APPNAME)
575
576 install: all
577 mkdir -p $(INSTALLDIR)
578 cp $(APPNAME) $(INSTALLDIR)
@@ -2124,36 +2134,31 @@
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
--- src/main.mk
+++ src/main.mk
@@ -569,10 +569,20 @@
569 $(OBJDIR)/winfile.o \
570 $(OBJDIR)/winhttp.o \
571 $(OBJDIR)/xfer.o \
572 $(OBJDIR)/xfersetup.o \
573 $(OBJDIR)/zip.o
574 compile-commands-dir = compile_commands
575 compile-commands-mkdir.yes = $(TOPDIR)/$(compile-commands-dir)
576 compile-commands-mkdir.no =
577 all: $(compile-commands-mkdir.$(MAKE_COMPILATION_DB))
578 $(compile-commands-mkdir.no):
579 $(compile-commands-mkdir.yes): $(compile-commands-dir)
580 mkdir -p $@
581 #$(OBJ): $(compile-commands-mkdir)
582
583
584 all: $(OBJDIR) $(APPNAME)
585
586 install: all
587 mkdir -p $(INSTALLDIR)
588 cp $(APPNAME) $(INSTALLDIR)
@@ -2124,36 +2134,31 @@
2134 -sEXPORT_NAME=initPikchrModule \
2135 --minify 0
2136 @chmod -x $(SRCDIR_extsrc)/pikchr.wasm
2137 wasm: $(SRCDIR_extsrc)/pikchr.js
2138
2139 #
2140 # compile_commands.json support...
2141 #
2142 compile-commands-file = $(TOPDIR)/$(compile-commands-dir)/$(@F:.o=.o.json)
2143 compile-command-args.yes = -MJ $(compile-commands-file)
2144 compile-command-args.no =
2145 CFLAGS += $(compile-command-args.$(MAKE_COMPILATION_DB))
2146 compile_commands.json:
 
 
 
 
2147 @-rm -f $@
2148 sed -e '1s/^/[\'$$'\n''/' -e '$$s/,$$/\'$$'\n'']/' $(compile-commands-dir)/*.o.json > $@+
2149 @if test -s $@+; then mv $@+ $@; else rm -f $@+; fi
2150 compile-commands.no:
2151 compile-commands.yes: compile_commands.json
2152 all: $(compile-commands.$(MAKE_COMPILATION_DB))
2153
2154 #
2155 # End compile_commands.json support
2156 #
 
2157
2158 #
2159 # The list of all the targets that do not correspond to real files. This stops
2160 # 'make' from getting confused when someone makes an error in a rule.
2161 #
2162
2163 .PHONY: all install test clean compile-commands-no compile-commands-yes
2164
2165
+25 -20
--- tools/makemake.tcl
+++ tools/makemake.tcl
@@ -359,10 +359,20 @@
359359
writeln "\n"
360360
writeln -nonewline "OBJ ="
361361
foreach s [lsort $src] {
362362
writeln -nonewline " \\\n \$(OBJDIR)/$s.o"
363363
}
364
+writeln {
365
+compile-commands-dir = compile_commands
366
+compile-commands-mkdir.yes = $(TOPDIR)/$(compile-commands-dir)
367
+compile-commands-mkdir.no =
368
+all: $(compile-commands-mkdir.$(MAKE_COMPILATION_DB))
369
+$(compile-commands-mkdir.no):
370
+$(compile-commands-mkdir.yes): $(compile-commands-dir)
371
+ mkdir -p $@
372
+#$(OBJ): $(compile-commands-mkdir)
373
+}
364374
365375
writeln [string map [list \
366376
<<<SQLITE_OPTIONS>>> [join $SQLITE_OPTIONS " \\\n "] \
367377
<<<SHELL_OPTIONS>>> [join $SHELL_OPTIONS " \\\n "] \
368378
<<<PIKCHR_OPTIONS>>> [join $PIKCHR_OPTIONS " \\\n "] \
@@ -574,33 +584,28 @@
574584
-sEXPORT_NAME=initPikchrModule <<<NEXT_LINE>>>
575585
--minify 0
576586
@chmod -x $(SRCDIR_extsrc)/pikchr.wasm
577587
wasm: $(SRCDIR_extsrc)/pikchr.js
578588
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)
589
+#
590
+# compile_commands.json support...
591
+#
592
+compile-commands-file = $(TOPDIR)/$(compile-commands-dir)/$(@F:.o=.o.json)
593
+compile-command-args.yes = -MJ $(compile-commands-file)
594
+compile-command-args.no =
595
+CFLAGS += $(compile-command-args.$(MAKE_COMPILATION_DB))
596
+compile_commands.json:
591597
@-rm -f $@
592598
sed -e '1s/^/[\'$$'\n''/' -e '$$s/,$$/\'$$'\n'']/' $(compile-commands-dir)/*.o.json > $@+
593599
@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)
600
+compile-commands.no:
601
+compile-commands.yes: compile_commands.json
602
+all: $(compile-commands.$(MAKE_COMPILATION_DB))
603
+
604
+#
605
+# End compile_commands.json support
606
+#
602607
603608
#
604609
# The list of all the targets that do not correspond to real files. This stops
605610
# 'make' from getting confused when someone makes an error in a rule.
606611
#
607612
--- tools/makemake.tcl
+++ tools/makemake.tcl
@@ -359,10 +359,20 @@
359 writeln "\n"
360 writeln -nonewline "OBJ ="
361 foreach s [lsort $src] {
362 writeln -nonewline " \\\n \$(OBJDIR)/$s.o"
363 }
 
 
 
 
 
 
 
 
 
 
364
365 writeln [string map [list \
366 <<<SQLITE_OPTIONS>>> [join $SQLITE_OPTIONS " \\\n "] \
367 <<<SHELL_OPTIONS>>> [join $SHELL_OPTIONS " \\\n "] \
368 <<<PIKCHR_OPTIONS>>> [join $PIKCHR_OPTIONS " \\\n "] \
@@ -574,33 +584,28 @@
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
--- tools/makemake.tcl
+++ tools/makemake.tcl
@@ -359,10 +359,20 @@
359 writeln "\n"
360 writeln -nonewline "OBJ ="
361 foreach s [lsort $src] {
362 writeln -nonewline " \\\n \$(OBJDIR)/$s.o"
363 }
364 writeln {
365 compile-commands-dir = compile_commands
366 compile-commands-mkdir.yes = $(TOPDIR)/$(compile-commands-dir)
367 compile-commands-mkdir.no =
368 all: $(compile-commands-mkdir.$(MAKE_COMPILATION_DB))
369 $(compile-commands-mkdir.no):
370 $(compile-commands-mkdir.yes): $(compile-commands-dir)
371 mkdir -p $@
372 #$(OBJ): $(compile-commands-mkdir)
373 }
374
375 writeln [string map [list \
376 <<<SQLITE_OPTIONS>>> [join $SQLITE_OPTIONS " \\\n "] \
377 <<<SHELL_OPTIONS>>> [join $SHELL_OPTIONS " \\\n "] \
378 <<<PIKCHR_OPTIONS>>> [join $PIKCHR_OPTIONS " \\\n "] \
@@ -574,33 +584,28 @@
584 -sEXPORT_NAME=initPikchrModule <<<NEXT_LINE>>>
585 --minify 0
586 @chmod -x $(SRCDIR_extsrc)/pikchr.wasm
587 wasm: $(SRCDIR_extsrc)/pikchr.js
588
589 #
590 # compile_commands.json support...
591 #
592 compile-commands-file = $(TOPDIR)/$(compile-commands-dir)/$(@F:.o=.o.json)
593 compile-command-args.yes = -MJ $(compile-commands-file)
594 compile-command-args.no =
595 CFLAGS += $(compile-command-args.$(MAKE_COMPILATION_DB))
596 compile_commands.json:
 
 
 
 
597 @-rm -f $@
598 sed -e '1s/^/[\'$$'\n''/' -e '$$s/,$$/\'$$'\n'']/' $(compile-commands-dir)/*.o.json > $@+
599 @if test -s $@+; then mv $@+ $@; else rm -f $@+; fi
600 compile-commands.no:
601 compile-commands.yes: compile_commands.json
602 all: $(compile-commands.$(MAKE_COMPILATION_DB))
603
604 #
605 # End compile_commands.json support
606 #
 
607
608 #
609 # The list of all the targets that do not correspond to real files. This stops
610 # 'make' from getting confused when someone makes an error in a rule.
611 #
612

Keyboard Shortcuts

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