Blame view

RIOT/boards/native/Makefile.include 4.71 KB
fb11e647   vrobic   reseau statique a...
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
  export NATIVEINCLUDES += -DNATIVE_INCLUDES
  export NATIVEINCLUDES += -I$(RIOTBOARD)/$(BOARD)/include/
  export NATIVEINCLUDES += -I$(RIOTBASE)/core/include/
  export NATIVEINCLUDES += -I$(RIOTBASE)/drivers/include/
  
  export CPU = native
  export ELF = $(BINDIR)/$(APPLICATION).elf
  
  USEMODULE += native-drivers
  
  # toolchain:
  export PREFIX =
  export CC ?= $(PREFIX)gcc
  export CXX ?= $(PREFIX)g++
  ifeq ($(LTO),1)
  export AR = $(PREFIX)gcc-ar
  else
  export AR = $(PREFIX)ar
  endif
  export AS ?= $(PREFIX)as
  export LINK ?= $(PREFIX)gcc
  export SIZE ?= $(PREFIX)size
  ifneq ($(shell uname -s),Darwin)
  export OBJCOPY ?= $(PREFIX)objcopy
  else
  ifeq (0,$(shell which gobjcopy 2>&1 > /dev/null ; echo $$?))
  export OBJCOPY ?= gobjcopy
  export OFLAGS ?= -O ihex
  else
  # If gobjcopy is not available, just create an empty file. The hexfile
  # is not used for native anyways.
  export OBJCOPY ?= touch
  export OFLAGS =
  endif
  endif
  
  ifeq ($(shell uname -s),Darwin)
  export DEBUGGER ?= lldb
  else
  export DEBUGGER ?= gdb
  endif
  export TERMPROG ?= $(ELF)
  export FLASHER = true
  export VALGRIND ?= valgrind
  export CGANNOTATE ?= cg_annotate
  export GPROF ?= gprof
  
  # basic cflags:
  export CFLAGS += -Wall -Wextra -pedantic -std=gnu99
  ifeq ($(shell uname -m),x86_64)
  export CFLAGS += -m32
  endif
  ifneq (,$(filter -DDEVELHELP,$(CFLAGS)))
  export CFLAGS += -fstack-protector-all
  endif
  ifeq ($(shell uname -s),FreeBSD)
  ifeq ($(shell uname -m),amd64)
  export CFLAGS += -m32 -DCOMPAT_32BIT -B/usr/lib32
  endif
  endif
  ifeq ($(shell uname -s),Darwin)
  export CFLAGS += -Wno-deprecated-declarations
  endif
  
  # unwanted (CXXUWFLAGS) and extra (CXXEXFLAGS) flags for c++
  export CXXUWFLAGS +=
  export CXXEXFLAGS +=
  
  ifeq ($(shell uname -m),x86_64)
  export LINKFLAGS += -m32
  endif
  ifeq ($(shell uname -s),FreeBSD)
  ifeq ($(shell uname -m),amd64)
  export LINKFLAGS += -m32 -DCOMPAT_32BIT -L/usr/lib32 -B/usr/lib32
  endif
  export LINKFLAGS += -L $(BINDIR)
  else
  export LINKFLAGS += -ldl
  endif
  
  # clean up unused functions
  export CFLAGS += -ffunction-sections -fdata-sections
  ifeq ($(shell uname -s),Darwin)
  export LINKFLAGS += -Wl,-dead_strip
  else
  export LINKFLAGS += -Wl,--gc-sections
  endif
  export LINKFLAGS += -ffunction-sections
  
  # set the tap interface for term/valgrind
  ifneq (,$(filter netdev_default gnrc_netdev_default,$(USEMODULE)))
  	export PORT ?= tap0
  else
  	export PORT =
  endif
  
  export TERMFLAGS := $(PORT) $(TERMFLAGS)
  
  export ASFLAGS =
  ifeq ($(shell basename $(DEBUGGER)),lldb)
  export DEBUGGER_FLAGS = -- $(ELF) $(TERMFLAGS)
  else
  export DEBUGGER_FLAGS = -q --args $(ELF) $(TERMFLAGS)
  endif
  term-valgrind: export VALGRIND_FLAGS ?= \
  	--leak-check=full \
  	--track-origins=yes \
  	--fullpath-after=$(RIOTBASE)/ \
  	--read-var-info=yes
  debug-valgrind-server: export VALGRIND_FLAGS ?= --vgdb=yes --vgdb-error=0 -v \
  	--leak-check=full --track-origins=yes --fullpath-after=${RIOTBASE} \
  	--read-var-info=yes
  term-cachegrind: export CACHEGRIND_FLAGS += --tool=cachegrind
  term-gprof: export TERMPROG = GMON_OUT_PREFIX=gmon.out $(ELF)
  all-valgrind: export CFLAGS += -DHAVE_VALGRIND_H -g
  all-valgrind: export NATIVEINCLUDES += $(shell pkg-config valgrind --cflags)
  all-debug: export CFLAGS += -g
  all-cachegrind: export CFLAGS += -g
  all-gprof: export CFLAGS += -pg
  all-gprof: export LINKFLAGS += -pg
  all-asan: export CFLAGS += -fsanitize=address -fno-omit-frame-pointer -g
  all-asan: export CFLAGS += -DNATIVE_IN_CALLOC
  all-asan: export LINKFLAGS += -fsanitize=address -fno-omit-frame-pointer -g
  
  export INCLUDES += $(NATIVEINCLUDES)
  
  export CFLAGS += -DDEBUG_ASSERT_VERBOSE
  
  # workaround for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52624
  ifneq ($(shell gcc --version | head -1 | grep -E ' (4.6|4.7)'),)
  	export CFLAGS += -DHAVE_NO_BUILTIN_BSWAP16
  endif
  
  # backward compatability with glibc <= 2.17 for native
  ifeq ($(CPU),native)
  ifeq ($(shell uname -s),Linux)
  ifeq ($(shell ldd --version |  awk '/^ldd/{if ($$NF < 2.17) {print "yes"} else {print "no"} }'),yes)
  	LINKFLAGS += -lrt
  endif
  endif
  endif
  
  # clumsy way to enable building native on osx:
  BUILDOSXNATIVE = 0
  ifeq ($(CPU),native)
  ifeq ($(shell uname -s),Darwin)
  	BUILDOSXNATIVE = 1
  endif
  endif
  
  all: # do not override first target
  
  all-debug: all
  
  all-gprof: all
  
  all-asan: all
  
  all-valgrind: all
  
  all-cachegrind: all
  
  term-valgrind:
  	$(VALGRIND) $(VALGRIND_FLAGS) $(ELF) $(PORT)
  
  debug-valgrind-server:
  	$(VALGRIND) $(VALGRIND_FLAGS) $(ELF) $(PORT)
  
  debug-valgrind:
  	$(eval VALGRIND_PID ?= $(shell pgrep -n memcheck-x86-li -u ${USER} | cut -d" " -f1))
  	$(eval DEBUGGER_FLAGS := -ex "target remote | vgdb --pid=${VALGRIND_PID}" $(DEBUGGER_FLAGS))
  	$(DEBUGGER) $(DEBUGGER_FLAGS)
  
  term-cachegrind:
  	$(VALGRIND) $(CACHEGRIND_FLAGS) $(ELF) $(PORT)
  
  term-gprof: term
  
  eval-gprof:
  	$(GPROF) $(ELF) $(shell ls -rt gmon.out* | tail -1)
  
  eval-cachegrind:
  	$(CGANNOTATE) $(shell ls -rt cachegrind.out* | tail -1)
  
  export UNDEF += $(BINDIR)/cpu/startup.o