forked from shared-ptr/sh_insns
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
103 lines (77 loc) · 1.8 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
ifneq ($(VERBOSE),true)
QUIET:=@
endif
# compiler options
ifndef CC
CC:=gcc
endif
ifndef CXX
CXX:=g++
endif
ifndef CPP_STANDARD
CPP_STANDARD:=-std=c++17
endif
ifndef C_STANDARD
C_STANDARD:=-std=c11
endif
# set CFLAGS
ifdef FLAGS
CFLAGS=$(FLAGS)
endif
ifdef DEFINES
CFLAGS += $(foreach var, $(DEFINES),-D$(var))
else # else use default options
endif
ifeq (,$(findstring -DLOCALE=,$(CFLAGS)))
CFLAGS += -DLOCALE=US
endif
ifndef SOURCE_PATH
SOURCE_PATH=.
endif
ifndef BUILD_PATH
BUILD_PATH=$(SOURCE_PATH)/bin
endif
# define what to build
ifndef BINARY
BINARY=sh_insns
endif
SOURCES = \
sh_insns.cpp \
build_instructions.cpp \
post_processing.cpp
OBJS := $(SOURCES:.s=.o)
OBJS := $(OBJS:.c=.o)
OBJS := $(OBJS:.cpp=.o)
OBJS := $(foreach f,$(OBJS),$(BUILD_PATH)/$(f))
SOURCES := $(foreach f,$(SOURCES),$(SOURCE_PATH)/$(f))
# !!! FIXME: Get -Wall in here, some day.
#CFLAGS += -w -fno-builtin -fno-strict-aliasing -fno-operator-names -fno-rtti -ffreestanding
# includes ...
.PHONY: all OUTPUT_DIR
$(BUILD_PATH)/%.o: $(SOURCE_PATH)/%.c
@echo [Compiling]: $<
$(QUIET) $(CC) -c -o $@ $< $(C_STANDARD) $(CFLAGS)
$(BUILD_PATH)/%.o: $(SOURCE_PATH)/%.s
@echo [Assembling]: $<
$(QUIET) $(CC) $(CPP_STANDARD) $(CFLAGS) -DELF -x assembler-with-cpp -o $@ -c $<
$(BUILD_PATH)/%.o: $(SOURCE_PATH)/%.cpp
@echo [Compiling]: $<
$(QUIET) $(CXX) -c -o $@ $< $(CPP_STANDARD) $(CFLAGS)
$(BUILD_PATH)/%.a: $(SOURCE_PATH)/%.a
cp $< $@
ranlib $@
$(BINARY): OUTPUT_DIR $(OBJS)
@echo [ Linking ]: $@
$(QUIET) $(CXX) -o $@ $(OBJS) $(LDFLAGS) $(CPP_STANDARD)
index.html: $(BINARY)
@echo [ Writing Output ]: $@
$(QUIET) ./$(BINARY) > $@
html: index.html $(BINARY)
@echo [ DONE ]
OUTPUT_DIR:
@echo -n "Creating build directory"
$(QUIET) mkdir -p $(BUILD_PATH)
@echo " DONE."
clean:
rm -f $(BINARY)
rm -rf $(BUILD_PATH)