-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathMakefile
97 lines (79 loc) · 2.21 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
# We only allow compilation on linux!
ifneq ($(shell uname), Linux)
$(error OS must be Linux!)
endif
# Default platform is no platform.
export PLATFORM =
# Global settings: folders.
export ROOT = $(realpath .)
# PREFIX is a standardized env variable for the target install directory.
export PREFIX = $(ROOT)/bin
export BUILD_DIR = $(ROOT)/build
export BIN_DIR = $(PREFIX)
export INC_DIR = $(ROOT)/include
# Build reduced version of libraries?
export SLIM =
# Instruction set. Could be -mz180 as well, for example.
export ISET = -mz80
# Global settings: tools.
export CC = sdcc
export CFLAGS = --std-c11 $(ISET) -I. -I$(INC_DIR) --no-std-crt0 --nostdinc --nostdlib --debug -D PLATFORM=$(PLATFORM) -D SLIM=$(SLIM)
export AS = sdasz80
export ASFLAGS = -xlos -g
export AR = sdar
export ARFLAGS = -rc
export CPP = sdcpp
export LD = sdldz80
# Check if all required tools are on the system.
REQUIRED = ${CC} ${AR} ${AS} ${CPP} ${LD}
K := $(foreach exec,$(REQUIRED),\
$(if $(shell which $(exec)),,$(error "$(exec) not found. Please install or add to path.")))
# crt0.s
export CRT0 = crt0cpm3-z80
export CRT0EXT = .rel
# Subfolders for make.
SUBDIRS = src
SUBMODULES = lib/libsdcc-z80
# Rules.
.PHONY: all
all: $(BUILD_DIR) $(SUBMODULES) $(SUBDIRS)
cp --dereference $(BUILD_DIR)/*.lib $(BIN_DIR)
cp --dereference $(BUILD_DIR)/$(CRT0).rel $(BIN_DIR)/$(CRT0)$(CRT0EXT)
cp -R --dereference $(ROOT)/include $(BIN_DIR)
# "make install" is somewhat expected to be present.
.PHONY: install
install: all
.PHONY: $(BUILD_DIR)
$(BUILD_DIR):
# Create build dir.
mkdir -p $(BUILD_DIR)
# Remove bin dir (we are going to write again).
rm -f -r $(BIN_DIR)
# And re-create!
mkdir -p $(BIN_DIR)
.PHONY: $(SUBDIRS)
$(SUBDIRS):
$(MAKE) -C $@ \
AS="$(AS)" \
CC="$(CC)" \
AR="$(AR)" \
CPP="$(CPP)" \
LD="$(LD)" \
REQUIRED="$(AS) $(CC) $(AR) $(CPP) $(LD)" \
CFLAGS="$(CFLAGS)"
.PHONY: $(SUBMODULES)
$(SUBMODULES):
# Pass current settings to the submodules.
$(MAKE) -C $@ \
BUILD_DIR=$(BUILD_DIR) \
BIN_DIR=$(BIN_DIR) \
AS="$(AS)" \
CC="$(CC)" \
AR="$(AR)" \
CPP="$(CPP)" \
LD="$(LD)" \
REQUIRED="$(AS) $(CC) $(AR) $(CPP) $(LD)" \
CFLAGS="$(CFLAGS)"
.PHONY: clean
clean:
rm -f -r $(BUILD_DIR)