-
Notifications
You must be signed in to change notification settings - Fork 75
/
Makefile.stm8
122 lines (85 loc) · 2.96 KB
/
Makefile.stm8
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
# paths
INCDIR = $(TOOLSET)/Hstm8
LIBDIR = $(TOOLSET)/Lib
# in linux, use wine to call compiler
ifdef WINEPREFIX
export WINEPREFIX
WINE = wine
else
WINE =
endif
# flags
CFLAGS = +warn +proto +mods$(SMODE)0 $(DEBUG) -i. -i$(INCDIR) -l $(VERBOSE) -pxp -ac
AFLAGS = -xx -xp -l $(VERBOSE) -c -i. -i$(INCDIR)
LDFLAGS = -l$(LIBDIR)
ifdef CHANNELS
CFLAGS += -dMAX_CHANNELS=$(CHANNELS)
endif
# used programs
AS = $(WINE) $(TOOLSET)/castm8
CC = $(WINE) $(TOOLSET)/cxstm8
LD = $(WINE) $(TOOLSET)/clnk
TOELF = $(WINE) $(TOOLSET)/cvdwarf
BIN = $(WINE) $(TOOLSET)/chex
RM = rm -f
# object files
OBJ = $(SRCC:.c=.o) $(INTRS:.c=.o)
# common compile
%.o: %.c
$(CC) $(CFLAGS) $<
%.s: %.c
$(CC) -s $(CFLAGS) $<
%.o: %.s
$(AS) $(AFLAGS) $<
# program
all: $(PROGRAM).elf $(PROGRAM).s19
$(PROGRAM).sm8: $(OBJ)
@echo "+seg .const -b 0x8080 -m 0x7f80 -n .const -it" >$(PROGRAM).lkf
@echo "+seg .text -a .const -n .text" >>$(PROGRAM).lkf
@echo "+seg .eeprom -b 0x4000 -m 0x400 -n .eeprom" >>$(PROGRAM).lkf
@echo "+seg .bsct -b 0x0 -m 0x100 -n .bsct" >>$(PROGRAM).lkf
@echo "+seg .ubsct -a .bsct -n .ubsct" >>$(PROGRAM).lkf
@echo "+seg .bit -a .ubsct -n .bit -id" >>$(PROGRAM).lkf
@echo "+seg .share -a .bit -n .share -is" >>$(PROGRAM).lkf
@echo "+seg .data -b 0x100 -m "$(ENDMEMORY)"+1-0x100 -n .data" >>$(PROGRAM).lkf
@echo "+seg .bss -a .data -n .bss" >>$(PROGRAM).lkf
@echo "crtsi0.sm8" >>$(PROGRAM).lkf
@echo $(SRCC:.c=.o) >>$(PROGRAM).lkf
@echo $(LIBS) >>$(PROGRAM).lkf
@echo "libis"$(SMODE)"0.sm8" >>$(PROGRAM).lkf
@echo "libm0.sm8" >>$(PROGRAM).lkf
@echo "+seg .const -b 0x8000 -k" >>$(PROGRAM).lkf
@echo $(INTRS:.c=.o) >>$(PROGRAM).lkf
@echo "+def [email protected]" >>$(PROGRAM).lkf
@echo "+def [email protected]" >>$(PROGRAM).lkf
@echo "+def __stack="$(STACK) >>$(PROGRAM).lkf
@echo "+def [email protected]" >>$(PROGRAM).lkf
@echo "+def __endmem="$(ENDMEMORY) >>$(PROGRAM).lkf
$(LD) $(LDFLAGS) -o $@ -m$(PROGRAM).map $(PROGRAM).lkf
$(PROGRAM).elf: $(PROGRAM).sm8
$(TOELF) $<
$(PROGRAM).s19: $(PROGRAM).sm8
$(BIN) -o $@ $<
clean:
$(RM) $(OBJ) $(OBJ:.o=.s) $(OBJ:.o=.ls) $(PROGRAM).sm8 $(PROGRAM).elf $(PROGRAM).s19 $(PROGRAM).map $(PROGRAM).lkf
depend:
$(CC) -sm $(CFLAGS) $(SRCC) $(INTRS) \
| sed -e 's/\<\(mods[^.]*\|iostm8s\|string\)\.h\>//g' \
-e 's/\r//' >.depend
# include dependences if they exists
ifeq (.depend, $(wildcard .depend))
include .depend
endif
compile.bat: Makefile Makefile.stm8
make clean
echo '@if "%TOOLSET%"=="" goto NoToolset' > $@
echo -e '@if not "%CHANNELS%"=="" goto ChannelOK\n@set CHANNELS=8\n:ChannelOK' >>$@
make CHANNELS=8 | grep /c | grep -v ^make | tee -a $@
sed -i -e "s|^\(wine \)\?$(TOOLSET)|%TOOLSET%|" \
-e "s|-\([il]\)$(TOOLSET)|-\1%TOOLSET%|" \
-e "s|-dMAX_CHANNELS=.|-dMAX_CHANNELS=%CHANNELS%|" $@
cp -p $(PROGRAM).lkf compile.lkf
sed -i -e "s|$(PROGRAM)\.lkf|compile.lkf|" $@
echo -e '@goto:EOF\n\n:NoToolset\n@echo TOOLSET variable is not set, set it with "set TOOLSET=path"' >>$@
sed -i -e 's|\(.*\)|\1|' $@