Skip to content

Commit 8477c87

Browse files
committed
Fix the build system to use qemu-user as expected
Although the previous Makefile used the TARGET_EXEC variable to store the name of an architecture-specific qemu executable, such as qemu-arm or qemu-riscv32, for compiling the stage 2 compiler of shecc, the build system didn't assign the variable correctly, causing the bootstrapping process to execute the stage 1 compiler directly. The above issue can be observed by running "make VERBOSE=1" to view all build steps: $ make VERBOSE=1 ... ... out/shecc-stage1.elf -o out/shecc-stage2.elf src/main.c ... Therefore, these changes modify Makefile and .mk files to fix this issue. After specifying the target architecture, the corresponding .mk file now assigns the TARGET_EXEC variable directly, ensuring the build system invokes qemu as expected.
1 parent 5ecfd87 commit 8477c87

File tree

3 files changed

+11
-17
lines changed

3 files changed

+11
-17
lines changed

Makefile

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ CFLAGS := -O -g \
1717
BUILD_SESSION := .session.mk
1818

1919
include mk/common.mk
20-
include mk/arm.mk
21-
include mk/riscv.mk
2220
-include $(BUILD_SESSION)
2321

2422
STAGE0 := shecc
@@ -43,11 +41,7 @@ all: config bootstrap
4341
ifeq (,$(filter $(ARCH),$(ARCHS)))
4442
$(error Support ARM and RISC-V only. Select the target with "ARCH=arm" or "ARCH=riscv")
4543
endif
46-
47-
ifneq ("$(wildcard $(PWD)/config)","")
48-
TARGET_EXEC := $($(shell head -1 config | sed 's/.*: \([^ ]*\).*/\1/')_EXEC)
49-
endif
50-
export TARGET_EXEC
44+
include mk/$(ARCH).mk
5145

5246
config:
5347
$(Q)ln -s $(PWD)/$(SRCDIR)/$(ARCH)-codegen.c $(SRCDIR)/codegen.c

mk/arm.mk

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
ifeq ($(HOST_ARCH),armv7l) # detect ARMv7-A only and assume Linux-compatible
2-
ARM_EXEC :=
2+
TARGET_EXEC :=
33
else
4-
ARM_EXEC = qemu-arm
5-
ARM_EXEC := $(shell which $(ARM_EXEC))
6-
ifndef ARM_EXEC
4+
TARGET_EXEC = qemu-arm
5+
TARGET_EXEC := $(shell which $(TARGET_EXEC))
6+
ifndef TARGET_EXEC
77
$(warning "no qemu-arm found. Please check package installation")
88
ARM_EXEC = echo WARN: unable to run
99
endif
1010
endif
1111

12-
export ARM_EXEC
12+
export TARGET_EXEC
1313

1414
arm-specific-defs = \
1515
$(Q)$(PRINTF) \

mk/riscv.mk

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
RISCV_EXEC = qemu-riscv32
2-
RISCV_EXEC := $(shell which $(RISCV_EXEC))
3-
ifndef RISCV_EXEC
1+
TARGET_EXEC = qemu-riscv32
2+
TARGET_EXEC := $(shell which $(TARGET_EXEC))
3+
ifndef TARGET_EXEC
44
$(warning "no qemu-riscv32 found. Please check package installation")
5-
RISCV_EXEC = echo WARN: unable to run
5+
TARGET_EXEC = echo WARN: unable to run
66
endif
77

8-
export RISCV_EXEC
8+
export TARGET_EXEC
99

1010
riscv-specific-defs = \
1111
$(Q)$(PRINTF) \

0 commit comments

Comments
 (0)