11include mk/common.mk
22include mk/toolchain.mk
33
4+ # Verify GNU make version (3.80+ required for order-only prerequisites)
5+ ifeq ($(filter 3.80 3.81 3.82 3.83 3.84 4.% 5.% ,$(MAKE_VERSION ) ) ,)
6+ $(error GNU make 3.80 or higher is required. Current version : $(MAKE_VERSION ) )
7+ endif
8+
49OUT ?= build
510BIN := $(OUT ) /rv32emu
611
4651# Device Tree(initrd, memory range)
4752# src/io.c(memory init)
4853# src/riscv.c(system emulation layout init)
54+ # Note: These memory settings are for SYSTEM mode only (when ELF_LOADER=0)
4955ifeq ($(call has, SYSTEM) , 1)
5056ifeq ($(call has, ELF_LOADER) , 0)
5157MiB = 1024*1024
@@ -66,6 +72,7 @@ CFLAGS_dt += -DMEM_START=0x$(MEM_START) \
6672 -DINITRD_END=0x$(shell echo "obase=16; ibase=16; \
6773 $(REAL_MEM_SIZE ) - $(call compute_size, $(DTB_SIZE ) ) - 1" | bc)
6874
75+ # Memory size for SYSTEM mode (may be overridden by FULL4G if ENABLE_ELF_LOADER=1)
6976CFLAGS += -DMEM_SIZE=0x$(REAL_MEM_SIZE ) -DDTB_SIZE=0x$(REAL_DTB_SIZE ) -DINITRD_SIZE=0x$(REAL_INITRD_SIZE )
7077endif
7178endif
@@ -192,27 +199,35 @@ ENABLE_FULL4G ?= 0
192199
193200# Experimental SDL oriented system calls
194201ENABLE_SDL ?= 1
202+ ENABLE_SDL_MIXER ?= 1
195203ifneq ("$(CC_IS_EMCC ) ", "1") # note that emcc generates port SDL headers/library, so it does not requires system SDL headers/library
196204ifeq ($(call has, SDL) , 1)
197205ifeq (, $(shell which sdl2-config) )
198206$(warning No sdl2-config in $$PATH. Check SDL2 installation in advance)
199207override ENABLE_SDL := 0
200208endif
201209ifeq (1, $(shell pkg-config --exists SDL2_mixer; echo $$? ) )
202- $(warning No SDL2_mixer lib installed. Check SDL2_mixer installation in advance)
203- override ENABLE_SDL := 0
210+ $(warning No SDL2_mixer lib installed. SDL2_mixer support will be disabled)
211+ override ENABLE_SDL_MIXER := 0
212+ endif
204213endif
205214endif
206215$(call set-feature, SDL)
216+ $(call set-feature, SDL_MIXER)
207217ifeq ($(call has, SDL) , 1)
208218OBJS_EXT += syscall_sdl.o
219+ ifneq ("$(CC_IS_EMCC ) ", "1")
209220$(OUT ) /syscall_sdl.o : CFLAGS += $(shell sdl2-config --cflags)
221+ endif
210222# 4 GiB of memory is required to run video games.
211223ENABLE_FULL4G := 1
224+ ifneq ("$(CC_IS_EMCC ) ", "1")
212225LDFLAGS += $(shell sdl2-config --libs) -pthread
226+ ifeq ($(call has, SDL_MIXER) , 1)
213227LDFLAGS += $(shell pkg-config --libs SDL2_mixer)
214228endif
215229endif
230+ endif
216231
217232# If SYSTEM is enabled and ELF_LOADER is not, then skip FULL4G bacause guestOS
218233# has dedicated memory mapping range.
@@ -225,7 +240,22 @@ endif
225240# Full access to a 4 GiB address space, necessitating more memory mapping
226241# during emulator initialization.
227242$(call set-feature, FULL4G)
243+
244+ # Configuration validation and conflict detection
245+ ifeq ($(call has, SDL) , 1)
246+ ifeq ($(call has, SYSTEM) , 1)
247+ ifeq ($(call has, ELF_LOADER) , 0)
248+ ifeq ($(call has, FULL4G) , 0)
249+ $(warning SDL requires FULL4G=1 but SYSTEM forces FULL4G=0. Set ENABLE_ELF_LOADER=1 or disable SDL/SYSTEM)
250+ endif
251+ endif
252+ endif
253+ endif
254+
228255ifeq ($(call has, FULL4G) , 1)
256+ # Note: If both SYSTEM and FULL4G are enabled with ELF_LOADER=1,
257+ # this MEM_SIZE definition will override the SYSTEM mode definition.
258+ # This is intentional for ELF loader use cases.
229259CFLAGS += -DMEM_SIZE=0xFFFFFFFFULL # 2^{32} - 1
230260endif
231261
@@ -278,6 +308,8 @@ ifeq ($(call has, JIT), 1)
278308 else
279309 $(error No llvm-config-18 installed. Check llvm-config-18 installation in advance, or use "ENABLE_T2C=0" to disable tier-2 LLVM compiler)
280310 endif
311+ else
312+ $(warning T2C (tier-2 compiler) is disabled. Using tier-1 JIT only.)
281313 endif
282314 ifneq ($(processor),$(filter $(processor),x86_64 aarch64 arm64))
283315 $(error JIT mode only supports for x64 and arm64 target currently.)
@@ -318,7 +350,7 @@ DTB_DEPS := $(BUILD_DTB) $(BUILD_DTB2C)
318350endif
319351endif
320352
321- all : config $(DTB_DEPS ) $(BIN )
353+ all : config $(DTB_DEPS ) $(BUILD_DTB ) $( BUILD_DTB2C ) $( BIN )
322354
323355OBJS := \
324356 map.o \
@@ -353,19 +385,31 @@ ifeq ($(call has, GDBSTUB), 1)
353385$(OBJS ) : $(GDBSTUB_LIB )
354386endif
355387
356- $(OUT ) /% .o : src/% .c $(deps_emcc )
357- $(Q ) mkdir -p $(shell dirname $@ )
388+ $(OUT ) /% .o : src/% .c $(CONFIG_FILE ) $( deps_emcc ) | $( OUT )
389+ $(Q ) mkdir -p $(dir $@ )
358390 $(VECHO ) " CC\t$@ \n"
359391 $(Q )$(CC ) -o $@ $(CFLAGS ) $(CFLAGS_emcc ) -c -MMD -MF $@ .d $<
360392
361- $(BIN ) : $(OBJS ) $(DEV_OBJS )
393+ $(OUT ) :
394+ $(Q ) mkdir -p $@
395+
396+ $(BIN ) : $(OBJS ) $(DEV_OBJS ) | $(OUT )
362397 $(VECHO ) " LD\t$@ \n"
363398 $(Q )$(CC ) -o $@ $(CFLAGS_emcc ) $^ $(LDFLAGS )
364399
400+ $(CONFIG_FILE ) : FORCE
401+ $(Q ) mkdir -p $(OUT )
402+ $(Q ) echo " $( CFLAGS) " | xargs -n1 | sort | sed -n ' s/^RV32_FEATURE/ENABLE/p' > $@ .tmp
403+ $(Q ) if ! cmp -s $@ $@ .tmp 2> /dev/null; then \
404+ mv $@ .tmp $@ ; \
405+ $(PRINTF ) " Configuration updated. Check $( OUT) /.config for configured items.\n" ; \
406+ else \
407+ $(RM ) $@ .tmp; \
408+ fi
409+
410+ .PHONY : FORCE config
411+ FORCE :
365412config : $(CONFIG_FILE )
366- $(CONFIG_FILE ) :
367- $(Q ) echo " $( CFLAGS) " | xargs -n1 | sort | sed -n ' s/^RV32_FEATURE/ENABLE/p' > $@
368- $(VECHO ) " Check the file $( OUT) /.config for configured items.\n"
369413
370414# Tools
371415include mk/tools.mk
@@ -460,4 +504,7 @@ distclean: clean
460504 $(Q ) -$(RM ) -r $(SOFTFLOAT_DUMMY_PLAT ) $(OUT ) /softfloat
461505 $(Q )$(call notice, [OK])
462506
507+ .PHONY : all config tool check check-hello misalign misalign-in-blk-emu mmu-test
508+ .PHONY : gdbstub-test doom quake clean distclean artifact
509+
463510-include $(deps )
0 commit comments