-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
88 lines (65 loc) · 1.78 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
# -*- coding: utf-8-unix; tab-width: 8 -*-
# Copyright (c) 2021-2025 Daishi Mori (mori0091)
#
# This software is released under the MIT License.
# See https://github.com/mori0091/libmsx/blob/main/LICENSE
#
# GitHub libmsx project
# https://github.com/mori0091/libmsx
.PHONY: all build clean sample tools test
all: build tools
SRCDIR ?= src
OBJDIR ?= obj
BINDIR ?= bin
LIBDIR ?= lib
NAME = libmsx
SRCS_C = $(shell find ${SRCDIR} -type f -name '*.c')
OBJS_C = $(patsubst ${SRCDIR}/%.c, ${OBJDIR}/%.rel, ${SRCS_C})
SRCS_ASM = $(shell find ${SRCDIR} -type f -name '*.s')
OBJS_ASM = $(patsubst ${SRCDIR}/%.s, ${OBJDIR}/%.rel, ${SRCS_ASM})
OBJS = ${OBJS_ASM} ${OBJS_C}
SRCS_CRT0 = $(shell find crt0 -type f -name '*.s')
OBJS_CRT0 = $(patsubst crt0/%.s, ${LIBDIR}/%.rel, ${SRCS_CRT0})
DEPS = $(patsubst %.rel, %.d, $(OBJS))
TARGETS = \
${OBJS_CRT0} \
${LIBDIR}/${NAME}.lib
SDCC = sdcc
SDAS = sdasz80
SDLD = sdld
SDAR = sdar
CFLAGS ?= --opt-code-size
CFLAGS += -mz80 -MMD
CFLAGS += -DNDEBUG --Werror
CFLAGS += -I include
LDFLAGS = --no-std-crt0 --code-loc ${ADDR_CODE} --data-loc ${ADDR_DATA}
build: ${TARGETS}
clean:
@rm -f ${TARGETS} ${OBJS} ${OBJS_CRT0} ${DEPS}
@rm -rf ${OBJDIR} ${BINDIR} ${LIBDIR}
@${MAKE} -s -C sample clean
@make BINDIR="$(abspath ${BINDIR})" -s -C tools clean
@make -s -C test clean
sample:
@${MAKE} -s -C sample
test:
@make -s -C test
tools:
@make BINDIR="$(abspath ${BINDIR})" -s -C tools
${LIBDIR}/%.rel: crt0/%.s
@${info [AS] $<}
@mkdir -p $(dir $@)
@${SDAS} -g -o $@ $<
${LIBDIR}/${NAME}.lib: ${OBJS}
@${info [AR] $@}
@mkdir -p $(dir $@)
@$(SDAR) cr $@ $^
${OBJDIR}/%.rel: ${SRCDIR}/%.c
@${info [C] $<}
@mkdir -p $(dir $@)
@${SDCC} ${CFLAGS} -o $@ -c $<
${OBJDIR}/%.rel: ${SRCDIR}/%.s
@${info [AS] $<}
@mkdir -p $(dir $@)
@${SDAS} -o $@ $<
-include $(DEPS)