Fossil SCM

Get the -MJ ... flags working for the in-binary objects and generate the top-level compile_commands.json.

stephan 2023-06-18 15:37 compile_commands.json
Commit e330509cd4b02a979c5efe4739db307930a65e14b9f745994a7cf0637f1c70b5
2 files changed +32 -18 +32 -18
+32 -18
--- src/main.mk
+++ src/main.mk
@@ -569,20 +569,10 @@
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
-
584574
all: $(OBJDIR) $(APPNAME)
585575
586576
install: all
587577
mkdir -p $(INSTALLDIR)
588578
cp $(APPNAME) $(INSTALLDIR)
@@ -2137,21 +2127,44 @@
21372127
wasm: $(SRCDIR_extsrc)/pikchr.js
21382128
21392129
#
21402130
# compile_commands.json support...
21412131
#
2142
-compile-commands-file = $(TOPDIR)/$(compile-commands-dir)/$(@F:.o=.o.json)
2143
-compile-command-args.yes = -MJ $(compile-commands-file)
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)
21442144
compile-command-args.no =
2145
-CFLAGS += $(compile-command-args.$(MAKE_COMPILATION_DB))
2146
-compile_commands.json:
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)
21472157
@-rm -f $@
2148
- sed -e '1s/^/[\'$$'\n''/' -e '$$s/,$$/\'$$'\n'']/' $(compile-commands-dir)/*.o.json > $@+
2158
+ sed -e '1s/^/[''\n''/' -e '$$s/,$$/''\n'']/' $(compile-commands-dir)/*.o.json > $@+
21492159
@if test -s $@+; then mv $@+ $@; else rm -f $@+; fi
21502160
compile-commands.no:
2151
-compile-commands.yes: compile_commands.json
2152
-all: $(compile-commands.$(MAKE_COMPILATION_DB))
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)
21532166
21542167
#
21552168
# End compile_commands.json support
21562169
#
21572170
@@ -2158,7 +2171,8 @@
21582171
#
21592172
# The list of all the targets that do not correspond to real files. This stops
21602173
# 'make' from getting confused when someone makes an error in a rule.
21612174
#
21622175
2163
-.PHONY: all install test clean compile-commands-no compile-commands-yes
2176
+.PHONY: all install test clean
2177
+.PHONY: compile-commands-clean compile-commands-dir
21642178
21652179
--- src/main.mk
+++ src/main.mk
@@ -569,20 +569,10 @@
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)
@@ -2137,21 +2127,44 @@
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,7 +2171,8 @@
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
--- src/main.mk
+++ src/main.mk
@@ -569,20 +569,10 @@
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)
@@ -2137,21 +2127,44 @@
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 sed -e '1s/^/[''\n''/' -e '$$s/,$$/''\n'']/' $(compile-commands-dir)/*.o.json > $@+
2159 @if test -s $@+; then mv $@+ $@; else rm -f $@+; fi
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
@@ -2158,7 +2171,8 @@
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
+32 -18
--- tools/makemake.tcl
+++ tools/makemake.tcl
@@ -359,20 +359,10 @@
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
-}
374364
375365
writeln [string map [list \
376366
<<<SQLITE_OPTIONS>>> [join $SQLITE_OPTIONS " \\\n "] \
377367
<<<SHELL_OPTIONS>>> [join $SHELL_OPTIONS " \\\n "] \
378368
<<<PIKCHR_OPTIONS>>> [join $PIKCHR_OPTIONS " \\\n "] \
@@ -587,21 +577,44 @@
587577
wasm: $(SRCDIR_extsrc)/pikchr.js
588578
589579
#
590580
# compile_commands.json support...
591581
#
592
-compile-commands-file = $(TOPDIR)/$(compile-commands-dir)/$(@F:.o=.o.json)
593
-compile-command-args.yes = -MJ $(compile-commands-file)
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)
594594
compile-command-args.no =
595
-CFLAGS += $(compile-command-args.$(MAKE_COMPILATION_DB))
596
-compile_commands.json:
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)
597607
@-rm -f $@
598
- sed -e '1s/^/[\'$$'\n''/' -e '$$s/,$$/\'$$'\n'']/' $(compile-commands-dir)/*.o.json > $@+
608
+ sed -e '1s/^/[''\n''/' -e '$$s/,$$/''\n'']/' $(compile-commands-dir)/*.o.json > $@+
599609
@if test -s $@+; then mv $@+ $@; else rm -f $@+; fi
600610
compile-commands.no:
601
-compile-commands.yes: compile_commands.json
602
-all: $(compile-commands.$(MAKE_COMPILATION_DB))
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)
603616
604617
#
605618
# End compile_commands.json support
606619
#
607620
@@ -608,11 +621,12 @@
608621
#
609622
# The list of all the targets that do not correspond to real files. This stops
610623
# 'make' from getting confused when someone makes an error in a rule.
611624
#
612625
613
-.PHONY: all install test clean compile-commands-no compile-commands-yes
626
+.PHONY: all install test clean
627
+.PHONY: compile-commands-clean compile-commands-dir
614628
}]
615629
616630
close $output_file
617631
#
618632
# End of the main.mk output
619633
--- tools/makemake.tcl
+++ tools/makemake.tcl
@@ -359,20 +359,10 @@
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 "] \
@@ -587,21 +577,44 @@
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,11 +621,12 @@
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
613 .PHONY: all install test clean compile-commands-no compile-commands-yes
 
614 }]
615
616 close $output_file
617 #
618 # End of the main.mk output
619
--- tools/makemake.tcl
+++ tools/makemake.tcl
@@ -359,20 +359,10 @@
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 "] \
@@ -587,21 +577,44 @@
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 sed -e '1s/^/[''\n''/' -e '$$s/,$$/''\n'']/' $(compile-commands-dir)/*.o.json > $@+
609 @if test -s $@+; then mv $@+ $@; else rm -f $@+; fi
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
@@ -608,11 +621,12 @@
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