MAKEFLAGS += -R -r prefix := $(CURDIR) export PATH := $(prefix)/gnu/bin:$(PATH) tooldir = riscv-gnu-toolchain binutils = $(tooldir)/riscv-binutils # --disable-gdb because the gdb with riscv-gnu-toolchain seems really broken all_config = --prefix=$(prefix)/gnu --with-system-zlib z80_config = $(all_config) \ --target=z80-none-elf riscv_target_flags = -fvisibility=hidden -fno-pic -mshorten-memrefs \ -frename-registers -mdiv -mno-strict-align \ -ffunction-sections -fdata-sections riscv_config = $(all_config) \ --with-arch=rv32imc --with-abi=ilp32 \ --with-target-cflags='$(riscv_target_flags)' \ --with-target-cxxflags='$(riscv_target_flags)' \ --enable-multilib --with-multilib-generator='rv32imc-ilp32--' # The tools don't seem to build correctly without buildin rules (sigh) # There isn't even an option to cancel them, so use this hideousness # to strip out the r and R option from MAKEFLAGS. _tail = $(wordlist 2,$(words $(1)),$(1)) _strip_flags = $(if $(1),$(call _strip_flags,$(call _tail,$(1)),$(subst $(word 1,$(1)),,$(2))),$(2)) strip_flags = $(if $(findstring -,$(word 1,$(2))),$(2),$(call _strip_flags,$(1),$(word 1,$(2))) $(call _tail,$(2))) RMAKE = $(MAKE) MAKEFLAGS='$(call strip_flags,r R,$(MAKEFLAGS))' riscv_configargs := target_configargs='--enable-lite-exit --disable-newlib-register-fini' all: gnu.riscv.build gnu.z80.build clean: rm -rf *.build *~ *.bak \#* .\#* spotless: clean rm -rf gnu .PHONY: src src: [ ! -f ../../.gitmodules ] || \ git submodule update --init --recursive # Note: the riscv-gnu-toolchain repo has bugs when building in # parallel, so spoon feed it a sequence to avoid dependency problems. .PHONY: gnu.riscv.build gnu.riscv.build: src mkdir -p $@ cd $@ && $(riscv_configargs) ../$(tooldir)/configure $(riscv_config) $(RMAKE) -C $@ $(riscv_configargs) build-binutils $(RMAKE) -C $@ $(riscv_configargs) newlib .PHONY: gnu.z80.build gnu.z80.build: src mkdir -p $@ cd $@ && ../$(binutils)/configure $(z80_config) $(RMAKE) -C $@ $(RMAKE) -C $@ install