-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
124 lines (94 loc) · 2.99 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
#== Project config ==
#Build mode: debug or release
BUILDTARGET := release
BUILDDIR := build
OBJDIR := obj
INCDIR := include
SRCDIR := src
RESDIR := $(SRCDIR)/res
TOOLDIR := tools
OUTPRG := $(BUILDDIR)/hello.prg
LIBS := cx16.lib
SDCARD :=
#== Build tools ==
SHELL := bash
ifeq ($(OS),Windows_NT)
MKDIR := $(SHELL) /E:ON /C mkdir
else
MKDIR := mkdir -p
endif
#== Target system config ==
TARGET := cx16
CFGFILE := cx16.cfg
#== Emulator config ==
#Emulator path
X16EMU := x16emu
EFLAGS =
#Uncomment to launch the PRG on start-up
EFLAGS += -run
#Uncomment to attach the SD card image specified above
#EFLAGS += -sdcard $(SDCARD)
#Uncomment to enable the emulator's debugger functionality
#EFLAGS += -debug
#Set to true if the emulator should run from the build directory.
#Otherwise, it will run from current directory (in case you want to mount an SD card image over there)
EMUCHDIR := false
#== Compiler config ==
#CC65 binary path (with trailing /). Leave blank to find in system path
CCPATH :=
#Compiler Binaries
CC := $(CCPATH)cl65
AS := $(CCPATH)ca65
LD := $(CCPATH)ld65
#Compiler flags
FLAGS = -t $(TARGET) -I $(INCDIR) -I $(SRCDIR) --create-dep $(OBJDIR)/$*.d
CFLAGS = $(FLAGS) -c -l $@.lst -O
AFLAGS = $(FLAGS)
LFLAGS = -C $(CFGFILE) -m $(BUILDDIR)/memory.map
#== Build targets ==
#List of all source files to be compiled/assembled
M_SRC = $(wildcard $(SRCDIR)/*.c)
M_ASM = $(wildcard $(SRCDIR)/*.asm)
#List of all object files that will be created
OBJ_SRC = $(addprefix $(OBJDIR)/,$(patsubst %.c,%.o,$(notdir $(M_SRC))))
OBJ_ASM = $(addprefix $(OBJDIR)/,$(patsubst %.asm,%.o,$(notdir $(M_ASM))))
#Final list of objects to link
OBJS = $(OBJ_ASM) $(OBJ_SRC)
#Dependency files created by the compiler
DEPS = $(OBJS:%.o=%.d)
#== Build goals ==
all: $(BUILDTARGET)
debug: FLAGS += -d -D _DEBUG
debug: $(OUTPRG)
release: $(OUTPRG)
#Link final PRG file
$(OUTPRG): $(OBJS) | resources $(BUILDDIR)
$(LD) $(LFLAGS) -o $@ $^ $(LIBS)
#Assemble .asm source files to object code
$(OBJDIR)/%.o: $(SRCDIR)/%.asm | binres $(OBJDIR)
$(AS) $(AFLAGS) -o $@ $<
#Compile .c source files to object code
$(OBJDIR)/%.o: $(SRCDIR)/%.c | binres $(OBJDIR)
$(CC) $(CFLAGS) -o $@ $<
#== Resources and Assets ==
#Generate binary/object files for assets/resources at link-time
resources: binres
#Resources that will be included directly in a source file
#These will be generated before compiling any source
binres: $(OBJDIR)
#Include Makefile for resources. You can add more dependencies to 'resources' and 'binres'
-include $(RESDIR)/Makefile
#Load dependency files, if they exist
-include $(DEPS)
#Build the target, then launch the emulator
run: $(BUILDTARGET) runemu
#Launch emulator with the input PRG file
runemu: $(OUTPRG) | $(if $(findstring -sdcard, $(EFLAGS)), $(SDCARD))
ifeq ($(EMUCHDIR), true)
cd $(dir $<) && $(X16EMU) $(EFLAGS) -prg $(notdir $<)
else
$(X16EMU) $(EFLAGS) -prg $<
endif
#Create directories for output files, if they don't exist
$(BUILDDIR) $(OBJDIR):
$(MKDIR) $(subst /,\,$@)