Skip to content

Commit 9b060bf

Browse files
committed
Download jq for generating compile_commands.json on macOS.
1 parent 81820b3 commit 9b060bf

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

Makefile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ BOTAN_PKG ?= $(call pkg-select-ab,botan-3,botan-2)
2727
CAPSTONE_PKG ?= capstone
2828
JANSSON_PKG ?= jansson
2929
LUA_PKG ?= $(call pkg-select-ab,lua5.3,lua)
30+
JQ ?= jq
3031

3132
EXE ?= rehex
3233
EMBED_EXE ?= ./tools/embed
@@ -717,17 +718,17 @@ wxLua/%.cpp: $(WXLUA_BINDINGS)
717718
# The compile_commands.json fragment for each file is written out under .cc/ and then merged into
718719
# the top-level compile_commands.json, all are rebuilt when the Makefile(s) are changed.
719720

720-
COMPILE_COMMAND_DEPENDENCIES := $(wildcard Makefile Makefile.*)
721+
COMPILE_COMMAND_DEPENDENCIES := $(wildcard Makefile Makefile.*) $(JQ)
721722
COMPILE_COMMAND_INTERMEDIATE_DIR := .cc
722723

723724
.PHONY: compile_commands.json
724725
compile_commands.json: $(addprefix $(COMPILE_COMMAND_INTERMEDIATE_DIR)/,$(addsuffix .compile_command.json,$(APP_OBJS) $(TEST_OBJS)))
725-
cat $^ | jq -s . > $@
726+
cat $^ | $(JQ) -s . > $@
726727

727728
# $(call emit-compile-command,$(COMPILE_COMMAND_INTERMEDIATE_DIR)/foo.o.compile_command.json,foo.c,$(CC) $(CFLAGS))
728729
define emit-compile-command
729730
@mkdir -p $(dir $(1))
730-
echo "{ \"directory\": $$(pwd | jq -R .), \"file\": $$(echo "$(patsubst $(COMPILE_COMMAND_INTERMEDIATE_DIR)/%,%,$(patsubst %.compile_command.json,%,$(2)))" | jq -R .), \"command\": $$(echo "$(3) -o $(2) $(patsubst $(COMPILE_COMMAND_INTERMEDIATE_DIR)/%,%,$(patsubst %.compile_command.json,%,$(2)))" | jq -R .) }" > $(1)
731+
echo "{ \"directory\": $$(pwd | $(JQ) -R .), \"file\": $$(echo "$(patsubst $(COMPILE_COMMAND_INTERMEDIATE_DIR)/%,%,$(patsubst %.compile_command.json,%,$(2)))" | $(JQ) -R .), \"command\": $$(echo "$(3) -o $(2) $(patsubst $(COMPILE_COMMAND_INTERMEDIATE_DIR)/%,%,$(patsubst %.compile_command.json,%,$(2)))" | $(JQ) -R .) }" > $(1)
731732
endef
732733

733734
$(COMPILE_COMMAND_INTERMEDIATE_DIR)/googletest/src/%.o.compile_command.json: googletest/src/%.cc $(GTKCONFIG_EXE) $(COMPILE_COMMAND_DEPENDENCIES)
@@ -751,6 +752,9 @@ $(COMPILE_COMMAND_INTERMEDIATE_DIR)/%.o.compile_command.json: %.cpp $(GTKCONFIG_
751752
$(COMPILE_COMMAND_INTERMEDIATE_DIR)/%.$(BUILD_TYPE).o.compile_command.json: %.cpp $(GTKCONFIG_EXE) $(COMPILE_COMMAND_DEPENDENCIES)
752753
$(call emit-compile-command,$@,$<,$(CXX) $(CXXFLAGS))
753754

755+
# Dummy rule for jq on platforms where we rely on a system-provided binary.
756+
jq:
757+
754758
.PHONY: help/rehex.chm
755759
help/rehex.chm:
756760
$(MAKE) -C help/ rehex.chm

Makefile.osx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ LUA_LIBS ?= -llua
5353

5454
all: REHex.app
5555

56+
JQ := .cc/jq
57+
5658
include Makefile
5759

5860
src/mainwindow.$(BUILD_TYPE).o: res/backward32.h res/document_new32.h res/document_open32.h res/document_save32.h res/document_save_as32.h res/forward32.h
@@ -112,3 +114,21 @@ REHex.dmg: REHex.app
112114
$(DEPPRE)
113115
$(CXX) $(CXXFLAGS) $(DEPFLAGS) -c -o $@ $<
114116
$(DEPPOST)
117+
118+
$(COMPILE_COMMAND_INTERMEDIATE_DIR)/%.o.compile_command.json: $(JQ) %.mm $(COMPILE_COMMAND_DEPENDENCIES)
119+
$(call emit-compile-command,$@,$<,$(CXX) $(CXXFLAGS))
120+
121+
.cc/jq:
122+
mkdir -p .cc
123+
if [ "$$(uname -m)" = "x86_64" ]; \
124+
then \
125+
curl -L https://github.com/jqlang/jq/releases/latest/download/jq-macos-amd64 > .cc/jq.tmp \
126+
&& chmod 0755 .cc/jq.tmp \
127+
&& .cc/jq.tmp --version > /dev/null \
128+
&& mv .cc/jq.tmp .cc/jq; \
129+
else \
130+
curl -L https://github.com/jqlang/jq/releases/latest/download/jq-macos-arm64 > .cc/jq.tmp \
131+
&& chmod 0755 .cc/jq.tmp \
132+
&& .cc/jq.tmp --version > /dev/null \
133+
&& mv .cc/jq.tmp .cc/jq; \
134+
fi

0 commit comments

Comments
 (0)