Browse Source

tools: build a z80-none-elf binutils, riscv-gdb

Build a z80-none-elf toolchain (currently just binutils) as well as
the riscv one; use the same binutils sources as riscv.

The reason the gdb build failed for riscv was the make -R -r issue; so
re-enable it.
H. Peter Anvin 3 years ago
parent
commit
3f417a182e
1 changed files with 39 additions and 22 deletions
  1. 39 22
      tools/Makefile

+ 39 - 22
tools/Makefile

@@ -1,20 +1,26 @@
 MAKEFLAGS += -R -r
 
-CROSS     = riscv32-unknown-elf-
 prefix   := $(CURDIR)
-target_flags = -fvisibility=hidden -fno-pic -mshorten-memrefs \
-	       -frename-registers -mdiv -mno-strict-align \
-	       -ffunction-sections -fdata-sections
+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
-config    = --prefix=$(prefix)/gnu \
+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='$(target_flags)' \
-	    --with-target-cxxflags='$(target_flags)' \
-	    --with-system-zlib \
-	    --disable-gdb \
+	    --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)
@@ -26,22 +32,33 @@ strip_flags  = $(if $(findstring -,$(word 1,$(2))),$(2),$(call _strip_flags,$(1)
 
 RMAKE = $(MAKE) MAKEFLAGS='$(call strip_flags,r R,$(MAKEFLAGS))'
 
-export target_configargs := --enable-lite-exit --disable-newlib-register-fini
-
-export PATH := $(prefix)/gnu/bin:$(PATH)
+riscv_configargs := target_configargs='--enable-lite-exit --disable-newlib-register-fini'
 
-all: gnu
+all: gnu.riscv.build gnu.z80.build
 
 clean:
-	rm -rf gnu *.build
+	rm -rf *.build *~ *.bak \#* .\#*
 
-# Note: the riscv-gnu-toolchain repo has bugs when building in
-# parallel, so spoon feed it a sequence to avoid dependency problems.
-.PHONY: gnu
-gnu:
+spotless: clean
+	rm -rf gnu
+
+.PHONY: src
+src:
 	[ ! -f ../../.gitmodules ] || \
 		git submodule update --init --recursive
-	mkdir -p gnu.build
-	cd gnu.build && ../$(tooldir)/configure $(config)
-	$(RMAKE) -C gnu.build build-binutils
-	$(RMAKE) -C gnu.build newlib
+
+# 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