-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
111 lines (84 loc) · 3.84 KB
/
makefile
File metadata and controls
111 lines (84 loc) · 3.84 KB
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
## COPYRIGHT (C) HARRY CLARK 2025
## HITACHI SUPERH INSTRUCTION DECODER
#####################################
## PREFIXES
#####################################
CC := gcc
CXX := g++
AR := ar
IINC := -I inc
IINC_XX := -I cplusplus/inc -I inc
CSTD := --std=c99
CXX_STD := --std=c++17
CFLAGS := -fPIC -fno-common
CXXFLAGS := -fPIC -fno-common
LDFLAGS :=
LDXXFLAGS := -Lbuild -lcath -Wl,-rpath,'$$ORIGIN'
WARNINGS := -Wall -Wextra -Wno-format-extra-args -Wpedantic -Wunused-value -Wunused-parameter -Wformat-zero-length -O0
#####################################
## DIRECTORIES
#####################################
SRC_DIR := src
TABLES_DIR := inc/tables
C_FILES := $(wildcard $(SRC_DIR)/*.c) \
$(wildcard $(SRC_DIR)/*/*.c) \
$(wildcard $(SRC_DIR)/*/*/*.c) \
$(wildcard $(TABLES_DIR)/*.c)
H_FILES := $(wildcard inc/*.h) \
$(wildcard inc/enums/*.h) \
$(wildcard inc/instructions/*.h) \
$(wildcard inc/tables/*.h)
INC_FILES := $(wildcard inc/tables/*.inc)
O_FILES := $(patsubst $(SRC_DIR)/%.c,build/%.o,$(filter $(SRC_DIR)/%.c,$(C_FILES))) \
$(patsubst $(SRC_DIR)/%,build/%,$(patsubst %.c,%.o,$(filter $(SRC_DIR)/%/*.c,$(C_FILES)))) \
$(patsubst $(SRC_DIR)/%,build/%,$(patsubst %.c,%.o,$(filter $(SRC_DIR)/*/*/*.c,$(C_FILES)))) \
$(patsubst $(TABLES_DIR)/%.c,build/tables_%.o,$(filter $(TABLES_DIR)/%.c,$(C_FILES)))
SRCX_DIR := cplusplus/src
CXX_FILES := $(wildcard $(SRCX_DIR)/*.cpp) $(wildcard $(SRCX_DIR)/*/*.cpp)
HXX_FILES := $(wildcard cplusplus/inc/*.hpp) \
$(wildcard cplusplus/inc/instructions/*.hpp) \
$(wildcard cplusplus/inc/enums/*.hpp)
OXX_FILES := $(patsubst $(SRCX_DIR)/%.cpp,build/cxx/%.o,$(CXX_FILES))
TESTS_DIR := tests
TESTS_C := $(wildcard $(TESTS_DIR)/*.c)
TEST_BINS := $(patsubst $(TESTS_DIR)/%.c,build/tests/%,$(TESTS_C))
#####################################
## TARGETS
#####################################
.PHONY: all clean dirs cxx tests
all: dirs build/libcath.a build/libcath.so build/catherine
cxx: dirs build/libcath.a build/libcath.so build/cathcxx
dirs:
@mkdir -p build/instructions
@mkdir -p build/instructions/DSP
@mkdir -p build/cxx/instructions
@mkdir -p build/tests
tests: dirs build/libcath.a $(TEST_BINS)
build/%.o: $(SRC_DIR)/%.c $(H_FILES) $(INC_FILES)
$(CC) -c $(CSTD) $(IINC) $(WARNINGS) $(CFLAGS) -o $@ $<
build/instructions/%.o: $(SRC_DIR)/instructions/%.c $(H_FILES) $(INC_FILES)
$(CC) -c $(CSTD) $(IINC) $(WARNINGS) $(CFLAGS) -o $@ $<
build/tables_%.o: $(TABLES_DIR)/%.c $(H_FILES) $(INC_FILES)
$(CC) -c $(CSTD) $(IINC) $(WARNINGS) $(CFLAGS) -o $@ $<
build/instructions/DSP/%.o: $(SRC_DIR)/instructions/DSP/%.c $(H_FILES) $(INC_FILES)
$(CC) -c $(CSTD) $(IINC) $(WARNINGS) $(CFLAGS) -o $@ $<
build/cxx/%.o: $(SRCX_DIR)/%.cpp $(HXX_FILES)
@mkdir -p $(dir $@)
$(CXX) -c $(CXX_STD) $(IINC_XX) $(WARNINGS) $(CXXFLAGS) -o $@ $<
build/cxx/instructions/%.o: $(SRCX_DIR)/instructions/%.cpp $(HXX_FILES)
@mkdir -p $(dir $@)
$(CXX) -c $(CXX_STD) $(IINC_XX) $(WARNINGS) $(CXXFLAGS) -o $@ $<
build/libcath.a: $(O_FILES)
$(AR) rcs $@ $^
build/libcath.so: build/libcath.a
$(CC) -shared -o $@ -Wl,--whole-archive $< -Wl,--no-whole-archive
build/libcathcxx.a: $(OXX_FILES)
$(AR) rcs $@ $^
build/catherine: $(O_FILES)
$(CC) $^ $(LDFLAGS) -o $@
build/cathcxx: $(OXX_FILES) build/libcath.a
$(CXX) $(OXX_FILES) $(LDXXFLAGS) -o $@
build/tests/%: $(TESTS_DIR)/%.c build/libcath.a
$(CC) $(CSTD) $(IINC) $(WARNINGS) $(CFLAGS) $< -Lbuild -lcath -o $@
clean:
rm -rf build