forked from FujiNetWIFI/fujinet-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
214 lines (164 loc) · 5.46 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# Adapted from the generic cc65 makefile.
# Notible exceptions:
# - recursive dirs for src
# - final files go into build/ directory instead of root folder (e.g. lbl, com file etc)
TARGETS := atari apple2 apple2enh c64
PROGRAM := fujinet.lib
LIBS :=
CONFIG :=
CFLAGS =
ASFLAGS =
LDFLAGS =
SRCDIR := src
OBJDIR := obj
EMUCMD :=
BUILD_DIR = build
# The subfolder src directory to use to build the particular target
# cl65 will get the "TARGET" name, but the src folder will be the "PLATFORM"
PLATFORM_apple2 := apple2
PLATFORM_apple2enh := apple2
PLATFORM_atari := atari
PLATFORM_atarixl := atari
PLATFORM_pet := commodore
PLATFORM_c64 := commodore
TARGETOBJDIR := $(OBJDIR)/$(TARGETS)
ifdef CC65_HOME
CC := $(CC65_HOME)/bin/cl65
else
CC := cl65
endif
ifeq ($(shell echo),)
MKDIR = mkdir -p $1
RMDIR = rmdir $1
RMFILES = $(RM) $1
else
MKDIR = mkdir $(subst /,\,$1)
RMDIR = rmdir $(subst /,\,$1)
RMFILES = $(if $1,del /f $(subst /,\,$1))
endif
COMMA := ,
SPACE := $(N/A) $(N/A)
define NEWLINE
endef
# Note: Do not remove any of the two empty lines above !
rwildcard=$(wildcard $(1)$(2))$(foreach d,$(wildcard $1*), $(call rwildcard,$d/,$2))
TARGETLIST := $(subst $(COMMA),$(SPACE),$(TARGETS))
ifeq ($(words $(TARGETLIST)),1)
PLATFORM_SRC_DIR := $(PLATFORM_$(TARGETLIST))/$(SRCDIR)
# Set PROGRAM to something like 'myprog.c64'.
override PROGRAM := $(PROGRAM).$(TARGETLIST)
# Recursive files
SOURCES += $(call rwildcard,$(PLATFORM_SRC_DIR)/,*.s)
SOURCES += $(call rwildcard,$(PLATFORM_SRC_DIR)/,*.c)
SOURCES += $(call rwildcard,common/$(SRCDIR)/,*.s)
SOURCES += $(call rwildcard,common/$(SRCDIR)/,*.c)
# remove trailing and leading spaces.
SOURCES := $(strip $(SOURCES))
# convert from src/your/long/path/foo.[c|s] to obj/your/long/path/foo.o
OBJ1 := $(SOURCES:.c=.o)
OBJECTS := $(OBJ1:.s=.o)
# change from atari/src/ -> obj/atari/
OBJECTS := $(OBJECTS:$(PLATFORM_SRC_DIR)/%=$(OBJDIR)/$(TARGETLIST)/%)
OBJECTS := $(OBJECTS:common/$(SRCDIR)/%=$(OBJDIR)/common/%)
DEPENDS := $(OBJECTS:.o=.d)
LIBS += $(wildcard $(PLATFORM_SRC_DIR)/*.lib)
ASFLAGS += \
--asm-include-dir common/inc \
--asm-include-dir $(PLATFORM_SRC_DIR)/include \
--asm-include-dir .
CFLAGS += \
-Osir \
--include-dir common/inc \
--include-dir $(PLATFORM_SRC_DIR)/include \
--include-dir .
CHANGELOG = Changelog.md
# single line with version number in semantic form (e.g. 2.1.3)
VERSION_FILE = version.txt
VERSION_STRING := $(file < $(VERSION_FILE))
# include files that are included in the ZIP dist/release target
FN_NW_HEADER = fujinet-network.h
FN_NW_INC = fujinet-network.inc
FN_FUJI_HEADER = fujinet-fuji.h
FN_FUJI_INC = fujinet-fuji.inc
define _listing_
CFLAGS += --listing $$(@:.o=.lst)
ASFLAGS += --listing $$(@:.o=.lst)
endef
define _mapfile_
LDFLAGS += --mapfile [email protected]
endef
define _labelfile_
LDFLAGS += -Ln [email protected]
endef
.SUFFIXES:
.PHONY: all clean dist fujinet.lib.$(TARGETLIST)
all: fujinet.lib.$(TARGETLIST)
STATEFILE := Makefile.options
-include $(DEPENDS)
-include $(STATEFILE)
ifeq ($(origin _OPTIONS_),file)
OPTIONS = $(_OPTIONS_)
$(eval $(OBJECTS): $(STATEFILE))
endif
# Transform the abstract OPTIONS to the actual cc65 options.
$(foreach o,$(subst $(COMMA),$(SPACE),$(OPTIONS)),$(eval $(_$o_)))
$(OBJDIR):
$(call MKDIR,$@)
$(TARGETOBJDIR):
$(call MKDIR,$@)
$(BUILD_DIR):
$(call MKDIR,$@)
SRC_INC_DIRS := \
$(sort $(dir $(wildcard $(PLATFORM_SRC_DIR)/*))) \
$(sort $(dir $(wildcard common/$(SRCDIR)/*)))
# $(info $$SOURCES = ${SOURCES})
# $(info $$OBJECTS = ${OBJECTS})
# $(info $$SRC_INC_DIRS = ${SRC_INC_DIRS})
# $(info $$ASFLAGS = ${ASFLAGS})
# $(info $$TARGETOBJDIR = ${TARGETOBJDIR})
# $(info $$TARGETLIST = ${TARGETLIST})
vpath %.c $(SRC_INC_DIRS)
obj/common/%.o: %.c | $(TARGETOBJDIR)
@$(call MKDIR,$(dir $@))
$(CC) -t $(TARGETLIST) -c --create-dep $(@:.o=.d) $(CFLAGS) -o $@ $<
$(TARGETOBJDIR)/%.o: %.c | $(TARGETOBJDIR)
@$(call MKDIR,$(dir $@))
$(CC) -t $(TARGETLIST) -c --create-dep $(@:.o=.d) $(CFLAGS) -o $@ $<
vpath %.s $(SRC_INC_DIRS)
obj/common/%.o: %.s | $(TARGETOBJDIR)
@$(call MKDIR,$(dir $@))
$(CC) -t $(TARGETLIST) -c --create-dep $(@:.o=.d) $(ASFLAGS) -o $@ $<
$(TARGETOBJDIR)/%.o: %.s | $(TARGETOBJDIR)
@$(call MKDIR,$(dir $@))
$(CC) -t $(TARGETLIST) -c --create-dep $(@:.o=.d) $(ASFLAGS) -o $@ $<
$(BUILD_DIR)/$(PROGRAM): $(OBJECTS) | $(BUILD_DIR)
ar65 a $@ $(OBJECTS)
$(PROGRAM): $(BUILD_DIR)/$(PROGRAM) | $(BUILD_DIR)
clean:
$(call RMFILES,$(OBJECTS))
$(call RMFILES,$(DEPENDS))
$(call RMFILES,$(REMOVES))
$(call RMFILES,$(BUILD_DIR)/$(PROGRAM))
dist: $(PROGRAM)
$(call MKDIR,dist/)
$(call RMFILES,dist/fujinet-$(TARGETLIST)-*.lib)
cp build/$(PROGRAM) dist/fujinet-$(TARGETLIST)-$(VERSION_STRING).lib
cp $(FN_NW_HEADER) dist/
cp $(FN_NW_INC) dist/
cp $(FN_FUJI_HEADER) dist/
cp $(FN_FUJI_INC) dist/
cp $(CHANGELOG) dist/
cd dist && zip fujinet-lib-$(TARGETLIST)-$(VERSION_STRING).zip $(CHANGELOG) fujinet-$(TARGETLIST)-$(VERSION_STRING).lib *.h *.inc
$(call RMFILES,dist/fujinet-$(TARGETLIST)-*.lib)
$(call RMFILES,dist/$(CHANGELOG))
$(call RMFILES,dist/*.h)
$(call RMFILES,dist/*.inc)
else # $(words $(TARGETLIST)),1
all:
$(foreach t,$(TARGETLIST),$(MAKE) TARGETS=$t clean all dist$(NEWLINE))
endif # $(words $(TARGETLIST)),1
###################################################################
### Place your additional targets in the additional Makefiles ###
### in the same directory - their names have to end with ".mk"! ###
###################################################################
-include *.mk