|
| 1 | +############################################################################### |
| 2 | +### Generic Makefile for cc65 projects - full version with abstract options ### |
| 3 | +### V1.3.0(w) 2010 - 2013 Oliver Schmidt & Patryk "Silver Dream !" Łogiewa ### |
| 4 | +############################################################################### |
| 5 | + |
| 6 | +############################################################################### |
| 7 | +### In order to override defaults - values can be assigned to the variables ### |
| 8 | +############################################################################### |
| 9 | + |
| 10 | +# Space or comma separated list of cc65 supported target platforms to build for. |
| 11 | +# Default: c64 (lowercase!) |
| 12 | +TARGETS := apple2 |
| 13 | + |
| 14 | +# Name of the final, single-file executable. |
| 15 | +# Default: name of the current dir with target name appended |
| 16 | +PROGRAM := nfind |
| 17 | + |
| 18 | +# Path(s) to additional libraries required for linking the program |
| 19 | +# Use only if you don't want to place copies of the libraries in SRCDIR |
| 20 | +# Default: none |
| 21 | +LIBS := |
| 22 | + |
| 23 | +# Custom linker nfinduration file |
| 24 | +# Use only if you don't want to place it in SRCDIR |
| 25 | +# Default: none |
| 26 | +CONFIG := |
| 27 | + |
| 28 | +# Additional C compiler flags and options. |
| 29 | +# Default: none |
| 30 | +CFLAGS = |
| 31 | + |
| 32 | +# Additional assembler flags and options. |
| 33 | +# Default: none |
| 34 | +ASFLAGS = |
| 35 | + |
| 36 | +# Additional linker flags and options. |
| 37 | +# Default: none |
| 38 | +LDFLAGS = $(LDFLAGS.$(TARGETS)) -u __EXEHDR__ --start-addr 0x0300 --mapfile nfind.map |
| 39 | + |
| 40 | +# Path to the directory containing C and ASM sources. |
| 41 | +# Default: src |
| 42 | +SRCDIR := |
| 43 | + |
| 44 | +# Path to the directory where object files are to be stored (inside respective target subdirectories). |
| 45 | +# Default: obj |
| 46 | +OBJDIR := |
| 47 | + |
| 48 | +# Command used to run the emulator. |
| 49 | +# Default: depending on target platform. For default (c64) target: x64 -kernal kernal -VICIIdsize -autoload |
| 50 | +EMUCMD := |
| 51 | + |
| 52 | +# Optional commands used before starting the emulation process, and after finishing it. |
| 53 | +# Default: none |
| 54 | +#PREEMUCMD := osascript -e "tell application \"System Events\" to set isRunning to (name of processes) contains \"X11.bin\"" -e "if isRunning is true then tell application \"X11\" to activate" |
| 55 | +#PREEMUCMD := osascript -e "tell application \"X11\" to activate" |
| 56 | +#POSTEMUCMD := osascript -e "tell application \"System Events\" to tell process \"X11\" to set visible to false" |
| 57 | +#POSTEMUCMD := osascript -e "tell application \"Terminal\" to activate" |
| 58 | +PREEMUCMD := |
| 59 | +POSTEMUCMD := |
| 60 | + |
| 61 | +# On Windows machines VICE emulators may not be available in the PATH by default. |
| 62 | +# In such case, please set the variable below to point to directory containing |
| 63 | +# VICE emulators. |
| 64 | +#VICE_HOME := "C:\Program Files\WinVICE-2.2-x86\" |
| 65 | +VICE_HOME := |
| 66 | + |
| 67 | +# Options state file name. You should not need to change this, but for those |
| 68 | +# rare cases when you feel you really need to name it differently - here you are |
| 69 | +STATEFILE := Makefile.options |
| 70 | + |
| 71 | +################################################################################### |
| 72 | +#### DO NOT EDIT BELOW THIS LINE, UNLESS YOU REALLY KNOW WHAT YOU ARE DOING! #### |
| 73 | +################################################################################### |
| 74 | + |
| 75 | +################################################################################### |
| 76 | +### Mapping abstract options to the actual compiler, assembler and linker flags ### |
| 77 | +### Predefined compiler, assembler and linker flags, used with abstract options ### |
| 78 | +### valid for 2.14.x. Consult the documentation of your cc65 version before use ### |
| 79 | +################################################################################### |
| 80 | + |
| 81 | +# Compiler flags used to tell the compiler to optimise for SPEED |
| 82 | +define _optspeed_ |
| 83 | + CFLAGS += -Oris |
| 84 | +endef |
| 85 | + |
| 86 | +# Compiler flags used to tell the compiler to optimise for SIZE |
| 87 | +define _optsize_ |
| 88 | + CFLAGS += -Or |
| 89 | +endef |
| 90 | + |
| 91 | +# Compiler and assembler flags for generating listings |
| 92 | +define _listing_ |
| 93 | + CFLAGS += --listing $$(@:.o=.lst) |
| 94 | + ASFLAGS += --listing $$(@:.o=.lst) |
| 95 | + REMOVES += $(addsuffix .lst,$(basename $(OBJECTS))) |
| 96 | +endef |
| 97 | + |
| 98 | +# Linker flags for generating map file |
| 99 | +define _mapfile_ |
| 100 | + LDFLAGS += --mapfile $$@.map |
| 101 | + REMOVES += $(PROGRAM).map |
| 102 | +endef |
| 103 | + |
| 104 | +# Linker flags for generating VICE label file |
| 105 | +define _labelfile_ |
| 106 | + LDFLAGS += -Ln $$@.lbl |
| 107 | + REMOVES += $(PROGRAM).lbl |
| 108 | +endef |
| 109 | + |
| 110 | +# Linker flags for generating a debug file |
| 111 | +define _debugfile_ |
| 112 | + LDFLAGS += -Wl --dbgfile,$$@.dbg |
| 113 | + REMOVES += $(PROGRAM).dbg |
| 114 | +endef |
| 115 | + |
| 116 | +############################################################################### |
| 117 | +### Defaults to be used if nothing defined in the editable sections above ### |
| 118 | +############################################################################### |
| 119 | + |
| 120 | +# Presume the C64 target like the cl65 compile & link utility does. |
| 121 | +# Set TARGETS to override. |
| 122 | +ifeq ($(TARGETS),) |
| 123 | + TARGETS := c64 |
| 124 | +endif |
| 125 | + |
| 126 | +# Presume we're in a project directory so name the program like the current |
| 127 | +# directory. Set PROGRAM to override. |
| 128 | +ifeq ($(PROGRAM),) |
| 129 | + PROGRAM := $(notdir $(CURDIR)) |
| 130 | +endif |
| 131 | + |
| 132 | +# Presume the C and asm source files to be located in the subdirectory 'src'. |
| 133 | +# Set SRCDIR to override. |
| 134 | +ifeq ($(SRCDIR),) |
| 135 | + SRCDIR := src |
| 136 | +endif |
| 137 | + |
| 138 | +# Presume the object and dependency files to be located in the subdirectory |
| 139 | +# 'obj' (which will be created). Set OBJDIR to override. |
| 140 | +ifeq ($(OBJDIR),) |
| 141 | + OBJDIR := obj |
| 142 | +endif |
| 143 | +TARGETOBJDIR := $(OBJDIR)/$(TARGETS) |
| 144 | + |
| 145 | +# On Windows it is mandatory to have CC65_HOME set. So do not unnecessarily |
| 146 | +# rely on cl65 being added to the PATH in this scenario. |
| 147 | +ifdef CC65_HOME |
| 148 | + CC := $(CC65_HOME)/bin/cl65 |
| 149 | +else |
| 150 | + CC := cl65 |
| 151 | +endif |
| 152 | + |
| 153 | +# Default emulator commands and options for particular targets. |
| 154 | +# Set EMUCMD to override. |
| 155 | +c64_EMUCMD := $(VICE_HOME)xscpu64 -VICIIdsize -autostart |
| 156 | +c128_EMUCMD := $(VICE_HOME)x128 -kernal kernal -VICIIdsize -autoload |
| 157 | +vic20_EMUCMD := $(VICE_HOME)xvic -kernal kernal -VICdsize -autoload |
| 158 | +pet_EMUCMD := $(VICE_HOME)xpet -Crtcdsize -autoload |
| 159 | +plus4_EMUCMD := $(VICE_HOME)xplus4 -TEDdsize -autoload |
| 160 | +# So far there is no x16 emulator in VICE (why??) so we have to use xplus4 with -memsize option |
| 161 | +c16_EMUCMD := $(VICE_HOME)xplus4 -ramsize 16 -TEDdsize -autoload |
| 162 | +cbm510_EMUCMD := $(VICE_HOME)xcbm2 -model 510 -VICIIdsize -autoload |
| 163 | +cbm610_EMUCMD := $(VICE_HOME)xcbm2 -model 610 -Crtcdsize -autoload |
| 164 | +atari_EMUCMD := atari800 -windowed -xl -pal -nopatchall -run |
| 165 | + |
| 166 | +ifeq ($(EMUCMD),) |
| 167 | + EMUCMD = $($(CC65TARGET)_EMUCMD) |
| 168 | +endif |
| 169 | + |
| 170 | +############################################################################### |
| 171 | +### The magic begins ### |
| 172 | +############################################################################### |
| 173 | + |
| 174 | +# The "Native Win32" GNU Make contains quite some workarounds to get along with |
| 175 | +# cmd.exe as shell. However it does not provide means to determine that it does |
| 176 | +# actually activate those workarounds. Especially does $(SHELL) NOT contain the |
| 177 | +# value 'cmd.exe'. So the usual way to determine if cmd.exe is being used is to |
| 178 | +# execute the command 'echo' without any parameters. Only cmd.exe will return a |
| 179 | +# non-empy string - saying 'ECHO is on/off'. |
| 180 | +# |
| 181 | +# Many "Native Win32" prorams accept '/' as directory delimiter just fine. How- |
| 182 | +# ever the internal commands of cmd.exe generally require '\' to be used. |
| 183 | +# |
| 184 | +# cmd.exe has an internal command 'mkdir' that doesn't understand nor require a |
| 185 | +# '-p' to create parent directories as needed. |
| 186 | +# |
| 187 | +# cmd.exe has an internal command 'del' that reports a syntax error if executed |
| 188 | +# without any file so make sure to call it only if there's an actual argument. |
| 189 | +ifeq ($(shell echo),) |
| 190 | + MKDIR = mkdir -p $1 |
| 191 | + RMDIR = rmdir $1 |
| 192 | + RMFILES = $(RM) $1 |
| 193 | +else |
| 194 | + MKDIR = mkdir $(subst /,\,$1) |
| 195 | + RMDIR = rmdir $(subst /,\,$1) |
| 196 | + RMFILES = $(if $1,del /f $(subst /,\,$1)) |
| 197 | +endif |
| 198 | +COMMA := , |
| 199 | +SPACE := $(N/A) $(N/A) |
| 200 | +define NEWLINE |
| 201 | + |
| 202 | + |
| 203 | +endef |
| 204 | +# Note: Do not remove any of the two empty lines above ! |
| 205 | + |
| 206 | +TARGETLIST := $(subst $(COMMA),$(SPACE),$(TARGETS)) |
| 207 | + |
| 208 | +ifeq ($(words $(TARGETLIST)),1) |
| 209 | + |
| 210 | +# Set PROGRAM to something like 'myprog.c64'. |
| 211 | +override PROGRAM := $(PROGRAM) |
| 212 | + |
| 213 | +# Set SOURCES to something like 'src/foo.c src/bar.s'. |
| 214 | +# Use of assembler files with names ending differently than .s is deprecated! |
| 215 | +SOURCES := $(wildcard $(SRCDIR)/*.c) |
| 216 | +SOURCES += $(wildcard $(SRCDIR)/*.s) |
| 217 | +SOURCES += $(wildcard $(SRCDIR)/*.asm) |
| 218 | +SOURCES += $(wildcard $(SRCDIR)/*.a65) |
| 219 | + |
| 220 | +# Add to SOURCES something like 'src/c64/me.c src/c64/too.s'. |
| 221 | +# Use of assembler files with names ending differently than .s is deprecated! |
| 222 | +SOURCES += $(wildcard $(SRCDIR)/$(TARGETLIST)/*.c) |
| 223 | +SOURCES += $(wildcard $(SRCDIR)/$(TARGETLIST)/*.s) |
| 224 | +SOURCES += $(wildcard $(SRCDIR)/$(TARGETLIST)/*.asm) |
| 225 | +SOURCES += $(wildcard $(SRCDIR)/$(TARGETLIST)/*.a65) |
| 226 | + |
| 227 | +# Set OBJECTS to something like 'obj/c64/foo.o obj/c64/bar.o'. |
| 228 | +OBJECTS := $(addsuffix .o,$(basename $(addprefix $(TARGETOBJDIR)/,$(notdir $(SOURCES))))) |
| 229 | + |
| 230 | +# Set DEPENDS to something like 'obj/c64/foo.d obj/c64/bar.d'. |
| 231 | +DEPENDS := $(OBJECTS:.o=.d) |
| 232 | + |
| 233 | +# Add to LIBS something like 'src/foo.lib src/c64/bar.lib'. |
| 234 | +LIBS += $(wildcard $(SRCDIR)/*.lib) |
| 235 | +LIBS += $(wildcard $(SRCDIR)/$(TARGETLIST)/*.lib) |
| 236 | + |
| 237 | +# Add to CONFIG something like 'src/c64/bar.cfg src/foo.cfg'. |
| 238 | +CONFIG += $(wildcard $(SRCDIR)/$(TARGETLIST)/*.cfg) |
| 239 | +CONFIG += $(wildcard $(SRCDIR)/*.cfg) |
| 240 | + |
| 241 | +# Select CONFIG file to use. Target specific nfinds have higher priority. |
| 242 | +ifneq ($(word 2,$(CONFIG)),) |
| 243 | + CONFIG := $(firstword $(CONFIG)) |
| 244 | + $(info Using nfind file $(CONFIG) for linking) |
| 245 | +endif |
| 246 | + |
| 247 | +.SUFFIXES: |
| 248 | +.PHONY: all test clean zap love |
| 249 | + |
| 250 | +all: $(PROGRAM) |
| 251 | + |
| 252 | +-include $(DEPENDS) |
| 253 | +-include $(STATEFILE) |
| 254 | + |
| 255 | +# If OPTIONS are given on the command line then save them to STATEFILE |
| 256 | +# if (and only if) they have actually changed. But if OPTIONS are not |
| 257 | +# given on the command line then load them from STATEFILE. Have object |
| 258 | +# files depend on STATEFILE only if it actually exists. |
| 259 | +ifeq ($(origin OPTIONS),command line) |
| 260 | + ifneq ($(OPTIONS),$(_OPTIONS_)) |
| 261 | + ifeq ($(OPTIONS),) |
| 262 | + $(info Removing OPTIONS) |
| 263 | + $(shell $(RM) $(STATEFILE)) |
| 264 | + $(eval $(STATEFILE):) |
| 265 | + else |
| 266 | + $(info Saving OPTIONS=$(OPTIONS)) |
| 267 | + $(shell echo _OPTIONS_=$(OPTIONS) > $(STATEFILE)) |
| 268 | + endif |
| 269 | + $(eval $(OBJECTS): $(STATEFILE)) |
| 270 | + endif |
| 271 | +else |
| 272 | + ifeq ($(origin _OPTIONS_),file) |
| 273 | + $(info Using saved OPTIONS=$(_OPTIONS_)) |
| 274 | + OPTIONS = $(_OPTIONS_) |
| 275 | + $(eval $(OBJECTS): $(STATEFILE)) |
| 276 | + endif |
| 277 | +endif |
| 278 | + |
| 279 | +# Transform the abstract OPTIONS to the actual cc65 options. |
| 280 | +$(foreach o,$(subst $(COMMA),$(SPACE),$(OPTIONS)),$(eval $(_$o_))) |
| 281 | + |
| 282 | +# Strip potential variant suffix from the actual cc65 target. |
| 283 | +CC65TARGET := $(firstword $(subst .,$(SPACE),$(TARGETLIST))) |
| 284 | + |
| 285 | +# The remaining targets. |
| 286 | +$(TARGETOBJDIR): |
| 287 | + $(call MKDIR,$@) |
| 288 | + |
| 289 | +vpath %.c $(SRCDIR)/$(TARGETLIST) $(SRCDIR) |
| 290 | + |
| 291 | +$(TARGETOBJDIR)/%.o: %.c | $(TARGETOBJDIR) |
| 292 | + $(CC) -t $(CC65TARGET) -c --create-dep $(@:.o=.d) $(CFLAGS) -o $@ $< |
| 293 | + |
| 294 | +vpath %.s $(SRCDIR)/$(TARGETLIST) $(SRCDIR) |
| 295 | + |
| 296 | +$(TARGETOBJDIR)/%.o: %.s | $(TARGETOBJDIR) |
| 297 | + $(CC) -t $(CC65TARGET) -c --create-dep $(@:.o=.d) $(ASFLAGS) -o $@ $< |
| 298 | + |
| 299 | +vpath %.asm $(SRCDIR)/$(TARGETLIST) $(SRCDIR) |
| 300 | + |
| 301 | +$(TARGETOBJDIR)/%.o: %.asm | $(TARGETOBJDIR) |
| 302 | + $(CC) -t $(CC65TARGET) -c --create-dep $(@:.o=.d) $(ASFLAGS) -o $@ $< |
| 303 | + |
| 304 | +vpath %.a65 $(SRCDIR)/$(TARGETLIST) $(SRCDIR) |
| 305 | + |
| 306 | +$(TARGETOBJDIR)/%.o: %.a65 | $(TARGETOBJDIR) |
| 307 | + $(CC) -t $(CC65TARGET) -c --create-dep $(@:.o=.d) $(ASFLAGS) -o $@ $< |
| 308 | + |
| 309 | +$(PROGRAM): $(CONFIG) $(OBJECTS) $(LIBS) |
| 310 | + $(CC) -t $(CC65TARGET) $(LDFLAGS) -o $@ $(patsubst %.cfg,-C %.cfg,$^) |
| 311 | + |
| 312 | +test: $(PROGRAM) |
| 313 | + $(PREEMUCMD) |
| 314 | + $(EMUCMD) $< |
| 315 | + $(POSTEMUCMD) |
| 316 | + |
| 317 | +dist: $(PROGRAM) |
| 318 | + cp dist.apple2/bootable.po dist.apple2/nfind.po |
| 319 | + java -jar dist.apple2/ac.jar -as dist.apple2/nfind.po nfind bin <nfind |
| 320 | + cp dist.apple2/nfind.po ~/Workspace/tnfs/ |
| 321 | + |
| 322 | +clean: |
| 323 | + $(call RMFILES,$(OBJECTS)) |
| 324 | + $(call RMFILES,$(DEPENDS)) |
| 325 | + $(call RMFILES,$(REMOVES)) |
| 326 | + $(call RMFILES,$(PROGRAM)) |
| 327 | + $(call RMFILES,*.map) |
| 328 | + |
| 329 | +else # $(words $(TARGETLIST)),1 |
| 330 | + |
| 331 | +all test clean: |
| 332 | + $(foreach t,$(TARGETLIST),$(MAKE) TARGETS=$t $@$(NEWLINE)) |
| 333 | + |
| 334 | +endif # $(words $(TARGETLIST)),1 |
| 335 | + |
| 336 | +OBJDIRLIST := $(wildcard $(OBJDIR)/*) |
| 337 | + |
| 338 | +zap: |
| 339 | + $(foreach o,$(OBJDIRLIST),-$(call RMFILES,$o/*.o $o/*.d $o/*.lst)$(NEWLINE)) |
| 340 | + $(foreach o,$(OBJDIRLIST),-$(call RMDIR,$o)$(NEWLINE)) |
| 341 | + -$(call RMDIR,$(OBJDIR)) |
| 342 | + -$(call RMFILES,$(basename $(PROGRAM)).* $(STATEFILE)) |
| 343 | + |
| 344 | +love: |
| 345 | + @echo "Not war, eh?" |
| 346 | + |
| 347 | +################################################################### |
| 348 | +### Place your additional targets in the additional Makefiles ### |
| 349 | +### in the same directory - their names have to end with ".mk"! ### |
| 350 | +################################################################### |
| 351 | +-include *.mk |
0 commit comments