-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
64 lines (50 loc) · 1.5 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
VERSION = 2.18.2
PROJECT_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
PROJECT_DIR := $(PROJECT_DIR:/=)
SRCLIB = /usr/share/cc65/lib/nes.lib
TGTLIB = $(PROJECT_DIR)/lib/runtime.lib
SRCDIR = $(PROJECT_DIR)/src
CFGDIR = $(PROJECT_DIR)/cfg
INCDIR = $(PROJECT_DIR)/include
ASMDIR = $(PROJECT_DIR)/asminc
OBJDIR = $(PROJECT_DIR)/obj
SAMPLE = $(PROJECT_DIR)/samples
CA = ca65
AR = ar65
rwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d))
CSOURCES = $(call rwildcard, $(SRCDIR), *.c)
SSOURCES = $(call rwildcard, $(SRCDIR), *.s)
DEPS := $(CSOURCES:.c=.d)
DEPS := $(DEPS:$(SRCDIR)/%=$(OBJDIR)/%)
OBJS := $(CRT0:.inc=.o) $(SSOURCES:.s=.o) $(CSOURCES:.c=.o)
OBJS := $(OBJS:$(SRCDIR)/%=$(OBJDIR)/%)
ARCHIVE := familib-$(VERSION).zip
AFLAGS := -I $(ASMDIR)
ifeq ($(shell echo),)
MKDIR = mkdir -p $1
else
MKDIR = mkdir $(subst /,\,$1)
endif
ifneq ($(MAKECMDGOALS),clean)
-include $(DEPS)
endif
$(TGTLIB): $(OBJS)
cp $(SRCLIB) $@
$(AR) a $@ $^
$(ARCHIVE): $(TGTLIB)
zip -r $(ARCHIVE) $(TGTLIB:$(PROJECT_DIR)/%=%) $(CFGDIR:$(PROJECT_DIR)/%=%) $(ASMDIR:$(PROJECT_DIR)/%=%) $(INCDIR:$(PROJECT_DIR)/%=%) $(SAMPLE:$(PROJECT_DIR)/%=%)
all: clean $(ARCHIVE)
$(info Done)
.SECONDEXPANSION:
$(OBJDIR)/%.o: $(SRCDIR)/%.s | $$(@D)/.
$(CA) $(AFLAGS) $< -o $@
$(OBJDIR)/%.o: $(ASMDIR)/%.inc | $$(@D)/.
$(CA) $(AFLAGS) $< -o $@
.PRECIOUS: $(OBJDIR)/. $(OBJDIR)%/.
$(OBJDIR)/.:
$(call MKDIR,$@)
$(OBJDIR)%/.:
$(call MKDIR,$@)
.PHONY: clean
clean:
$(RM) $(OBJS) $(DEPS) $(TGTLIB) $(ARCHIVE)