forked from jks-prv/Beagle_SDR_GPS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.comp.inc
186 lines (166 loc) · 6.11 KB
/
Makefile.comp.inc
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#
# The '/etc/dogtag' file is present on the Beagle and not on the dev machine.
# Grep returns 0 if "Debian" is found in /etc/dogtag, 1 if it isn't and 2 if /etc/dogtag doesn't exist.
# This same mechanism is used in the wrapper shell script (./k) because device tree files need to be
# loaded only on the Beagle.
#
DEBIAN_DEVSYS = $(shell grep -q -s Debian /etc/dogtag; echo $$?)
#double check for RPI
ifeq ($(DEBIAN_DEVSYS),2)
DEBIAN_DEVSYS = $(shell grep -q -s dtparam /boot/config.txt; echo $$?)
endif
DEBIAN = 0
NOT_DEBIAN = 1
DEVSYS = 2
UNAME = $(shell uname)
SYS = $(shell uname -r)
SYS_MAJ = $(shell uname -r | awk '{print $1}' | cut -d. -f1)
SYS_MIN = $(shell uname -r | awk '{print $1}' | cut -d. -f2)
COMPILE_HOST = $(shell hostname)
################################
# compiler/option selection
################################
VIS_OPT =
VIS_UNOPT =
BUILD_OBJ = $(BUILD_DIR)/kiwi.bin
CFLAGS += -g -pipe -MMD -DCOMPILE_HOST=STRINGIFY\($(COMPILE_HOST)\)
#CFLAGS_UNSAFE_OPT = -fcx-limited-range -funsafe-math-optimizations
CFLAGS_UNSAFE_OPT = -funsafe-math-optimizations
# devsys
ifeq ($(DEBIAN_DEVSYS),$(DEVSYS))
ifeq ($(XC),-DXC)
# Headers+libraries from a KiwiSDR are needed for cross-compilation with clang
# For this mount the KiwiSDR's root file system:
# sshfs -o ro,follow_symlinks,auto_cache,reconnect root@kiwisdr:/ ${HOME}/mnt
KIWI_XC_REMOTE_FS ?= ${HOME}/mnt
# nfs doesn't see special files in /proc, so assume BBAI if running Debian 9
HAS_PROC = $(shell test -d $(KIWI_XC_REMOTE_FS)/proc/device-tree && echo true)
ifeq ($(HAS_PROC),true)
BBAI = $(shell cat $(KIWI_XC_REMOTE_FS)/proc/device-tree/model | grep -q -s "BeagleBone AI" && echo true)
RPI = $(shell cat $(KIWI_XC_REMOTE_FS)/proc/device-tree/model | grep -q -s "Raspberry Pi 3" && echo true)
else
BBAI = $(shell cat $(KIWI_XC_REMOTE_FS)/etc/debian_version | grep -q -s "9\." && echo true)
RPI = $(shell cat $(KIWI_XC_REMOTE_FS)/etc/os-release | grep -q -s "raspbian" && echo true)
endif
DEBIAN_7 = $(shell cat $(KIWI_XC_REMOTE_FS)/etc/debian_version | grep -q -s "7\." && echo true)
CC = clang
CPP = clang++
CPP_FLAGS += -std=gnu++11
CFLAGS += --target=armv7a-linux-gnueabihf
CFLAGS += -mfpu=neon
CFLAGS += -mfloat-abi=hard
CFLAGS += --sysroot=$(KIWI_XC_REMOTE_FS)
CFLAGS += -I$(KIWI_XC_REMOTE_FS)/usr/include/c++/4.9
CFLAGS += -I$(KIWI_XC_REMOTE_FS)/usr/include/arm-linux-gnueabihf/c++/4.9
CFLAGS += -DHOST
VIS_OPT = -Ofast
KIWI_XC_LD ?= lld
LDFLAGS += -fuse-ld=$(KIWI_XC_LD)
LDFLAGS += -v
LDFLAGS += --sysroot=$(KIWI_XC_REMOTE_FS)
LDFLAGS += --target=armv7a-linux-gnueabihf
LDFLAGS += -L$(KIWI_XC_REMOTE_FS)/usr/lib/arm-linux-gnueabihf
LDFLAGS += -L$(KIWI_XC_REMOTE_FS)/usr/local/lib/
ifeq ($(RPI),true)
CFLAGS += -mtune=cortex-a53 -mcpu=cortex-a53
else
CFLAGS += -mtune=cortex-a8 -mcpu=cortex-a8
endif
else
# make the compiles fast on dev system (but don't do this with cross-compiling case above)
OPT = 0
CFLAGS += -DDEVSYS
ifeq ($(UNAME),Darwin)
CC = clang
CPP = clang++
CPP_FLAGS += -std=gnu++11
else
# try clang on your development system (if you have it) -- it's better
#CC = clang
#CPP = clang++
CC = gcc
CPP = g++
endif
endif
endif
# Debian target
ifeq ($(DEBIAN_DEVSYS),$(DEBIAN))
#CFLAGS += -mfloat-abi=softfp -mfpu=neon
CFLAGS += -mfpu=neon -mfloat-abi=hard
CFLAGS += -DHOST
BBAI = $(shell cat /proc/device-tree/model | grep -q -s "BeagleBone AI" && echo true)
RPI = $(shell cat /proc/device-tree/model | grep -q -s "Raspberry Pi 3" && echo true)
DEBIAN_7 = $(shell cat /etc/debian_version | grep -q -s "7\." && echo true)
ifeq ($(DEBIAN_7),true)
# clang 3.0 available on Debian 7.9 doesn't work
CC = gcc
CPP = g++
CFLAGS += -DKIWI_DEBIAN7
CFLAGS += -mtune=cortex-a8 -mcpu=cortex-a8
VIS_OPT = -O3
# needed for iq_display.cpp et al (-std=gnu++11 isn't available on Debian 7.9)
CPP_FLAGS += -std=gnu++0x
else ifeq ($(BBAI),true)
#PROFILING = true
PROFILING = false
ifeq ($(PROFILING),true)
CC = gcc
CPP = g++
CFLAGS += -pg -fprofile-arcs -ftest-coverage
LDFLAGS += -pg -lgcov --coverage
VIS_OPT =
BUILD_OBJ = ./kiwi.bin
else
CC = clang-7
CPP = clang++-7
VIS_OPT = -Ofast
endif
CFLAGS += -mtune=cortex-a8 -mcpu=cortex-a8
# needed for iq_display.cpp et al
CPP_FLAGS += -std=gnu++11
# clang still used by other things (e_cpu etc)
CMD_DEPS_DEBIAN = /usr/bin/clang-7
else ifeq ($(RPI),true)
CMD_DEPS_DEBIAN = /usr/bin/clang-7
CC = clang-7
CPP = clang++-7
VIS_OPT = -Ofast
CFLAGS += -mtune=cortex-a53 -mcpu=cortex-a53
# needed for iq_display.cpp et al
CPP_FLAGS += -std=gnu++11
else
CMD_DEPS_DEBIAN = /usr/bin/clang-6.0
CFLAGS += -mtune=cortex-a8 -mcpu=cortex-a8
CC = clang-6.0
CPP = clang++-6.0
#CC = clang
#CPP = clang++
VIS_OPT = -Ofast
# needed for iq_display.cpp et al
CPP_FLAGS += -std=gnu++11
endif
endif
# To use clang address sanitizer build with "make ASAN=1 [OPT=0]" on target.
# There are shell aliases "masan" and "masan0" for these.
# Use gdb "asan" alias to set breakpoint necessary to backtrace address errors.
ifeq ($(ASAN),1)
ifeq ($(OPT),0)
VIS_OPT = -fsanitize=address
VIS_UNOPT = -fsanitize=address
else
VIS_OPT += -fsanitize=address
VIS_UNOPT += -fsanitize=address
endif
CFLAGS += -fno-omit-frame-pointer
#LDFLAGS += -v -fsanitize=address,leak
#LDFLAGS += -fsanitize=address,leak
LDFLAGS += -fsanitize=address
endif
# static analyzer (NB: different from address sanitizer "asan")
# build on devsys or target with "make SAN=1" using alias "msan"
# uses -O0 for speedup when used on target (clang on Debian seems to catch more errors than on OSX)
ifeq ($(SAN),1)
CPP_FLAGS += -O0 -Werror --analyze -DKIWI_STATIC_ANALYSIS
OPT = 0
VIS_OPT =
endif