/
Makefile
132 lines (97 loc) · 3.83 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
GAS=$(shell which tms9900-as)
LD=$(shell which tms9900-ld)
CC=$(shell which tms9900-gcc)
OBJCOPY=$(shell which tms9900-objcopy)
OBJDUMP=$(shell which tms9900-objdump)
XGA99?=$(shell which xga99.py)
XDM99?=$(shell which xdm99.py)
FNAME=FCMD
BANKBINS:=$(shell seq -s ' ' -f "bank%1g.page" 0 15)
VER:=$(shell grep "\#define APP_VER" b0_main.h | cut -d '"' -f2)
MANIFEST=FCMDG.bin FCMDC.bin README.md
SUPPORT=FC/LOAD FC/FCMD FC/FCMDXB FC/BIN/DISKIMAGE FC/BIN/FCMENU FC/BIN/FTP FC/BIN/SAMPLE FC/BIN/SAY FC/BIN/TELNET FC/BIN/VIRGIL99 FC/BIN/FONT FC/MDOSANSI FC/MDOSFONT
LDFLAGS=\
--script=linkfile
CFLAGS=\
-std=gnu99 -nostdlib -ffreestanding -O2 -Werror --save-temps -I$(abspath .) -I$(abspath libti99)
SRCS:=$(sort $(wildcard *.c) $(wildcard *.asm))
LIBTI99_SRCS=$(sort $(wildcard libti99/*.c))
LIBTI99_OBJS:=$(notdir $(LIBTI99_SRCS:.c=.o))
OBJECT_LIST:=$(SRCS:.c=.o) $(LIBTI99_OBJS)
OBJECT_LIST:=$(filter-out api.o b3_fcbanner.o,$(OBJECT_LIST:.asm=.o)) api.o b3_fcbanner.o
LINK_OBJECTS:=$(addprefix objects/,$(OBJECT_LIST))
all: forcecmd_$(VER).zip
# The size of the cart_rom segment in decimal
# must agree with linkfile
COMMON_SIZE = 128
HEADBIN:=objects/header.bin
$(HEADBIN): $(FNAME).elf
$(OBJCOPY) -O binary -j .text $< $(HEADBIN)
@dd if=/dev/null of=$(HEADBIN) bs=$(COMMON_SIZE) seek=1
bank0.page: $(FNAME).elf $(HEADBIN)
$(OBJCOPY) -O binary -j .data $< objects/data.bin_tmp
$(OBJCOPY) -O binary -j .bank0 $< objects/$@_tmp
cat $(HEADBIN) objects/$@_tmp objects/data.bin_tmp >$@
@dd if=/dev/null of=$@ bs=8192 seek=1
%.page: $(FNAME).elf $(HEADBIN)
$(OBJCOPY) -O binary -j .$(basename $@) $< objects/$@_tmp
cat $(HEADBIN) objects/$@_tmp >$@
@dd if=/dev/null of=$@ bs=8192 seek=1
$(FNAME)C.bin: $(BANKBINS)
cat $^ >$@
$(FNAME)G.bin: gpl-boot.g99 $(FNAME).elf
python3 $(XGA99) -D "CART=$(shell echo -n '>' ; grep _cart mapfile | sed 's/^\s*0x0*\([0-9a-f]*\) *_cart/\1/')" -o $@ $<
$(FNAME).elf: $(LINK_OBJECTS) linkfile
$(LD) $(LINK_OBJECTS) $(LDFLAGS) -o $(FNAME).elf -Map=mapfile
linkfile: linkfile.m4
m4 $< > $@
clean:
rm -f forcecmd_*.zip
rm -fr objects
rm -f *.elf
rm -f *.bin
rm -f *.page
rm -f linkfile
rm -f mapfile
rm -f *.RPK
rm -f api.asm
rm -f api.banks
$(MAKE) -C FC clean
for d in $(SUBDIRS); do $(MAKE) -C example/gcc/$$d clean; done
rm -fr fcsdk
objects/%.o: %.asm
mkdir -p objects; cd objects; $(GAS) $(abspath $<) -o $(notdir $@)
objects/%.o: %.c
mkdir -p objects; cd objects; $(CC) -c $(abspath $<) $(CFLAGS) -o $(notdir $@)
objects/%.o: libti99/%.c
mkdir -p objects; cd objects; $(CC) -c $(abspath $<) $(CFLAGS) -o $(notdir $@)
api.asm: fc_api.lst makeapi.py fc_api_template
rm -f api.asm
grep DECLARE_BANKED libti99/*.h *.h >api.banks
python3 ./makeapi.py fc_api.lst api.asm api.banks example/gcc/fcsdk/fc_api.h
b3_fcbanner.asm: fcbanner.ans ans2asm.py
python3 ./ans2asm.py
SUBDIRS=hello samshello charset diskimage fcmenu ftp say telnet virgil font
subdirs: api.asm
for d in $(SUBDIRS); do $(MAKE) -C example/gcc/$$d; done
support: FC/reload_fcmd.asm FC/loadxb.bas
$(MAKE) -C FC
$(FNAME).DSK: subdirs support
python3 $(XDM99) $(FNAME).DSK -X 360 -t -a FC/BIN/DISKIMAGE FC/BIN/FCMENU FC/BIN/FTP FC/BIN/TELNET FC/BIN/SAY FC/BIN/SAMPLE FC/BIN/VIRGIL99 FC/BIN/FONT FC/MDOSANSI FC/MDOSFONT
$(FNAME).RPK: $(FNAME)C.bin $(FNAME)G.bin layout.xml
zip $@ $^
$(FNAME)_ALT.RPK: $(FNAME)C.bin layout_alt.xml
cp $^ /tmp
mv /tmp/layout_alt.xml /tmp/layout.xml
cd /tmp && zip $@ layout.xml $(FNAME)C.bin
mv /tmp/$@ $@
fcsdk: subdirs
rm -f ./fcsdk
cp -a example/gcc/fcsdk ./fcsdk
cp -a example/gcc/hello ./fcsdk/hello
cp -a example/gcc/samshello ./fcsdk/samshello
find fcsdk -name "objects" -o -name "mapfile" -o -name "*HELLO*" | xargs rm -r
forcecmd_$(VER).zip: $(MANIFEST) subdirs support $(FNAME).RPK $(FNAME).DSK fcsdk
rm -f $@
zip -r $@ $(MANIFEST) $(SUPPORT) $(FNAME).RPK $(FNAME).DSK fcsdk
.PHONY: clean subdirs support