1# 2# make [target] - Build libraries for target, (eg make zx) 3# make clean-[target] - Clean the target (eg make clean-zx) 4# 5 6 7Z80ASM = z88dk-z80asm 8ZX7 = z88dk-zx7 9 10TARGET = am9511 cpm hbios m math16 math32 rc2014 scz180 sms vgl yaz180 z180 z80 zx zxn 11 12Z88DK_LIB := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))/../../lib/ 13 14 15.PHONY: all clean install-clean 16all: $(TARGET) 17 18clean: $(addprefix clean-,$(TARGET)) 19 @find . -name '*.err' | xargs $(RM) 20 $(RM) config_private.inc 21 22install-clean: 23 $(RM) -fr target/*/obj 24 25 26 27define config 28.PHONY: clean-$(1) 29 30# +zx/+zxn use +z80 as part of the config stage so add the dependency 31target/zx/obj/config_private.inc: lib/sccz80/z80.lib 32target/zxn/obj/config_private.inc: lib/sccz80/z80.lib 33 34# Convenience target (eg make zx to build the zx libraries) 35.PHONY: $(1) 36$(1): lib/sccz80/$(1).lib lib/sdcc_ix/$(1).lib lib/sdcc_iy/$(1).lib 37 38target/$(1)/obj/config_private.inc: target/$(1)/config.m4 39 @mkdir -p target/$(1)/obj/sccz80 target/$(1)/obj/sdcc_ix target/$(1)/obj/sdcc_iy 40 $(eval cpu := $(shell \ 41 if [ "$(1)" = "z180" ]; then \ 42 echo "-mz180"; \ 43 elif \ 44 [ "$(1)" = "scz180" ]; then \ 45 echo "-mz180"; \ 46 elif \ 47 [ "$(1)" = "yaz180" ]; then \ 48 echo "-mz180"; \ 49 elif \ 50 [ "$(1)" = "zxn" ]; then \ 51 echo "-mz80n"; \ 52 else \ 53 echo ""; \ 54 fi) ) 55 m4 -DCFG_ASM_DEF target/$(1)/config.m4 > target/$(1)/config_$(1)_private.inc 56 m4 -DCFG_ASM_PUB target/$(1)/config.m4 > target/$(1)/config_$(1)_public.inc 57 m4 -DCFG_C_DEF target/$(1)/config.m4 > target/$(1)/config_$(1).h 58 cp target/$(1)/config_$(1)_private.inc target/$(1)/obj/config_private.inc 59 @if [ "$(1)" = "zx" ]; then \ 60 m4 -I../../src/m4 -Itarget/zx/obj arch/zx/bifrost2/z80/BIFROST2_ENGINE.asm.m4 > arch/zx/bifrost2/z80/BIFROST2_ENGINE.asm; \ 61 m4 -I../../src/m4 -Itarget/zx/obj arch/zx/bifrost2/z80/BIFROST2_INSTALL.asm.m4 > arch/zx/bifrost2/z80/BIFROST2_INSTALL.asm; \ 62 m4 -I../../src/m4 -Itarget/zx/obj arch/zx/bifrost_h/z80/BIFROSTH_ENGINE.asm.m4 > arch/zx/bifrost_h/z80/BIFROSTH_ENGINE.asm; \ 63 m4 -I../../src/m4 -Itarget/zx/obj arch/zx/bifrost_l/z80/BIFROSTL_ENGINE.asm.m4 > arch/zx/bifrost_l/z80/BIFROSTL_ENGINE.asm; \ 64 m4 -I../../src/m4 -Itarget/zx/obj arch/zx/nirvanap/z80/NIRVANAP_ENGINE.asm.m4 > arch/zx/nirvanap/z80/NIRVANAP_ENGINE.asm; \ 65 m4 -I../../src/m4 -Itarget/zx/obj arch/zx/nirvanam/z80/NIRVANAM_ENGINE.asm.m4 > arch/zx/nirvanam/z80/NIRVANAM_ENGINE.asm; \ 66 zcc +z80 -vn -clib=new --no-crt -g -Ca"-DSTRIPVECTOR" -Cm-Itarget/$(1)/obj arch/zx/bifrost2/z80/BIFROST2_ENGINE.asm.m4 -o arch/zx/bifrost2/z80/bifrost2_engine_48.bin; \ 67 zcc +z80 -vn -clib=new --no-crt -g -Ca"-DPLUS3 -DSTRIPVECTOR" -Cm-Itarget/$(1)/obj arch/zx/bifrost2/z80/BIFROST2_ENGINE.asm.m4 -o arch/zx/bifrost2/z80/bifrost2_engine_p3.bin; \ 68 $(ZX7) -f arch/zx/bifrost2/z80/bifrost2_engine_48.bin; \ 69 $(ZX7) -f arch/zx/bifrost2/z80/bifrost2_engine_p3.bin; \ 70 fi; 71 @if [ "$(1)" = "zxn" ]; then \ 72 m4 -I../../src/m4 -Itarget/zx/obj arch/zx/bifrost2/z80/BIFROST2_ENGINE.asm.m4 > arch/zx/bifrost2/z80/BIFROST2_ENGINE.asm; \ 73 m4 -I../../src/m4 -Itarget/zx/obj arch/zx/bifrost2/z80/BIFROST2_INSTALL.asm.m4 > arch/zx/bifrost2/z80/BIFROST2_INSTALL.asm; \ 74 m4 -I../../src/m4 -Itarget/zx/obj arch/zx/bifrost_h/z80/BIFROSTH_ENGINE.asm.m4 > arch/zx/bifrost_h/z80/BIFROSTH_ENGINE.asm; \ 75 m4 -I../../src/m4 -Itarget/zx/obj arch/zx/bifrost_l/z80/BIFROSTL_ENGINE.asm.m4 > arch/zx/bifrost_l/z80/BIFROSTL_ENGINE.asm; \ 76 m4 -I../../src/m4 -Itarget/zx/obj arch/zx/nirvanap/z80/NIRVANAP_ENGINE.asm.m4 > arch/zx/nirvanap/z80/NIRVANAP_ENGINE.asm; \ 77 m4 -I../../src/m4 -Itarget/zx/obj arch/zx/nirvanam/z80/NIRVANAM_ENGINE.asm.m4 > arch/zx/nirvanam/z80/NIRVANAM_ENGINE.asm; \ 78 zcc +z80 -vn -clib=new --no-crt -g -Ca"-DSTRIPVECTOR" -Cm-Itarget/$(1)/obj arch/zx/bifrost2/z80/BIFROST2_ENGINE.asm.m4 -o arch/zx/bifrost2/z80/bifrost2_engine_48.bin; \ 79 zcc +z80 -vn -clib=new --no-crt -g -Ca"-DPLUS3 -DSTRIPVECTOR" -Cm-Itarget/$(1)/obj arch/zx/bifrost2/z80/BIFROST2_ENGINE.asm.m4 -o arch/zx/bifrost2/z80/bifrost2_engine_p3.bin; \ 80 $(ZX7) -f arch/zx/bifrost2/z80/bifrost2_engine_48.bin; \ 81 $(ZX7) -f arch/zx/bifrost2/z80/bifrost2_engine_p3.bin; \ 82 fi; 83 @if [ -f target/$(1)/library/$(1)_macro.lst ]; then \ 84 zcc +z80 -vn -clib=new -m4 -Cm-Itarget/$(1)/obj --lstcwd @target/$(1)/library/$(1)_macro.lst; \ 85 fi; 86endef 87 88define build_libs 89lib/sccz80/$(1).lib: target/$(1)/obj/config_private.inc 90 $(Z80ASM) $(cpu) -d -Otarget/$(1)/obj/sccz80 -Itarget/$(1)/obj -xlib/sccz80/$(1) -I$(Z88DK_LIB) @target/$(1)/library/$(1)_sccz80.lst 91 92lib/sdcc_ix/$(1).lib: target/$(1)/obj/config_private.inc 93 $(Z80ASM) $(cpu) -d -Otarget/$(1)/obj/sdcc_ix -Itarget/$(1)/obj -xlib/sdcc_ix/$(1) -I$(Z88DK_LIB) -D__SDCC -D__SDCC_IX @target/$(1)/library/$(1)_sdcc_ix.lst 94 95lib/sdcc_iy/$(1).lib: target/$(1)/obj/config_private.inc 96 $(Z80ASM) $(cpu) -d -Otarget/$(1)/obj/sdcc_iy -Itarget/$(1)/obj -IXIY -xlib/sdcc_iy/$(1) -I$(Z88DK_LIB) -D__SDCC -D__SDCC_IY @target/$(1)/library/$(1)_sdcc_iy.lst 97endef 98 99define make_clean 100.PHONY: clean-$(1) 101 102clean-$(1): 103 @$(RM) -r target/$(1)/obj 104 @$(RM) lib/sccz80/$(1).lib 105 @$(RM) lib/sdcc_ix/$(1).lib 106 @$(RM) lib/sdcc_iy/$(1).lib 107endef 108 109define build_target 110endef 111 112# $(1) = list of targets 113define build_targets 114 $(foreach target, $(1), \ 115 $(eval $(call config,$(target))) \ 116 $(eval $(call build_libs,$(target))) \ 117 $(eval $(call make_clean,$(target))) \ 118 ) 119endef 120 121$(eval $(call build_targets,$(TARGET))) 122 123 124