-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
101 lines (73 loc) · 2.62 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
.SUFFIXES:
# Sources and defines
TARGET := $(notdir $(CURDIR))
BUILD := build
INCLUDES := include lodepng tex3ds/include
SOURCES := source lodepng tex3ds/source
DEFINES := -DLODEPNG_NO_COMPILE_DISK -D_GNU_SOURCE
# Compiler settings
ARCH :=
CFLAGS := $(ARCH) -std=c11 -O2 -g -fstrict-aliasing -ffunction-sections \
-Wall -Wextra -Wstrict-aliasing=3
CXXFLAGS := $(ARCH) -std=c++14 -O2 -g -fstrict-aliasing -ffunction-sections \
-Wall -Wextra -Wstrict-aliasing=3
ASFLAGS := $(ARCH) -O2 -g -x assembler-with-cpp
ARFLAGS := -rcs
LDFLAGS := $(ARCH) -O2 -s -static -ffunction-sections -Wl,--gc-sections
PREFIX :=
CC := $(PREFIX)gcc
CXX := $(PREFIX)g++
AS := $(PREFIX)gcc
AR := $(PREFIX)gcc-ar
# Do not change anything after this
ifneq ($(BUILD),$(notdir $(CURDIR)))
export OUTPUT := $(CURDIR)/$(TARGET)
export VPATH := $(foreach dir,$(DATA),$(CURDIR)/$(dir)) \
$(foreach dir,$(SOURCES),$(CURDIR)/$(dir))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
ifeq ($(strip $(CPPFILES)),)
export LD := $(CC)
else
export LD := $(CXX)
endif
export OFILES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) -I$(CURDIR)/$(BUILD)
.PHONY: $(BUILD) clean release
$(BUILD):
@[ -d $@ ] || mkdir -p $@
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
clean:
@echo clean ...
@rm -rf $(BUILD) $(TARGET)
release:
@[ -d $(BUILD) ] || mkdir -p $(BUILD)
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile NO_DEBUG=1
else
ifneq ($(strip $(NO_DEBUG)),)
DEFINES += -DNDEBUG
endif
VERS_STRING := $(shell git describe --tags --match v[0-9]* --abbrev=8 | sed 's/-[0-9]*-g/-/i')
VERS_MAJOR := $(shell echo "$(VERS_STRING)" | sed 's/v\([0-9]*\)\..*/\1/i')
VERS_MINOR := $(shell echo "$(VERS_STRING)" | sed 's/.*\.\([0-9]*\).*/\1/')
DEFINES += -DVERS_STRING=\"$(VERS_STRING)\"
DEFINES += -DVERS_MAJOR=$(shell echo "$(VERS_STRING)" | sed 's/v\([0-9]*\)\..*/\1/i')
DEFINES += -DVERS_MINOR=$(shell echo "$(VERS_STRING)" | sed 's/.*\.\([0-9]*\).*/\1/')
# Main target
$(OUTPUT): $(OFILES)
$(LD) $(LDFLAGS) $(OFILES) $(LIBPATHS) $(LIBS) -o $@
@echo built ... $(notdir $@)
%.o: %.cpp
@echo $(notdir $<)
$(CXX) $(CXXFLAGS) $(DEFINES) $(INCLUDE) -c $< -o $@
%.o: %.c
@echo $(notdir $<)
$(CC) $(CFLAGS) $(DEFINES) $(INCLUDE) -c $< -o $@
%.o: %.s
@echo $(notdir $<)
$(AS) $(ASFLAGS) $(DEFINES) $(INCLUDE) -c $< -o $@
%.a:
@echo $(notdir $@)
$(AR) $(ARFLAGS) $@ $^
endif