forked from contiki-os/contiki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.include
973 lines (792 loc) · 28.9 KB
/
Makefile.include
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
# -*- makefile -*-
# Set CONTIKI to the directory where Makefile.include resides.
CONTIKI ?= $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST))))
# Give an error message when using an old version of GNU Make.
MAKE_MAJOR_VERSION := $(word 1,$(subst ., ,$(MAKE_VERSION)))
ifeq ($(shell test $(MAKE_MAJOR_VERSION) -lt 4; echo $$?),0)
$(error GNU Make version 4.0 or newer is required)
endif
# Only use rules from the Makefiles. This eliminates a lot
# of attempted matches from the implicit rules for SCCS.
MAKEFLAGS += --no-builtin-rules
# Despite --no-builtin-rules, make insists on "remaking" the included
# Makefiles, so disable that with these empty rules. This saves 200+ lines
# of rule matching on "make -d TARGET=native" on hello-world.
Makefile: ;
Makefile.%: ;
# The target logic makes all build artifacts implicit, prevent make from
# removing object files upon build completion.
.SECONDARY:
### Include a helper Makefile that creates variables for all Contiki-NG path
### locations.
include $(CONTIKI)/Makefile.dir-variables
# Enable Werror by default. To disable from command line, use make WERROR=0.
# Setting this option is also important for tests on Cooja motes to check for warnings.
WERROR ?= 1
# Disable Clang by default.
CLANG ?= 0
include $(CONTIKI)/Makefile.identify-target
### Include Makefile.tools to pull in targets that allow us to build tools dir
include $(CONTIKI)/Makefile.tools
ifeq ($(DEFINES),)
-include Makefile.$(TARGET).defines
ifneq ($(DEFINES),)
${info using saved defines '$(DEFINES)'}
endif
endif
ifndef HOST_OS
ifeq ($(OS),Windows_NT)
## TODO: detect more specific Windows set-ups,
## e.g. CygWin, MingW, VisualC, Watcom, Interix
HOST_OS := Windows
else
HOST_OS := $(shell uname)
endif
endif
# Display more build information when running in CI, less when quiet.
ifeq ($(CI),true)
V = 1
else ifeq ($(QUIET),1)
V = 1
Q = @
endif
ifneq (, $(shell which ccache))
CCACHE ?= ccache
endif
# Command converting lowercase to uppercase, and "-" and "/" to "_".
UPPERCASE_CMD = tr '[:lower:][\-/]' '[:upper:][__]'
COMMA := ,
COOJA_PATH ?= $(CONTIKI_NG_TOOLS_DIR)/cooja
JAVA = java
GRADLE = $(COOJA_PATH)/gradlew
BUILD_DIR = build
BUILD_DIR_TARGET = $(BUILD_DIR)/$(TARGET)
BUILD_DIR_TARGET_BOARD = $(BUILD_DIR_TARGET)/$(BOARD)
# If BOARD was empty, make sure we don't end up with a sequence of slashes
BUILD_DIR_FULL = $(BUILD_DIR_TARGET_BOARD:/=)/$(BUILD_DIR_CONFIG)
# Ditto if BUILD_DIR_CONFIG was empty
BUILD_DIR_BOARD = $(BUILD_DIR_FULL:/=)
GENDIR = $(BUILD_DIR_BOARD)/gen
OBJECTDIR = $(BUILD_DIR_BOARD)/obj
ifdef OBJECTVARIANT
# provide suffix to obj dir, so that we can different variantsin same target of build
OBJECTDIR = $(BUILD_DIR_BOARD)/obj.$(OBJECTVARIANT)
else
OBJECTDIR = $(BUILD_DIR_BOARD)/obj
endif
DEPDIR = $(OBJECTDIR)/.deps
TARGET_UPPERCASE := ${shell echo $(TARGET) | $(UPPERCASE_CMD)}
CFLAGS += -DCONTIKI=1 -DCONTIKI_TARGET_$(TARGET_UPPERCASE)=1
CFLAGS += -DCONTIKI_TARGET_STRING=\"$(TARGET)\"
# try it for cleanup unused code
ifneq ("$(RELEASE)","")
CFLAGS += -ffunction-sections
CFLAGS += -fdata-sections
LDFLAGS+= -Wl,-gc-sections,--cref
# turn off asserts
CFLAGS += -DNDEBUG
endif
ifdef NDEBUG
# turn off asserts
CFLAGS += -DNDEBUG
endif
ifdef GCCTEMPS
CFLAGS += -save-temps=obj -dD
endif
LDFLAGS_WERROR ?= -Wl,--fatal-warnings
#CFLAGS_WERROR += -Wno-error=unused-const-variable
CFLAGS_WERROR += -Wno-error=unused-function -Wno-error=unused-variable
CFLAGS_WERROR += -Wno-error=unused-but-set-variable
CFLAGS_WERROR += -Wno-error=array-bounds
#some code use pragma "warning". this code warns anyway, but still need compiles
CFLAGS += -Wno-error=unknown-pragmas
ifneq ("$(DEBUG)","")
CFLAGS += -g3
endif
ifeq ($(WERROR),1)
LDFLAGS += $(LDFLAGS_WERROR)
CFLAGS += $(CFLAGS_WERROR)
endif
MODULES += $(CONTIKI_NG_OS_DIR) $(CONTIKI_NG_ARCH_DIR)
MODULES += $(CONTIKI_NG_SYS_DIR) $(CONTIKI_NG_LIB_DIR) $(CONTIKI_NG_DEV_DIR)
#provide featured v/sprintf
MODULES += $(CONTIKI_NG_LIB_DIR)/dbg-io
MODULES += $(CONTIKI_NG_NET_DIR) $(CONTIKI_NG_ROUTING_DIR)
MODULES += $(CONTIKI_NG_MAC_DIR) $(CONTIKI_NG_MAC_DIR)/framer
MODULES += $(CONTIKI_NG_STORAGE_DIR) $(CONTIKI_NG_SERVICES_DIR)
# Automatically include project-conf.h if found
ifneq ("$(wildcard project-conf.h)","")
CFLAGS += -DPROJECT_CONF_PATH=\"project-conf.h\"
endif
define oname
${patsubst %.c,%.o, \
${patsubst %.cpp,%.o, \
${patsubst %.S,%.o, \
${patsubst %.s,%.o, \
$(1) \
}}}}
endef
# Rule to force rebuilds.
.PHONY: FORCE
FORCE:
uniq = $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1)))
# Identify if the target makefile is in-tree, or from $(TARGETDIRS).
# resolves list of pathes ($2) for prefix ($1):
# - prefix+path if exist
# - path if exist
# - prefix+path - if not exits path
resolvedir_prefix = ${foreach d, $(2), ${if ${wildcard $(1)$(d) } , $(1)$(d) , \
$(if ${wildcard $(d) } , $(d) , $(1)$(d) ) } }
target_makefile := $(wildcard $(CONTIKI_NG_RELOC_PLATFORM_DIR)/$(TARGET)/Makefile.$(TARGET) \
$(foreach TDIR, $(TARGETDIRS), $(TDIR)/$(TARGET)/Makefile.$(TARGET)))
# Ensure there is exactly one target makefile found.
ifeq ($(strip $(target_makefile)),)
${error The target platform "$(TARGET)" does not exist (maybe it was misspelled?)}
endif
ifneq (1, ${words $(target_makefile)})
${error More than one TARGET Makefile found: $(target_makefile)}
endif
# Include the target makefile.
$(info target make by $(target_makefile) )
include $(target_makefile)
ifneq ($(MAKECMDGOALS),clean)
ifeq ($(CLANG),1)
# Use GCC sysroot unless user specified something else.
ifndef SYSROOT
SYSROOT := $(shell $(CC) $(CFLAGS) --print-sysroot)
endif
# Default to the most recent Clang in Ubuntu.
CLANG_CC ?= clang-14
CC := $(CLANG_CC)
AS := $(CC)
LD := $(CC)
CFLAGS += $(CFLAGS_CLANG)
LDFLAGS += $(LDFLAGS_CLANG)
endif
# Validate the toolchain.
ifeq (, $(shell which $(CC)))
$(error Target "$(TARGET)" compiler "$(CC)" cannot be found)
endif
GCC_VERSION := $(shell $(CC) -dumpfullversion -dumpversion)
GCC_MAJOR_VERSION := $(word 1,$(subst ., ,$(GCC_VERSION)))
GCC_MINOR_VERSION := $(word 2,$(subst ., ,$(GCC_VERSION)))
# Warn if using version 6.3.x of arm-none-eabi-gcc
ifeq ("$(CC)","arm-none-eabi-gcc")
ifeq (6,$(GCC_MAJOR_VERSION))
ifeq (3,$(GCC_MINOR_VERSION))
$(warning Warning: $(CC) version 6.3.x may create broken Contiki-NG executables.)
$(warning We recommend to upgrade or downgrade your toolchain.)
endif
endif
endif
# Error if using 4.6.x or older msp430-gcc
ifeq ("$(CC)","msp430-gcc")
ifeq ($(shell test $(GCC_MAJOR_VERSION) -lt 5; echo $$?),0)
ifeq ($(shell test $(GCC_MINOR_VERSION) -lt 7; echo $$?),0)
$(error GCC 4.7 or later is required for MSP430.)
endif
endif
endif
endif
CP ?= cp
# Default to release builds.
DEBUG ?= 0
# Default to generate debug information for gdb. Targets can override this.
CFLAGS_DEBUG ?= -ggdb
ifeq ($(DEBUG),1)
CFLAGS += $(CFLAGS_DEBUG)
endif
# Configure link-time-optimization (LTO).
FLAGS_LTO ?= -flto
ifdef LTO
CFLAGS += $(FLAGS_LTO)
LDFLAGS += $(FLAGS_LTO)
ifdef NO_LTO_TARGET
PLATFORM_ACTION = skip
endif
endif
# Decide whether to build or to skip this target for this platform
ifneq ("", "$(PLATFORMS_ONLY)")
ifeq ("","$(filter $(TARGET), $(PLATFORMS_ONLY))")
PLATFORM_ACTION = skip
endif
endif
ifneq ("", "$(PLATFORMS_EXCLUDE)")
ifneq ("","$(filter $(TARGET), $(PLATFORMS_EXCLUDE))")
PLATFORM_ACTION = skip
endif
endif
ifneq ($(BOARD),)
ifneq ("", "$(BOARDS_ONLY)")
ifeq ("","$(filter $(BOARD), $(BOARDS_ONLY))")
PLATFORM_ACTION = skip
endif
endif
ifneq ("", "$(BOARDS_EXCLUDE)")
ifneq ("","$(filter $(BOARD), $(BOARDS_EXCLUDE))")
PLATFORM_ACTION = skip
endif
endif
endif # $(BOARD) not empty
PLATFORM_ACTION ?= build
$(BUILD_DIR):
$(TRACE_MKDIR)
$(Q)mkdir -p $@
$(DEPDIR): | $(BUILD_DIR)
$(TRACE_MKDIR)
$(Q)mkdir -p $@
# Provide path for *.map file
$(BUILD_DIR_BOARD): | $(BUILD_DIR)
$(TRACE_MKDIR)
$(Q)mkdir -p $@
# Provide way to create directories that have been removed by make clean.
$(OBJECTDIR) $(GENDIR): | $(BUILD_DIR) $(DEPDIR)
$(TRACE_MKDIR)
$(Q)mkdir -p $@
ifneq ($(BOARD),)
TARGET_BOARD_UPPERCASE := ${shell echo $(BOARD) | $(UPPERCASE_CMD)}
CFLAGS += -DCONTIKI_BOARD_$(TARGET_BOARD_UPPERCASE)=1
CFLAGS += -DCONTIKI_BOARD_STRING=\"$(BOARD)\"
endif
# Include IPv6, IPv4, and/or Rime
ifneq ($(MAKE_NET),)
HAS_STACK = 1
else
HAS_STACK = 0
endif
ifeq ($(CONTIKI_WITH_IPV4),1)
HAS_STACK = 1
MAKE_NET ?= MAKE_NET_IPV4
endif
ifeq ($(CONTIKI_WITH_RIME),1)
HAS_STACK = 1
MAKE_NET ?= MAKE_NET_RIME
endif
# Make IPv6 the default stack
ifeq ($(HAS_STACK),0)
ifneq ($(CONTIKI_WITH_IPV6),0)
$(info enable IPV6 by default)
CONTIKI_WITH_IPV6 ?= 1
endif
endif
ifeq ($(CONTIKI_WITH_IPV6),1)
MAKE_NET ?= MAKE_NET_IPV6
endif
ifeq ($(CONTIKI_WITH_RPL),1)
CFLAGS += -DUIP_CONF_IPV6_RPL=1
MAKE_ROUTING ?= MAKE_ROUTING_RPL_LITE
else ifeq ($(CONTIKI_WITH_RPL),0)
CFLAGS += -DUIP_CONF_IPV6_RPL=0
endif
# Configure MAC layer
# The different options
MAKE_MAC_NULLMAC = 0
MAKE_MAC_CSMA = 1
MAKE_MAC_TSCH = 2
MAKE_MAC_BLE = 3
MAKE_MAC_OTHER = 4
ifeq ($(MAKE_NET),MAKE_NET_NULLNET)
# Make NULLMAC the default MAC for NULLNET
MAKE_MAC ?= MAKE_MAC_NULLMAC
else
# Make CSMA the default MAC
MAKE_MAC ?= MAKE_MAC_CSMA
endif
ifeq ($(MAKE_MAC),MAKE_MAC_NULLMAC)
MODULES += $(CONTIKI_NG_MAC_DIR)/nullmac
CFLAGS += -DMAC_CONF_WITH_NULLMAC=1
endif
ifeq ($(MAKE_MAC),MAKE_MAC_CSMA)
MODULES += $(CONTIKI_NG_MAC_DIR)/csma
CFLAGS += -DMAC_CONF_WITH_CSMA=1
endif
ifeq ($(MAKE_MAC),MAKE_MAC_TSCH)
MODULES += $(CONTIKI_NG_MAC_DIR)/tsch
CFLAGS += -DMAC_CONF_WITH_TSCH=1
endif
ifeq ($(MAKE_MAC),MAKE_MAC_BLE)
MODULES += $(CONTIKI_NG_MAC_DIR)/ble
CFLAGS += -DMAC_CONF_WITH_BLE=1
endif
ifeq ($(MAKE_MAC),MAKE_MAC_OTHER)
CFLAGS += -DMAC_CONF_WITH_OTHER=1
endif
# Configure Network layer
MAKE_NET_NULLNET = 0
MAKE_NET_IPV6 = 1
MAKE_NET_OTHER = 2
MAKE_NET_IPV4 = 3
MAKE_NET_RIME = 4
# Make IPv6 the default stack
ifneq ($(CONTIKI_WITH_IPV6),0)
MAKE_NET ?= MAKE_NET_IPV6
else
MAKE_NET ?= MAKE_NET_NULLNET
endif
ifeq ($(MAKE_NET),MAKE_NET_NULLNET)
CFLAGS += -DNETSTACK_CONF_WITH_NULLNET=1
MODULES += $(CONTIKI_NG_NET_DIR)/nullnet
# SLIP uses the rxbuf defined in uIP.
MODULES_SOURCES_EXCLUDES += slip.c
CONTIKI_SOURCES_EXCLUDES_COOJA += slip-arch.c
CONTIKI_SOURCES_EXCLUDES_NATIVE += tun6-net.c
endif
ifeq ($(MAKE_NET),MAKE_NET_IPV6)
CFLAGS += -DNETSTACK_CONF_WITH_IPV6=1
MODULES += $(CONTIKI_NG_NET_DIR)/ipv6 $(CONTIKI_NG_NET_DIR)/ip
endif
ifeq ($(MAKE_NET),MAKE_NET_IPV4)
CFLAGS += -DNETSTACK_CONF_WITH_IPV4=1
MODULES += $(CONTIKI_NG_NET_DIR)/ipv4 $(CONTIKI_NG_NET_DIR)/ip
endif
ifeq ($(MAKE_NET),MAKE_NET_RIME)
CFLAGS += -DNETSTACK_CONF_WITH_RIME=1
MODULES += $(CONTIKI_NG_NET_DIR)/rime
endif
ifeq ($(MAKE_NET),MAKE_NET_OTHER)
CFLAGS += -DNETSTACK_CONF_WITH_OTHER=1
endif
ifeq ($(WITH_IP64),1)
MODULES += $(CONTIKI_NG_SERVICES_DIR)/ip64
endif
# Configure Routing protocol
MAKE_ROUTING_NULLROUTING = 0
MAKE_ROUTING_RPL_CLASSIC = 1
MAKE_ROUTING_RPL_LITE = 2
# Default routing protocol: RPL for IPv6, None otherwise
ifeq ($(MAKE_NET),MAKE_NET_IPV6)
MAKE_ROUTING ?= MAKE_ROUTING_RPL_LITE
else
MAKE_ROUTING ?= MAKE_ROUTING_NULLROUTING
endif
ifeq ($(MAKE_ROUTING),MAKE_ROUTING_RPL_CLASSIC)
CFLAGS += -DROUTING_CONF_RPL_CLASSIC=1
MODULES += $(CONTIKI_NG_ROUTING_DIR)/rpl-classic
else ifeq ($(MAKE_ROUTING),MAKE_ROUTING_RPL_LITE)
CFLAGS += -DROUTING_CONF_RPL_LITE=1
MODULES += $(CONTIKI_NG_ROUTING_DIR)/rpl-lite
else ifeq ($(MAKE_ROUTING),MAKE_ROUTING_NULLROUTING)
CFLAGS += -DROUTING_CONF_NULLROUTING=1
MODULES += $(CONTIKI_NG_ROUTING_DIR)/nullrouting
endif
### Include application makefiles
ifdef APPS
$(info apps: $(APPDS))
APPDS = ${wildcard ${foreach DIR, $(APPDIRS), ${addprefix $(DIR)/, $(APPS)}}} \
${wildcard ${addprefix $(CONTIKI)/apps/, $(APPS)} \
${addprefix $(OBJECTDIR)/apps/, $(APPS)} \
$(APPS)}
APPINCLUDES = ${foreach APP, $(APPS), ${wildcard ${foreach DIR, $(APPDS), $(DIR)/Makefile.$(APP)}}}
-include $(APPINCLUDES)
APP_SOURCES = ${foreach APP, $(APPS), $($(APP)_src)}
DSC_SOURCES = ${foreach APP, $(APPS), $($(APP)_dsc)}
CONTIKI_SOURCEFILES += $(APP_SOURCES) $(DSC_SOURCES)
endif
ifdef MODULES
MODULEDIRS = $(MODULES_REL) ${call resolvedir_prefix, $(CONTIKI)/, $(MODULES)}
UNIQUEMODULES = $(call uniq,$(MODULEDIRS))
MODULES_SOURCES = ${foreach d, $(UNIQUEMODULES), ${subst ${d}/,,${wildcard $(d)/*.c}}}
CONTIKI_SOURCEFILES += $(MODULES_SOURCES)
# Include module-specific makefiles
MODULES_INCLUDES = ${wildcard ${foreach d, $(UNIQUEMODULES), $(d)/Makefile.${notdir $(d)}}}
### Perform an immediate expansion of MODULES_INCLUDES and store it in a
### variable. This will allow us to subsequently filter-out module Makefiles
### that were included in the first pass, such that we don't end up including
### them twice.
MODULES_INCLUDED_FIRST_PASS := $(MODULES_INCLUDES)
include $(MODULES_INCLUDED_FIRST_PASS)
$(info modules 1st pass $(MODULES_INCLUDED_FIRST_PASS) )
# Iterate once more: include the modules added from the previous include.
# Only works with one level of nested module inclusion.
MODULES_INCLUDED_SECOND_PASS := $(filter-out $(MODULES_INCLUDED_FIRST_PASS) \
, $(MODULES_INCLUDES) )
include $(MODULES_INCLUDED_SECOND_PASS)
$(info modules 2nd pass $(MODULES_INCLUDED_SECOND_PASS) )
# Iterate once more: include the modules added from the previous include.
# Only works with one level of nested module inclusion.
MODULES_INCLUDED_3_PASS := $(filter-out $(MODULES_INCLUDED_FIRST_PASS) \
$(MODULES_INCLUDED_SECOND_PASS) \
,$(MODULES_INCLUDES) )
include $(MODULES_INCLUDED_3_PASS)
$(info modules 3rd pass $(MODULES_INCLUDED_3_PASS) )
# C-include module-specific macros using -imacros
MODULES_IMACROS = ${wildcard ${foreach d, $(UNIQUEMODULES), $(d)/module-macros.h}}
ifneq ($(MODULES_IMACROS),)
CFLAGS += ${foreach d, $(MODULES_IMACROS), -imacros $(d)}
endif
endif
CXXFLAGS += $(subst -std=c99,-std=gnu++11,$(CFLAGS))
CXXFLAGS += -fpermissive -fno-exceptions -fno-unwind-tables
CXXFLAGS += -fno-threadsafe-statics -fno-rtti -fno-use-cxa-atexit
### Verbosity control. Use make V=1 to get verbose builds.
ifeq ($(V),1)
TRACE_CC = @echo " CC " $< "-->" $@
TRACE_CCX= @echo " C++ " $< "-->" $@
TRACE_CXX= @echo " C++ " $< "-->" $@
TRACE_LD = @echo " LD " "-->" $@
TRACE_AR = @echo " AR " "-->" $@
TRACE_AS = @echo " AS " $< "-->" $@
TRACE_OBJCOPY = @echo " OBJCOPY " $< "-->" $@
TRACE_OBJDUMP = @echo " OBJDUMP " $< "-->" $@
TRACE_MKDIR = @echo " MKDIR " $@
TRACE_CP = @echo " CP " $< "-->" $@
Q ?=
else
ifeq ("$(V)","")
TRACE_CC =
TRACE_CCX=
TRACE_CXX=
TRACE_LD =
TRACE_AR =
TRACE_AS =
TRACE_OBJCOPY =
TRACE_OBJDUMP =
TRACE_MKDIR =
TRACE_CP =
Q ?= @
else
TRACE_CC = @echo " CC " $< "-->" $@
TRACE_CCX= @echo " C++ " $< "-->" $@
TRACE_CXX= @echo " C++ " $< "-->" $@
TRACE_LD = @echo " LD " $@
TRACE_AR = @echo " AR " $@
TRACE_AS = @echo " AS " $< "-->" $@
TRACE_OBJCOPY = @echo " OBJCOPY " $< "-->" $@
TRACE_OBJDUMP = @echo " OBJDUMP " $< "-->" $@
TRACE_MKDIR = @echo " MKDIR " $@
TRACE_CP = @echo " CP " $< "-->" $@
Q ?= @
endif
endif
### Forward comma-separated list of arbitrary defines to the compiler
CFLAGS += ${addprefix -D,${subst $(COMMA), ,$(DEFINES)}}
### Setup directory search path for source and header files
CONTIKI_TARGET_DIRS_CONCAT = ${call resolvedir_prefix, ${dir $(target_makefile)}, \
$(CONTIKI_TARGET_DIRS)}
CONTIKI_CPU_DIRS_CONCAT = ${call resolvedir_prefix, $(CONTIKI_CPU)/, \
$(CONTIKI_CPU_DIRS)}
$(info terget dirs:$(CONTIKI_TARGET_DIRS) -> $(CONTIKI_TARGET_DIRS_CONCAT) )
$(info cpu dirs:$(CONTIKI_CPU_DIRS) -> $(CONTIKI_CPU_DIRS_CONCAT) )
$(info external dirs:$(EXTERNALDIRS) )
SOURCEDIRS += . $(PROJECTDIRS) $(CONTIKI_TARGET_DIRS_CONCAT) \
$(CONTIKI_CPU_DIRS_CONCAT) $(MODULEDIRS) $(EXTERNALDIRS) $(APPDS)
vpath %.c $(abspath $(SOURCEDIRS))
vpath %.cpp $(abspath $(SOURCEDIRS))
vpath %.in $(SOURCEDIRS)
vpath %.S $(abspath $(SOURCEDIRS))
vpath %.s $(abspath $(SOURCEDIRS))
CFLAGS += ${addprefix -I, $(call uniq,$(SOURCEDIRS) $(CONTIKI)) }
### Check for a git repo and pass version if found
### git.exe in Windows cmd shells may require no stderr redirection
ifndef RELSTR
ifneq ($(wildcard ${CONTIKI}/.git/*),)
RELSTR:=${shell git --git-dir ${CONTIKI}/.git --work-tree ${CONTIKI} describe \
--tags --always --dirty}
else
RELSTR=4.7
endif
endif
ifneq ($(RELSTR),)
CONTIKI_VERSION = -DCONTIKI_VERSION_STRING=\"Contiki-NG-$(RELSTR)\"
else
CONTIKI_VERSION = -DCONTIKI_VERSION_STRING=\"Contiki-NG\"
endif
# These files are compiled with -DCONTIKI_VERSION_STRING in CFLAGS.
NEEDS_CONTIKI_VERSION_FILES += contiki-main.c lwm2m-device.c
CFLAGS_CPU ?=
CPPFLAGS := ${CPPFLAGS} ${CFLAGS}
CFLAGS := ${CFLAGS_CPU} ${CFLAGS}
### drop excluded objects
ifneq ("$(SOURCE_EXCLUDE)$(MODULES_SOURCES_EXCLUDES)","")
CONTIKI_SOURCEFILES := $(filter-out $(SOURCE_EXCLUDE) $(MODULES_SOURCES_EXCLUDES), $(CONTIKI_SOURCEFILES))
PROJECT_SOURCEFILES := $(filter-out $(SOURCE_EXCLUDE) $(MODULES_SOURCES_EXCLUDES), $(PROJECT_SOURCEFILES))
endif
CONTIKI_OBJECTFILES += ${addprefix $(OBJECTDIR)/,${call oname, $(CONTIKI_SOURCEFILES)}}
PROJECT_OBJECTFILES += ${addprefix $(OBJECTDIR)/,${call oname, $(PROJECT_SOURCEFILES)}}
# prevent delete project objects that have deps but not included in contiki lib
.SECONDARY : $(PROJECT_OBJECTFILES) $(CONTIKI_OBJECTFILES) $(TARGET_STARTFILES)
### Harmonize filename of a .map file, if the platform's build system wants
### to create one
CONTIKI_NG_PROJECT_MAP = $(BUILD_DIR_BOARD)/$(basename $(notdir $@)).map
# At this stage, all source files for the build have been defined, so
# define the corresponding object files.
#
# The logic is that the general build system adds source files with wildcards,
# and architectures/applications can specify exclusions to that through
# variables ending with _EXCLUDES and _EXCLUDES_$(TARGET_UPPERCASE).
CONTIKI_SOURCEFILES += $(filter-out $(MODULES_SOURCES_EXCLUDES) $(MODULES_SOURCES_EXCLUDES_$(TARGET_UPPERCASE)), $(MODULES_SOURCES))
CONTIKI_FILTERED_SOURCEFILES = $(filter-out $(CONTIKI_SOURCES_EXCLUDES) $(CONTIKI_SOURCES_EXCLUDES_$(TARGET_UPPERCASE)), $(CONTIKI_SOURCEFILES))
CONTIKI_OBJECTFILES += ${addprefix $(OBJECTDIR)/,${call oname, $(CONTIKI_FILTERED_SOURCEFILES)}}
PROJECT_FILTERED_SOURCEFILES = $(filter-out $(PROJECT_SOURCES_EXCLUDES) $(PROJECT_SOURCES_EXCLUDES_$(TARGET_UPPERCASE)), $(PROJECT_SOURCEFILES))
PROJECT_OBJECTFILES += ${addprefix $(OBJECTDIR)/,${call oname, $(PROJECT_FILTERED_SOURCEFILES)}}
.PHONY: all clean distclean usage help targets boards savetarget savedefines viewconf
clean:
-$(Q)rm -f *.d *.e *.o $(CLEAN) \
$(addsuffix .$(TARGET), $(CONTIKI_PROJECT) )
-rm -rf $(BUILD_DIR_TARGET)
@echo Target $(TARGET) cleaned
distclean:
$(Q)for TARG in `ls $(CONTIKI_NG_RELOC_PLATFORM_DIR) $(TARGETDIRS)`; do \
echo Running: $(MAKE) TARGET=$$TARG clean; \
$(MAKE) TARGET=$$TARG clean; \
done
$(Q)rm -rf $(BUILD_DIR)
# Compare % and %.diffupdate, replace % with %.diffupdate if they differ.
$(GENDIR)/%: $(GENDIR)/%.diffupdate | $(GENDIR)
$(Q)diff $< $@ > /dev/null 2>&1 || mv $< $@
# Start cooja through "make file.csc", where the real target is defined through the csc.
%.csc %.csc.gz: FORCE
$(Q)$(GRADLE) --no-watch-fs --parallel --build-cache -p $(COOJA_PATH) run --args="-quickstart=$(addprefix $(CURDIR)/,$@) -contiki=$(realpath $(CONTIKI)) -logdir=$(CURDIR)"
DEPS_GCC ?= 1
ifeq ([${DEPS_GCC}],[1])
# GCC provide deps generation tool from the box, so nothin need to do with it
define FINALIZE_DEPENDENCY
endef
### Automatic dependency generation, see
### http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/#advanced
DEPFLAGS ?= -MT $@ -MMD -MP -MF $(DEPDIR)/$*.d
else ##ifeq ([${DEPS_GCC}]
DEPFLAGS ?=
### Automatic dependency generation, see
### See http://make.paulandlesley.org/autodep.html#advanced
ifeq ([${WINDIR}],[])
define FINALIZE_DEPENDENCY
cp $(@:.o=.d) $(@:.o=.$$$$); \
sed -e 's/#.*//' -e 's/^[^:].*: *//' -e 's/ *\\$$//' \
-e '/^$$/ d' -e 's/$$/ :/' < $(@:.o=$(DEPDIR)/%.$$$$) >> $(@:.o=$(DEPDIR)/%.d); \
rm -f $(@:.o=$(DEPDIR)/%.$$$$)
endef
else
### windows pathes can contain ':' char, so just allow it
define FINALIZE_DEPENDENCY
cp $(@:.o=.d) $(@:.o=.$$$$); \
sed -e 's/#.*//' -e 's/^.*: *//' -e 's/ *\\$$//' \
-e '/^$$/ d' -e 's/$$/ :/' < $(@:.o=$(DEPDIR)/%.$$$$) >> $(@:.o=$(DEPDIR)/%.d); \
rm -f $(@:.o=$(DEPDIR)/%.$$$$)
endef
endif ##ifeq ([${WINDIR}]
endif ##ifeq ([${DEPS_GCC}]
ifneq ($(findstring clean,$(MAKECMDGOALS)),clean)
DEPOBJS = $(CONTIKI_OBJECTFILES) $(PROJECT_OBJECTFILES) $(TARGET_STARTFILES)
DEPS = $(DEPOBJS:%.o=$(@D)/$(DEPDIR)/$(@F).d)
# LDSCRIPT is generated with the preprocessor on some targets, so enable
# those targets to avoid rebuilds as well.
DEPS += $(addprefix $(DEPDIR)/, $(addsuffix .d, $(notdir $(LDSCRIPT))))
#$(info deps: ${DEPS})
-include ${DEPS}
endif
# Add CONTIKI_VERSION to CFLAGS for these files.
NEEDS_VERSION_OBJFILES = $(NEEDS_CONTIKI_VERSION_FILES:%.c=$(OBJECTDIR)/%.o)
$(NEEDS_VERSION_OBJFILES): CFLAGS += $(CONTIKI_VERSION)
# Include custom build rule Makefiles specified by platforms/CPUs.
ifdef MAKEFILES_CUSTOMRULES
-include $(MAKEFILES_CUSTOMRULES)
else
-include $(CONTIKI_NG_RELOC_PLATFORM_DIR)/$(TARGET)/Makefile.customrules-$(TARGET)
endif
ifdef GCCTEMPS
define DUMP_GCCCPP
$(Q)$(CC) $(CFLAGS) -E -c $< -o ${patsubst %.o,%.ip, $@}
endef
else
define DUMP_GCCCPP
endef
endif
ifndef CUSTOM_RULE_IN_TO_GENDIR
QUOTE := '
# Fix Emacs syntax highlighting: '
# Run sed on the .in file to produce the outfile, with one replacement
# expression for each LHS=RHS in $(REPLACEMENTS).
$(GENDIR)/%: %.in | $(GENDIR)
$(Q)sed $(addprefix -e , $(addsuffix =g$(QUOTE), $(addprefix $(QUOTE)s=, $(REPLACEMENTS)))) $< > $@
endif
ifndef CUSTOM_RULE_C_TO_OBJECTDIR_O
$(OBJECTDIR)/%.o: %.c | $(OBJECTDIR)
$(TRACE_CC)
$(Q)$(CCACHE) $(CC) $(CFLAGS) $(DEPFLAGS) -c $< -o $@
@$(FINALIZE_DEPENDENCY)
@${DUMP_GCCCPP}
$(OBJECTDIR)/%.o: %.cpp | $(OBJECTDIR)
$(TRACE_CCX)
$(Q)$(CCX) $(CPPFLAGS) -MMD -c $< -o $@
@$(FINALIZE_DEPENDENCY)
@${DUMP_GCCCPP}
endif
ifndef CUSTOM_RULE_CPP_TO_OBJECTDIR_O
$(OBJECTDIR)/%.o: %.cpp | $(OBJECTDIR)
$(TRACE_CXX)
$(Q)$(CCACHE) $(CXX) $(CXXFLAGS) $(DEPFLAGS) -c $< -o $@
@$(FINALIZE_DEPENDENCY)
endif
ifndef CUSTOM_RULE_S_TO_OBJECTDIR_O
$(OBJECTDIR)/%.o: %.S | $(OBJECTDIR)
$(TRACE_AS)
$(Q)$(AS) $(ASFLAGS) -o $@ $<
@${DUMP_GCCCPP}
$(OBJECTDIR)/%.o: %.s | $(OBJECTDIR)
$(TRACE_AS)
$(Q)$(AS) $(ASFLAGS) -o $@ $<
@${DUMP_GCCCPP}
endif
ifndef CUSTOM_RULE_C_TO_OBJECTDIR_S
$(OBJECTDIR)/%.s: %.c | $(OBJECTDIR)
$(TRACE_CC)
$(Q)$(CCACHE) $(CC) $(CFLAGS) -S $< -o $@
@${DUMP_GCCCPP}
endif
ifndef CUSTOM_RULE_CPP_TO_OBJECTDIR_S
$(OBJECTDIR)/%.s: %.cpp | $(OBJECTDIR)
$(TRACE_CXX)
$(Q)$(CCACHE) $(CXX) $(CXXFLAGS) -S $< -o $@
endif
ifndef CUSTOM_RULE_C_TO_OBJECTDIR_E
$(OBJECTDIR)/%.e: %.c | $(OBJECTDIR)
$(TRACE_CC)
$(Q)$(CCACHE) $(CC) $(CFLAGS) -E $< -o $@
endif
ifndef CUSTOM_RULE_CPP_TO_OBJECTDIR_E
$(OBJECTDIR)/%.e: %.cpp | $(OBJECTDIR)
$(TRACE_CXX)
$(Q)$(CCACHE) $(CXX) $(CXXFLAGS) -E $< -o $@
endif
ifndef AROPTS
AROPTS = rc
endif
ifndef CUSTOM_RULE_ALLOBJS_TO_TARGETLIB
CONTIKI_NG_TARGET_LIB = $(BUILD_DIR_BOARD)/contiki-ng-$(TARGET).a
$(CONTIKI_NG_TARGET_LIB): $(CONTIKI_OBJECTFILES) | $(BUILD_DIR_BOARD)
$(TRACE_AR)
$(Q)$(AR) $(AROPTS) $@ $^
endif
ifndef LD
LD = $(CC)
endif
ifndef CUSTOM_RULE_LINK
# Targets can define LD_START_GROUP and LD_END_GROUP to resolve circular
# dependencies between linked libraries, see:
# https://stackoverflow.com/questions/5651869/gcc-what-are-the-start-group-and-end-group-command-line-options/5651895
# These are not defined by default since it has a significant performance cost.
TARGET_LIBEXTRAS = $(LD_START_GROUP) $(TARGET_LIBFILES) $(LD_END_GROUP)
# The order of object files passed to $(LD) varies across runs and this causes
# binary sizes to vary. Sort the files to get a deterministic size.
#
# Cooja passes LIBNAME through the environment and all .csc files contain
# calls to make with a target that is *not* what Cooja needs. Add
# a compatibility line for link rule so we can have a single rule that
# outputs to LIBNAME on all platforms.
LIBNAME ?= $@
LIBTARGET ?= $(LIBNAME)
#
# FIX: use linking via archive can relax errors about undefined references of an unused
# objects on a project. we can safely contain all contiki sources in a lib, and not
# bother - wich of them used, and wich not
# linking via $(CONTIKI_OBJECTFILES) - ld can surprisingly fails on linking unused obj
# on that have no demanded references
$(BUILD_DIR_BOARD)/%.$(TARGET): $(OBJECTDIR)/%.o $(LDSCRIPT) $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) $(CONTIKI_NG_TARGET_LIB) $(MAPFILE)
ifdef REDEFINE_PRINTF
@echo Redefining printf,sprintf,vsnprintf,etc.
$(Q)$(foreach OBJ,$(filter %.o %.a,$^), \
$(OBJCOPY) --redefine-syms $(CONTIKI)/arch/platform/$(TARGET)/redefine.syms $(OBJ); )
endif
$(TRACE_LD)
$(Q)$(LD) $(LDFLAGS) $(TARGET_STARTFILES) ${filter %.o,$^} \
${filter %.a,$^} $(TARGET_LIBEXTRAS) -o $(LIBTARGET)
ifdef BINARY_SIZE_LOGFILE
$(Q)$(SIZE) $(LIBNAME) | grep $(BUILD_DIR_BOARD) >> $(BINARY_SIZE_LOGFILE)
endif
ifeq ($(V),1)
$(info contiki:$(CONTIKI_SOURCEFILES))
$(info proj:$(PROJECT_SOURCEFILES))
$(info obj:$(PROJECT_OBJECTFILES))
endif
endif
# this objects need for debuger, and need for quick rebuild
.PRECIOUS: $(OBJECTDIR)/%.o $(PROJECT_OBJECTFILES)
.PRECIOUS: $(CONTIKI_NG_TARGET_LIB)
.PRECIOUS: $(LIBNAME) $(LIBNAME).%
ifndef CUSTOM_RULE_TARGET
# LD builds $(LIBNAME) as final for target, so copy that one
%.$(TARGET): $(BUILD_DIR_BOARD)/%.$(TARGET)
@echo "target -> $(abspath $@) (* $(PROJECT_OBJECTFILES))"
$(TRACE_CP)
$(Q)$(CP) $(LIBNAME) $@
ifneq ($(NODEID),)
$(Q)$(CP) $(LIBNAME) $*-$(NODEID).$(TARGET)
endif
endif
%.ramprof: $(BUILD_DIR_BOARD)/%.$(TARGET)
$(NM) -S -td --size-sort $< | grep -i " [abdrw] " | cut -d' ' -f2,4
%.flashprof: $(BUILD_DIR_BOARD)/%.$(TARGET)
$(NM) -S -td --size-sort $< | grep -i " [t] " | cut -d' ' -f2,4
include $(CONTIKI)/Makefile.help
targets:
@ls $(CONTIKI_NG_RELOC_PLATFORM_DIR) $(TARGETDIRS)
boards:
ifdef BOARD
@echo "$(BOARDS) (current: $(BOARD))"
else
@echo "Platform has no boards"
endif
savetarget:
@rm -f Makefile.target
@echo "saving Makefile.target"
@echo >Makefile.target "TARGET = $(TARGET)"
ifneq ($(BOARD),)
@echo >>Makefile.target "BOARD = $(BOARD)"
endif
savedefines:
@rm -f Makefile.$(TARGET).defines
@echo "saving Makefile.$(TARGET).defines"
@echo >Makefile.$(TARGET).defines "DEFINES = $(DEFINES)"
VIEWCONF = $(CONTIKI_NG_TOOLS_DIR)/viewconf/viewconf.c
viewconf:
@echo "----------------- Make variables: --------------"
@echo "##### \"TARGET\": ________________________________ $(TARGET)"
@echo "##### \"BOARD\": _________________________________ $(BOARD)"
@echo "##### \"MAKE_MAC\": ______________________________ $(MAKE_MAC)"
@echo "##### \"MAKE_NET\": ______________________________ $(MAKE_NET)"
@echo "##### \"MAKE_ROUTING\": __________________________ $(MAKE_ROUTING)"
ifdef MAKE_COAP_DTLS_KEYSTORE
@echo "##### \"MAKE_COAP_DTLS_KEYSTORE\": _______________ $(MAKE_COAP_DTLS_KEYSTORE)"
endif
@echo "----------------- C variables: -----------------"
$(Q)$(CC) $(CONTIKI_VERSION) $(CFLAGS) -E $(VIEWCONF) | grep \#\#\#\#\#
@echo "------------------------------------------------"
@echo "'==' Means the flag is set to a given a value"
@echo "'->' Means the flag is unset, but will default to a given value"
@echo "'><' Means the flag is unset and has no default value"
@echo "To view more Make variables, edit $(CONTIKI)/Makefile.include, rule 'viewconf'"
@echo "To view more C variables, edit $(VIEWCONF)"
###
### Targets using tools/motelist
###
CONTIKI_NG_MOTELIST_DIR = $(CONTIKI_NG_TOOLS_DIR)/motelist
CONTIKI_NG_MOTELIST = $(CONTIKI_NG_MOTELIST_DIR)/motelist.py
.PHONY: motelist-all
motelist-all:
$(Q)$(CONTIKI_NG_MOTELIST)
### Include Makefile.embedded for relevant platforms, in order to pull in
### rules for login, serialview etc
ifeq ($(findstring $(TARGET),native cooja),)
include $(CONTIKI)/Makefile.embedded
endif
### Include Makefile.gcc for GCC specific definitions and actions
include $(CONTIKI)/Makefile.gcc
# Don't treat $(BUILD_DIR_BOARD)/%.$(TARGET) and $(TARGET) as intermediate
# files because for many platforms they are in fact the primary target.
.SECONDARY: $(BUILD_DIR_BOARD)/%.$(TARGET) %.$(TARGET)
%: %.cpp
ifeq ($(PLATFORM_ACTION),skip)
# Skip this target.
$(CONTIKI_PROJECT):
@echo "Skipping $@: not for the '$(TARGET)/$(BOARD)' platform!"
%.$(TARGET):
@echo "Skipping $@: not for the '$(TARGET)/$(BOARD)' platform!"
else
# Build this target.
# Match-anything pattern rule to allow the project makefiles to
# abstract from the actual binary name. It needs to contain some
# command in order to be a rule, not just a prerequisite.
%: %.$(TARGET)
@echo "prepared for $@ prerequesites "$(BUILD_DIR)/$@.$(TARGET)
endif