forked from RebelTechnology/OwlProgram
-
Notifications
You must be signed in to change notification settings - Fork 0
/
native.mk
95 lines (79 loc) · 2.9 KB
/
native.mk
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
ifeq ($(CONFIG),Debug)
CPPFLAGS ?= -g -O0 -Wall -Wcpp -Wunused-function -DDEBUG -DUSE_FULL_ASSERT
endif
ifeq ($(CONFIG),Release)
CPPFLAGS ?= -Os -ffast-math
endif
BUILDROOT ?= .
BUILD ?= $(BUILDROOT)/Build
PATCHSOURCE ?= $(BUILDROOT)/PatchSource
SOURCE = $(BUILDROOT)/Source
LIBSOURCE = $(BUILDROOT)/LibSource
BUILDSOURCE = $(BUILD)/Source
TESTPATCHES = $(BUILDROOT)/TestPatches
DSPINC = $(BUILDROOT)/Libraries/CMSIS/DSP/Include
DSPLIB = $(BUILDROOT)/Libraries/CMSIS/DSP/Source
CPPFLAGS += -I$(SOURCE)
CPPFLAGS += -I$(PATCHSOURCE)
CPPFLAGS += -I$(LIBSOURCE)
CPPFLAGS += -I$(BUILDSOURCE)
CPPFLAGS += -I$(TESTPATCHES)
CPPFLAGS += -I$(DSPINC)
CPPFLAGS += -ILibraries -ILibraries/KissFFT
CPPFLAGS += -D__PROGRAM_START=1 # prevent compilation of __cmsis_start function
CXXFLAGS = -std=gnu++17
LDLIBS = -lm
LDFLAGS = -Wl,--gc-sections
# Tools
CC=$(TOOLROOT)gcc
LD=$(TOOLROOT)gcc
AR=$(TOOLROOT)ar
AS=$(TOOLROOT)as
NM=$(TOOLROOT)nm
CXX=$(TOOLROOT)g++
GDB=$(TOOLROOT)gdb
SIZE=$(TOOLROOT)size
RANLIB=$(TOOLROOT)ranlib
OBJCOPY=$(TOOLROOT)objcopy
OBJDUMP=$(TOOLROOT)objdump
# Uncomment lines below to build in 32-bit mode
# include $(BUILDROOT)/libs.mk
# CPPFLAGS += -ILibraries/CMSIS/Include
# CPPFLAGS += -DARM_MATH_CM0
# CPPFLAGS += -fno-builtin -ffreestanding -m32
# C_SRC += $(DSPLIB)/TransformFunctions/arm_bitreversal.c
include $(BUILDROOT)/sources.mk
C_SRC += Libraries/KissFFT/kiss_fft.c
C_SRC += $(wildcard $(BUILDSOURCE)/*.c)
CPP_SRC += $(wildcard $(BUILDSOURCE)/*.cpp)
C_SRC += $(wildcard $(PATCHSOURCE)/*.c)
CPP_SRC += $(wildcard $(PATCHSOURCE)/*.cpp)
ifdef MAXIMILIAN
CPP_SRC := $(filter-out $(PATCHSOURCE)/$(MAXIMILIAN).cpp, $(CPP_SRC))
endif
# Set up search path
OBJS = $(addprefix $(BUILD)/Test/,$(notdir $(C_SRC:.c=.o)))
OBJS += $(addprefix $(BUILD)/Test/,$(notdir $(CPP_SRC:.cpp=.o)))
vpath %.c $(sort $(dir $(C_SRC)))
vpath %.cpp $(sort $(dir $(CPP_SRC)))
vpath %.cpp $(SOURCE) $(LIBSOURCE) $(BUILDSOURCE)
vpath %.c $(SOURCE) $(LIBSOURCE) $(BUILDSOURCE)
.PHONY: native run test
native: $(TESTPATCHES)/PatchRun.cpp $(DEPS) $(OBJS)
@$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(TESTPATCHES)/PatchRun.cpp -I$(BUILD) $(OBJS) -o $(BUILD)/Test/patch
echo Built $(PATCHNAME) native executable in $(BUILD)/Test/patch
run: native
@$(BUILD)/Test/patch
grind: native
valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes $(BUILD)/Test/patch
test: $(TESTPATCHES)/PatchTest.cpp $(DEPS) $(OBJS)
@$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(TESTPATCHES)/PatchTest.cpp -I$(BUILD) $(OBJS) -o $(BUILD)/Test/$@
@$(BUILD)/Test/$@
# compile and generate dependency info
$(BUILD)/Test/%.o: %.c
@$(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
@$(CC) -MM -MT"$@" $(CPPFLAGS) $(CFLAGS) $< > $(@:.o=.d)
$(BUILD)/Test/%.o: %.cpp
@$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@
@$(CXX) -MM -MT"$@" $(CPPFLAGS) $(CXXFLAGS) $< > $(@:.o=.d)
-include $(OBJS:.o=.d) $(SOLO_OBJS:.o=.d) $(MULTI_OBJS:.o=.d)