|
1 | | -#.SILENT: |
2 | | -# These shouldn't need to be changed |
3 | | -# |
4 | | -# |
5 | | -ifneq ($(strip $(CROSSASM)),) |
6 | | - export Z80BASE=$(CROSSASM)/z80/tools/bin/ |
7 | | -endif |
8 | | - |
9 | | -export AS=$(Z80BASE)z80-unknown-coff-as |
10 | | -export AR=$(Z80BASE)z80-unknown-coff-ar |
11 | | -export LD=$(Z80BASE)z80-unknown-coff-ld |
12 | | -export OBJCOPY=$(Z80BASE)z80-unknown-coff-objcopy |
13 | | -export OBJDUMP=$(Z80BASE)z80-unknown-coff-objdump |
14 | | - |
15 | | -export ASFLAGS += --defsym ROM$(rom)=1 -z80 -ignore-undocumented-instructions -warn-unportable-instructions |
16 | | -# --oformat forces coff output, as small single file programs seem to generate binary output directly, which is not what we want |
17 | | -export LDFLAGS = --trace --oformat coff-z80 |
18 | | - |
19 | | -ifneq ($(strip $(LDSCRIPT)),) |
20 | | - LDFLAGS += -T $(LDSCRIPT) |
21 | | -endif |
22 | | -ifneq ($(strip $(OUTSECTIONS)),) |
23 | | - COPYSECTIONS = $(addprefix -j,$(OUTSECTIONS)) |
24 | | -endif |
25 | | - |
26 | | -export ROOT=$(shell pwd) |
27 | | - |
28 | | -# Define the extension for src files |
29 | | -ifneq ($(strip $(SRC_EXT)),) |
30 | | - SRCEXT = $(SRC_EXT) |
31 | | -else |
32 | | - SRCEXT = z80 |
33 | | -endif |
34 | | - |
35 | | -BIN=rom |
36 | | -OBJ=obj |
37 | | -LST=lst |
38 | | - |
39 | | -COFF=$(TARGET:%.rom=%.coff) |
40 | | - |
41 | | -OBJF = $(Z80_ASM:%.$(SRCEXT)=%.o) |
42 | | -OBJFILES = $(addprefix $(OBJ)/,$(OBJF)) |
43 | | -LDLIBS = $(addprefix -l,$(LINK_LIBS)) |
44 | | -LDLIBSDIR= $(addprefix -L,$(LIB_DIRS)) |
45 | | -INCDIRS = $(addprefix -I,$(INC_DIRS)) |
46 | | - |
47 | | -ASFLAGS += $(INCDIRS) |
48 | | - |
49 | | -$(TARGET) : bdirs binary |
50 | | -$(LIBRARY): bdirs library |
51 | | - |
52 | | -# Build target.coff from target.rom through objcopy |
53 | | -binary: $(COFF) |
54 | | - @echo Info: Extract sections $(OUTSECTIONS) "-->" $(TARGET) |
55 | | - @$(OBJCOPY) -v $(OBJCOPYFLAGS) $(COPYSECTIONS) -O binary $< $(TARGET) |
56 | | - @chmod +x $(TARGET) |
57 | | - @echo |
58 | | - |
59 | | -libf: |
60 | | - @echo $(OBJFILES) |
61 | | - |
62 | | -# Produce library archive from OBJFILES |
63 | | -library: $(OBJFILES) |
64 | | - @echo Info: Creating library $@ |
65 | | - @rm -f $(LIBRARY) |
66 | | - @$(AR) -rsv $(LIBRARY) $(OBJFILES) |
67 | | - @echo |
68 | | - |
69 | | -# Assemble .z8s into .o |
70 | | -$(OBJ)/%.o: %.$(SRCEXT) |
71 | | - @echo "Info: Assemble" $@ "<--" $< |
72 | | - @$(AS) $(ASFLAGS) -al=$(LST)/$(<:%.$(SRCEXT)=%.lst) -o$@ $(PARAMFILES) $< |
73 | | - |
74 | | -# Produce .coff by assembling Z80_ASM into a single .o and then linking with |
75 | | -# libraries |
76 | | -%.coff : $(Z80_ASM) |
77 | | - @echo "info: Assemble" $(@:%.coff=%.o) "<--" $? |
78 | | - $(AS) $(ASFLAGS) -al=$(LST)/$(@:%.coff=%.lst) -o$(OBJ)/$(@:%.coff=%.o) $(PARAMFILES) $? |
79 | | - @echo |
80 | | - @echo "Info: Link " $(@:%.coff=%.o) "-->" $@ |
81 | | - $(LD) $(LDFLAGS) -Map=$(LST)/$(@:%.coff=%.map) -o$@ $(OBJ)/$(@:%.coff=%.o) $(LDLIBSDIR) $(LDLIBS) |
82 | | - @echo |
83 | | - @echo Info: Create object dump $(@:%.coff=%.dump) |
84 | | - @$(OBJDUMP) -d -S $(COPYSECTIONS) $@ > $(LST)/$(@:%.coff=%.dump) |
85 | | - |
86 | | -# Link .coff from individual .o files |
87 | | -%.coff_needs_globl : $(OBJFILES) |
88 | | - @echo "Info: Link " $? "-->" $@ |
89 | | - $(LD) $(LDFLAGS) -Map=$(LST)/$(@:%.coff=%.map) -o$@ $? $(LDLIBSDIR) $(LDLIBS) |
90 | | - @echo |
91 | | - @echo Info: Create object dump $(@:%.coff=%.dump) |
92 | | - @$(OBJDUMP) -d -S $(COPYSECTIONS) $@ > $(LST)/$(@:%.coff=%.dump) |
93 | | - |
94 | | - |
95 | | -# Utility targets |
96 | | -# |
97 | | -bdirs: |
98 | | - @#[ -d $(BIN) ] || mkdir $(BIN) |
99 | | - @[ -d $(OBJ) ] || mkdir $(OBJ) |
100 | | - @[ -d $(LST) ] || mkdir $(LST) |
101 | | - |
102 | | -.PHONY: tags |
103 | | -tags : |
104 | | - @rm -f ctags |
105 | | - find . -name \*.c -exec ctags -a {} \; |
106 | | - find . -name \*.h -exec ctags -a {} \; |
107 | | - |
108 | | -.PHONEY: gclean |
109 | | -gclean : |
110 | | - find . -name \*.o -exec rm -f {} \; |
111 | | - find . -name \*.o._x -exec rm -f {} \; |
112 | | - find . -name .depend -exec rm -f {} \; |
113 | | - rm -f $(LST)/*.map $(LST)/*.lst *.coff *.rom $(LST)/*.dump |
114 | | - rmdir $(LST) |
115 | | - rmdir $(OBJ) |
116 | | - |
117 | | -clean: gclean |
| 1 | +#.SILENT: |
| 2 | +# These shouldn't need to be changed |
| 3 | +# |
| 4 | +# |
| 5 | +ifneq ($(strip $(CROSSASM)),) |
| 6 | + export Z80BASE=$(CROSSASM)/z80/tools/bin/ |
| 7 | +endif |
| 8 | + |
| 9 | +export AS=$(Z80BASE)z80-unknown-coff-as |
| 10 | +export AR=$(Z80BASE)z80-unknown-coff-ar |
| 11 | +export LD=$(Z80BASE)z80-unknown-coff-ld |
| 12 | +export OBJCOPY=$(Z80BASE)z80-unknown-coff-objcopy |
| 13 | +export OBJDUMP=$(Z80BASE)z80-unknown-coff-objdump |
| 14 | + |
| 15 | +export ASFLAGS += --defsym ROM$(rom)=1 -z80 -ignore-undocumented-instructions -warn-unportable-instructions |
| 16 | +# --oformat forces coff output, as small single file programs seem to generate binary output directly, which is not what we want |
| 17 | +export LDFLAGS = --trace --oformat coff-z80 |
| 18 | + |
| 19 | +ifneq ($(strip $(LDSCRIPT)),) |
| 20 | + LDFLAGS += -T $(LDSCRIPT) |
| 21 | +endif |
| 22 | +ifneq ($(strip $(OUTSECTIONS)),) |
| 23 | + COPYSECTIONS = $(addprefix -j,$(OUTSECTIONS)) |
| 24 | +endif |
| 25 | + |
| 26 | +export ROOT=$(shell pwd) |
| 27 | + |
| 28 | +# Define the extension for src files |
| 29 | +ifneq ($(strip $(SRC_EXT)),) |
| 30 | + SRCEXT = $(SRC_EXT) |
| 31 | +else |
| 32 | + SRCEXT = z80 |
| 33 | +endif |
| 34 | + |
| 35 | +BIN=rom |
| 36 | +OBJ=obj |
| 37 | +LST=lst |
| 38 | + |
| 39 | +COFF=$(TARGET:%.rom=%.coff) |
| 40 | + |
| 41 | +OBJF = $(Z80_ASM:%.$(SRCEXT)=%.o) |
| 42 | +OBJFILES = $(addprefix $(OBJ)/,$(OBJF)) |
| 43 | +LDLIBS = $(addprefix -l,$(LINK_LIBS)) |
| 44 | +LDLIBSDIR= $(addprefix -L,$(LIB_DIRS)) |
| 45 | +INCDIRS = $(addprefix -I,$(INC_DIRS)) |
| 46 | + |
| 47 | +ASFLAGS += $(INCDIRS) |
| 48 | + |
| 49 | +$(TARGET) : bdirs binary |
| 50 | +$(LIBRARY): bdirs library |
| 51 | + |
| 52 | +# Build target.coff from target.rom through objcopy |
| 53 | +binary: $(COFF) |
| 54 | + @echo Info: Extract sections $(OUTSECTIONS) "-->" $(TARGET) |
| 55 | + @$(OBJCOPY) -v $(OBJCOPYFLAGS) $(COPYSECTIONS) -O binary $< $(TARGET) |
| 56 | + @chmod +x $(TARGET) |
| 57 | + @echo |
| 58 | + |
| 59 | +libf: |
| 60 | + @echo $(OBJFILES) |
| 61 | + |
| 62 | +# Produce library archive from OBJFILES |
| 63 | +library: $(OBJFILES) |
| 64 | + @echo Info: Creating library $@ |
| 65 | + @rm -f $(LIBRARY) |
| 66 | + @$(AR) -rsv $(LIBRARY) $(OBJFILES) |
| 67 | + @echo |
| 68 | + |
| 69 | +# Assemble .z8s into .o |
| 70 | +#$(OBJ)/%.o: %.$(SRCEXT) |
| 71 | +# @echo "Info: X Assemble" $@ "<--" $< |
| 72 | +# @$(AS) $(ASFLAGS) -al=$(LST)/$(<:%.$(SRCEXT)=%.lst) -o$@ $(PARAMFILES) $< |
| 73 | + |
| 74 | +# Produce .coff by assembling Z80_ASM into a single .o and then linking with |
| 75 | +# libraries |
| 76 | +%.coff : $(Z80_ASM) |
| 77 | + @echo "info: Assemble" $(@:%.coff=%.o) "<--" $? |
| 78 | + $(AS) $(ASFLAGS) -al=$(LST)/$(@:%.coff=%.lst) -o$(OBJ)/$(@:%.coff=%.o) $(PARAMFILES) $? |
| 79 | + @echo |
| 80 | + @echo "Info: Link " $(@:%.coff=%.o) "-->" $@ |
| 81 | + $(LD) $(LDFLAGS) -Map=$(LST)/$(@:%.coff=%.map) -o$@ $(OBJ)/$(@:%.coff=%.o) $(LDLIBSDIR) $(LDLIBS) |
| 82 | + @echo |
| 83 | + @echo Info: Create object dump $(@:%.coff=%.dump) |
| 84 | + @$(OBJDUMP) -d -S $(COPYSECTIONS) $@ > $(LST)/$(@:%.coff=%.dump) |
| 85 | + |
| 86 | +# Link .coff from individual .o files |
| 87 | +%.coff_needs_globl : $(OBJFILES) |
| 88 | + @echo "Info: Link " $? "-->" $@ |
| 89 | + $(LD) $(LDFLAGS) -Map=$(LST)/$(@:%.coff=%.map) -o$@ $? $(LDLIBSDIR) $(LDLIBS) |
| 90 | + @echo |
| 91 | + @echo Info: Create object dump $(@:%.coff=%.dump) |
| 92 | + @$(OBJDUMP) -d -S $(COPYSECTIONS) $@ > $(LST)/$(@:%.coff=%.dump) |
| 93 | + |
| 94 | + |
| 95 | +# Utility targets |
| 96 | +# |
| 97 | +bdirs: |
| 98 | + @#[ -d $(BIN) ] || mkdir $(BIN) |
| 99 | + @[ -d $(OBJ) ] || mkdir $(OBJ) |
| 100 | + @[ -d $(LST) ] || mkdir $(LST) |
| 101 | + |
| 102 | +.PHONY: tags |
| 103 | +tags : |
| 104 | + @rm -f ctags |
| 105 | + find . -name \*.c -exec ctags -a {} \; |
| 106 | + find . -name \*.h -exec ctags -a {} \; |
| 107 | + |
| 108 | +.PHONEY: gclean |
| 109 | +gclean : |
| 110 | + find . -name \*.o -exec rm -f {} \; |
| 111 | + find . -name \*.o._x -exec rm -f {} \; |
| 112 | + find . -name .depend -exec rm -f {} \; |
| 113 | + rm -f $(LST)/*.map $(LST)/*.lst *.coff *.rom $(LST)/*.dump; |
| 114 | + |
| 115 | +clean: gclean |
0 commit comments