forked from sudar/Arduino-Makefile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Arduino.mk
1917 lines (1662 loc) · 69.3 KB
/
Arduino.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
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
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
########################################################################
#
# Makefile for compiling Arduino sketches from command line
# System part (i.e. project independent)
#
# Copyright (C) 2012 Sudar <http://sudarmuthu.com>, based on
# M J Oldfield work: https://github.com/mjoldfield/Arduino-Makefile
#
# Copyright (C) 2010,2011,2012 Martin Oldfield <[email protected]>, based on
# work that is copyright Nicholas Zambetti, David A. Mellis & Hernando
# Barragan.
#
# This file is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2.1 of the
# License, or (at your option) any later version.
#
# Adapted from Arduino 0011 Makefile by M J Oldfield
#
# Original Arduino adaptation by mellis, eighthave, oli.keller
#
# Current version: 1.6.0
#
# Refer to HISTORY.md file for complete history of changes
#
########################################################################
#
# PATHS YOU NEED TO SET UP
#
# We need to worry about three different sorts of files:
#
# 1. The directory where the *.mk files are stored
# => ARDMK_DIR
#
# 2. Things which are always in the Arduino distribution e.g.
# boards.txt, libraries, etc.
# => ARDUINO_DIR
#
# 3. Things which might be bundled with the Arduino distribution, but
# might come from the system. Most of the toolchain is like this:
# on Linux it is supplied by the system.
# => AVR_TOOLS_DIR
#
# Having set these three variables, we can work out the rest assuming
# that things are canonically arranged beneath the directories defined
# above.
#
# On the Mac with IDE 1.0 you might want to set:
#
# ARDUINO_DIR = /Applications/Arduino.app/Contents/Resources/Java
# ARDMK_DIR = /usr/local
#
# On the Mac with IDE 1.5+ you might want to set:
#
# ARDUINO_DIR = /Applications/Arduino.app/Contents/Java
# ARDMK_DIR = /usr/local
#
# On Linux, you might prefer:
#
# ARDUINO_DIR = /usr/share/arduino
# ARDMK_DIR = /usr/share/arduino
# AVR_TOOLS_DIR = /usr
#
# On Windows declare this environmental variables using the windows
# configuration options or Cygwin .bashrc. Control Panel > System > Advanced system settings
# The paths must use Unix style forward slash and not have any spaces
# or escape charactors. One must use a symbolic link if the path does
# contain spaces.
#
# This are just examples, you have to adapt this variables accordingly to
# your system. Note the difference between ARDMK_DIR, which can use /cygdrive/
# and USER_LIB_PATH, which cannnot due to invoking with the build tools.
# It is best practice to avoid cygdrive all together.
#
# ARDUINO_DIR = C:/Arduino
# AVR_TOOLS_DIR = C:/Arduino/hardware/tools/avr
# ARDMK_DIR = /cygdrive/c/Users/"YourUser"/Arduino-Makefile
#
# On Windows it is highly recommended that you create a symbolic link directory
# for avoiding using the normal directories name of windows such as
# C:\Program Files (x86)\Arduino
# For this use the command mklink on the console.
#
#
# You can either set these up in the Makefile, or put them in your
# environment e.g. in your .bashrc
#
# If you don't specify these, we can try to guess, but that might not work
# or work the way you want it to.
#
# If you'd rather not see the configuration output, define ARDUINO_QUIET.
#
########################################################################
#
# DEPENDENCIES
#
# to reset a board the (python) pySerial program is used.
# please install it prior to continue.
#
########################################################################
#
# STANDARD ARDUINO WORKFLOW
#
# Given a normal sketch directory, all you need to do is to create
# a small Makefile which defines a few things, and then includes this one.
#
# For example:
#
# ARDUINO_LIBS = Ethernet SPI
# BOARD_TAG = uno
# MONITOR_PORT = /dev/cu.usb*
#
# include /usr/share/arduino/Arduino.mk
#
# Hopefully these will be self-explanatory but in case they're not:
#
# ARDUINO_LIBS - A list of any libraries used by the sketch (we
# assume these are in $(ARDUINO_DIR)/hardware/libraries
# or your sketchbook's libraries directory)
#
# MONITOR_PORT - The port where the Arduino can be found (only needed
# when uploading)
#
# BOARD_TAG - The tag for the board e.g. uno or mega
# 'make show_boards' shows a list
#
# If you have your additional libraries relative to your source, rather
# than in your "sketchbook", also set USER_LIB_PATH, like this example:
#
# USER_LIB_PATH := $(realpath ../../libraries)
#
# If you've added the Arduino-Makefile repository to your git repo as a
# submodule (or other similar arrangement), you might have lines like this
# in your Makefile:
#
# ARDMK_DIR := $(realpath ../../tools/Arduino-Makefile)
# include $(ARDMK_DIR)/Arduino.mk
#
# In any case, once this file has been created the typical workflow is just
#
# $ make upload
#
# All of the object files are created in the build-{BOARD_TAG} subdirectory
# All sources should be in the current directory and can include:
# - at most one .pde or .ino file which will be treated as C++ after
# the standard Arduino header and footer have been affixed.
# - any number of .c, .cpp, .s and .h files
#
# Included libraries are built in the build-{BOARD_TAG}/libs subdirectory.
#
# Besides make upload, there are a couple of other targets that are available.
# Do make help to get the complete list of targets and their description
#
########################################################################
#
# SERIAL MONITOR
#
# The serial monitor just invokes the GNU screen program with suitable
# options. For more information see screen (1) and search for
# 'character special device'.
#
# The really useful thing to know is that ^A-k gets you out!
#
# The fairly useful thing to know is that you can bind another key to
# escape too, by creating $HOME{.screenrc} containing e.g.
#
# bindkey ^C kill
#
# If you want to change the baudrate, just set MONITOR_BAUDRATE. If you
# don't set it, it tries to read from the sketch. If it couldn't read
# from the sketch, then it defaults to 9600 baud.
#
########################################################################
#
# ARDUINO WITH ISP
#
# You need to specify some details of your ISP programmer and might
# also need to specify the fuse values:
#
# ISP_PROG = stk500v2
# ISP_PORT = /dev/ttyACM0
#
# You might also need to set the fuse bits, but typically they'll be
# read from boards.txt, based on the BOARD_TAG variable:
#
# ISP_LOCK_FUSE_PRE = 0x3f
# ISP_LOCK_FUSE_POST = 0xcf
# ISP_HIGH_FUSE = 0xdf
# ISP_LOW_FUSE = 0xff
# ISP_EXT_FUSE = 0x01
#
# You can specify to also upload the EEPROM file:
# ISP_EEPROM = 1
#
# I think the fuses here are fine for uploading to the ATmega168
# without bootloader.
#
# To actually do this upload use the ispload target:
#
# make ispload
#
#
########################################################################
#
# ALTERNATIVE CORES
#
# To use alternative cores for platforms such as ATtiny, you need to
# specify a few more variables, depending on the core in use.
#
# The HLT (attiny-master) core can be used just by specifying
# ALTERNATE_CORE, assuming your core is in your ~/sketchbook/hardware
# directory. For example:
#
# ISP_PORT = /dev/ttyACM0
# BOARD_TAG = attiny85
# ALTERNATE_CORE = attiny-master
#
# To use the more complex arduino-tiny and TinyCore2 cores, you must
# also set ARDUINO_CORE_PATH and ARDUINO_VAR_PATH to the core
# directory, as these cores essentially replace the main Arduino core.
# For example:
#
# ISP_PORT = /dev/ttyACM0
# BOARD_TAG = attiny85at8
# ALTERNATE_CORE = arduino-tiny
# ARDUINO_VAR_PATH = ~/sketchbook/hardware/arduino-tiny/cores/tiny
# ARDUINO_CORE_PATH = ~/sketchbook/hardware/arduino-tiny/cores/tiny
#
# or....
#
# ISP_PORT = /dev/ttyACM0
# BOARD_TAG = attiny861at8
# ALTERNATE_CORE = tiny2
# ARDUINO_VAR_PATH = ~/sketchbook/hardware/tiny2/cores/tiny
# ARDUINO_CORE_PATH = ~/sketchbook/hardware/tiny2/cores/tiny
#
########################################################################
arduino_output =
# When output is not suppressed and we're in the top-level makefile,
# running for the first time (i.e., not after a restart after
# regenerating the dependency file), then output the configuration.
ifndef ARDUINO_QUIET
ARDUINO_QUIET = 0
endif
ifeq ($(ARDUINO_QUIET),0)
ifeq ($(MAKE_RESTARTS),)
ifeq ($(MAKELEVEL),0)
arduino_output = $(info $(1))
endif
endif
endif
########################################################################
# Makefile distribution path
ifndef ARDMK_DIR
# presume it's the same path to our own file
ARDMK_DIR := $(realpath $(dir $(realpath $(lastword $(MAKEFILE_LIST)))))
else
# show_config_variable macro is defined in Common.mk file and is not available yet.
# Let's define a variable to know that user specified ARDMK_DIR
ARDMK_DIR_MSG = USER
endif
# include Common.mk now we know where it is
ifndef COMMON_INCLUDED
include $(ARDMK_DIR)/Common.mk
endif
# show_config_variable macro is available now. So let's print config details for ARDMK_DIR
ifndef ARDMK_DIR_MSG
$(call show_config_variable,ARDMK_DIR,[COMPUTED],(relative to $(notdir $(lastword $(MAKEFILE_LIST)))))
else
$(call show_config_variable,ARDMK_DIR,[USER])
endif
########################################################################
# Default TARGET to pwd (ex Daniele Vergini)
ifndef TARGET
space :=
space +=
TARGET = $(notdir $(subst $(space),_,$(CURDIR)))
endif
########################################################################
# Arduino version number
ifndef ARDUINO_VERSION
# Remove all the decimals, remove anything before/including ":", remove anything after/including "+" and finally grab the last 5 bytes.
# Works for 1.0 and 1.0.1 and 1.6.10 and debian-style 2:1.0.5+dfsg2-4
VERSION_FILE := $(ARDUINO_DIR)/lib/version.txt
AUTO_ARDUINO_VERSION := $(shell [ -e $(VERSION_FILE) ] && cat $(VERSION_FILE) | sed -e 's/^[0-9]://g' -e 's/[.]//g' -e 's/\+.*//g' | head -c5)
ifdef AUTO_ARDUINO_VERSION
ARDUINO_VERSION = $(AUTO_ARDUINO_VERSION)
$(call show_config_variable,ARDUINO_VERSION,[AUTODETECTED])
else
ARDUINO_VERSION = 100
$(call show_config_variable,ARDUINO_VERSION,[DEFAULT])
endif
else
$(call show_config_variable,ARDUINO_VERSION,[USER])
endif
########################################################################
# 1.5.x architecture - avr or sam for arduino vendor
ifndef ARCHITECTURE
ifeq ($(shell expr $(ARDUINO_VERSION) '>' 150), 1)
# default to avr for 1.5
ARCHITECTURE = avr
ARDUINO_ARCH_FLAG = -DARDUINO_ARCH_AVR
else
# unset for 1.0
ARCHITECTURE =
endif
$(call show_config_variable,ARCHITECTURE,[DEFAULT])
else
$(call show_config_variable,ARCHITECTURE,[USER])
#avoid using shell for known architectures
ifeq ($(ARCHITECTURE),avr)
ARDUINO_ARCH_FLAG = -DARDUINO_ARCH_AVR
else
ARDUINO_ARCH_FLAG = -DARDUINO_ARCH_$(shell echo $(ARCHITECTURE) | tr '[:lower:]' '[:upper:]')
endif
endif
########################################################################
# 1.5.x vendor - defaults to arduino
ifndef ARDMK_VENDOR
ARCH_LINUX := $(shell grep "Arch Linux" /etc/os-release 2>/dev/null)
ifdef ARCH_LINUX
ARDMK_VENDOR = archlinux-arduino
else
ARDMK_VENDOR = arduino
endif
$(call show_config_variable,ARDMK_VENDOR,[DEFAULT])
else
$(call show_config_variable,ARDMK_VENDOR,[USER])
endif
########################################################################
# Arduino Sketchbook folder
ifndef ARDUINO_SKETCHBOOK
ifndef ARDUINO_PREFERENCES_PATH
ifeq ($(shell expr $(ARDUINO_VERSION) '>' 150), 1)
AUTO_ARDUINO_PREFERENCES := $(firstword \
$(call dir_if_exists,$(HOME)/.arduino15/preferences.txt) \
$(call dir_if_exists,$(HOME)/Library/Arduino15/preferences.txt) )
else
AUTO_ARDUINO_PREFERENCES := $(firstword \
$(call dir_if_exists,$(HOME)/.arduino/preferences.txt) \
$(call dir_if_exists,$(HOME)/Library/Arduino/preferences.txt) )
endif
ifdef AUTO_ARDUINO_PREFERENCES
ARDUINO_PREFERENCES_PATH = $(AUTO_ARDUINO_PREFERENCES)
$(call show_config_variable,ARDUINO_PREFERENCES_PATH,[AUTODETECTED])
endif
else
$(call show_config_variable,ARDUINO_PREFERENCES_PATH,[USER])
endif
ifneq ($(ARDUINO_PREFERENCES_PATH),)
ARDUINO_SKETCHBOOK := $(shell grep --max-count=1 --regexp='sketchbook.path=' \
$(ARDUINO_PREFERENCES_PATH) | \
sed -e 's/sketchbook.path=//' )
endif
ifneq ($(ARDUINO_SKETCHBOOK),)
$(call show_config_variable,ARDUINO_SKETCHBOOK,[AUTODETECTED],(from arduino preferences file))
else
ifeq ($(CURRENT_OS), WINDOWS)
ARDUINO_SKETCHBOOK := $(firstword \
$(call dir_if_exists,$(USERPROFILE)/sketchbook) \
$(call dir_if_exists,$(USERPROFILE)/Documents/Arduino) )
else
ARDUINO_SKETCHBOOK := $(firstword \
$(call dir_if_exists,$(HOME)/sketchbook) \
$(call dir_if_exists,$(HOME)/Documents/Arduino) )
endif
$(call show_config_variable,ARDUINO_SKETCHBOOK,[DEFAULT])
endif
else
$(call show_config_variable,ARDUINO_SKETCHBOOK,[USER])
endif
########################################################################
# Arduino and system paths
# Third party hardware and core like ATtiny or ATmega 16
ifdef ALTERNATE_CORE
$(call show_config_variable,ALTERNATE_CORE,[USER])
ifndef ALTERNATE_CORE_PATH
ALTERNATE_CORE_PATH = $(ARDUINO_SKETCHBOOK)/hardware/$(ALTERNATE_CORE)/$(ARCHITECTURE)
endif
endif
ifdef ALTERNATE_CORE_PATH
ifdef ALTERNATE_CORE
$(call show_config_variable,ALTERNATE_CORE_PATH,[COMPUTED], (from ARDUINO_SKETCHBOOK and ALTERNATE_CORE))
else
$(call show_config_variable,ALTERNATE_CORE_PATH,[USER])
endif
ifndef ARDUINO_VAR_PATH
ARDUINO_VAR_PATH = $(ALTERNATE_CORE_PATH)/variants
$(call show_config_variable,ARDUINO_VAR_PATH,[COMPUTED],(from ALTERNATE_CORE_PATH))
endif
ifndef BOARDS_TXT
BOARDS_TXT = $(ALTERNATE_CORE_PATH)/boards.txt
$(call show_config_variable,BOARDS_TXT,[COMPUTED],(from ALTERNATE_CORE_PATH))
endif
else
ifndef ARDUINO_VAR_PATH
ARDUINO_VAR_PATH = $(ARDUINO_DIR)/hardware/$(ARDMK_VENDOR)/$(ARCHITECTURE)/variants
$(call show_config_variable,ARDUINO_VAR_PATH,[COMPUTED],(from ARDUINO_DIR))
else
$(call show_config_variable,ARDUINO_VAR_PATH,[USER])
endif
ifndef BOARDS_TXT
BOARDS_TXT = $(ARDUINO_DIR)/hardware/$(ARDMK_VENDOR)/$(ARCHITECTURE)/boards.txt
$(call show_config_variable,BOARDS_TXT,[COMPUTED],(from ARDUINO_DIR))
else
$(call show_config_variable,BOARDS_TXT,[USER])
endif
endif
ifeq (,$(wildcard $(BOARDS_TXT)))
$(error Currently BOARDS_TXT='$(BOARDS_TXT)', which is not an existing file or an invalid filename.)
endif
ifndef TOOL_PREFIX
TOOL_PREFIX = avr
endif
ifndef CC_NAME
CC_NAME := $(call PARSE_BOARD,$(BOARD_TAG),build.command.gcc)
ifndef CC_NAME
CC_NAME := $(TOOL_PREFIX)-gcc
else
$(call show_config_variable,CC_NAME,[COMPUTED])
endif
endif
ifndef CXX_NAME
CXX_NAME := $(call PARSE_BOARD,$(BOARD_TAG),build.command.g++)
ifndef CXX_NAME
CXX_NAME := $(TOOL_PREFIX)-g++
else
$(call show_config_variable,CXX_NAME,[COMPUTED])
endif
endif
ifndef AS_NAME
AS_NAME := $(call PARSE_BOARD,$(BOARD_TAG),build.command.as)
ifndef AS_NAME
AS_NAME := $(TOOL_PREFIX)-as
else
$(call show_config_variable,AS_NAME,[COMPUTED])
endif
endif
ifndef OBJCOPY_NAME
OBJCOPY_NAME := $(call PARSE_BOARD,$(BOARD_TAG),build.command.objcopy)
ifndef OBJCOPY_NAME
OBJCOPY_NAME := $(TOOL_PREFIX)-objcopy
else
$(call show_config_variable,OBJCOPY_NAME,[COMPUTED])
endif
endif
ifndef OBJDUMP_NAME
OBJDUMP_NAME := $(call PARSE_BOARD,$(BOARD_TAG),build.command.objdump)
ifndef OBJDUMP_NAME
OBJDUMP_NAME := $(TOOL_PREFIX)-objdump
else
$(call show_config_variable,OBJDUMP_NAME,[COMPUTED])
endif
endif
ifndef AR_NAME
AR_NAME := $(call PARSE_BOARD,$(BOARD_TAG),build.command.ar)
ifndef AR_NAME
AR_NAME := $(TOOL_PREFIX)-ar
else
$(call show_config_variable,AR_NAME,[COMPUTED])
endif
endif
ifndef SIZE_NAME
SIZE_NAME := $(call PARSE_BOARD,$(BOARD_TAG),build.command.size)
ifndef SIZE_NAME
SIZE_NAME := $(TOOL_PREFIX)-size
else
$(call show_config_variable,SIZE_NAME,[COMPUTED])
endif
endif
ifndef NM_NAME
NM_NAME := $(call PARSE_BOARD,$(BOARD_TAG),build.command.nm)
ifndef NM_NAME
NM_NAME := $(TOOL_PREFIX)-nm
else
$(call show_config_variable,NM_NAME,[COMPUTED])
endif
endif
ifndef AVR_TOOLS_DIR
BUNDLED_AVR_TOOLS_DIR := $(call dir_if_exists,$(ARDUINO_DIR)/hardware/tools/avr)
ifdef BUNDLED_AVR_TOOLS_DIR
AVR_TOOLS_DIR = $(BUNDLED_AVR_TOOLS_DIR)
$(call show_config_variable,AVR_TOOLS_DIR,[BUNDLED],(in Arduino distribution))
# In Linux distribution of Arduino, the path to avrdude and avrdude.conf are different
# More details at https://github.com/sudar/Arduino-Makefile/issues/48 and
# https://groups.google.com/a/arduino.cc/d/msg/developers/D_m97jGr8Xs/uQTt28KO_8oJ
ifeq ($(CURRENT_OS),LINUX)
ifndef AVRDUDE
ifeq ($(shell expr $(ARDUINO_VERSION) '>' 157), 1)
# 1.5.8 has different location than all prior versions!
AVRDUDE = $(AVR_TOOLS_DIR)/bin/avrdude
else
AVRDUDE = $(AVR_TOOLS_DIR)/../avrdude
endif
endif
ifndef AVRDUDE_CONF
ifeq ($(shell expr $(ARDUINO_VERSION) '>' 157), 1)
AVRDUDE_CONF = $(AVR_TOOLS_DIR)/etc/avrdude.conf
else
AVRDUDE_CONF = $(AVR_TOOLS_DIR)/../avrdude.conf
endif
endif
else
ifndef AVRDUDE_CONF
AVRDUDE_CONF = $(AVR_TOOLS_DIR)/etc/avrdude.conf
endif
endif
else
SYSTEMPATH_AVR_TOOLS_DIR := $(call dir_if_exists,$(abspath $(dir $(shell which $(CC_NAME)))/..))
ifdef SYSTEMPATH_AVR_TOOLS_DIR
AVR_TOOLS_DIR = $(SYSTEMPATH_AVR_TOOLS_DIR)
$(call show_config_variable,AVR_TOOLS_DIR,[AUTODETECTED],(found in $$PATH))
else
# One last attempt using $(TOOL_PREFIX)-gcc in case using arm
SYSTEMPATH_AVR_TOOLS_DIR := $(call dir_if_exists,$(abspath $(dir $(shell which $($(TOOL_PREFIX)-gcc)))/..))
ifdef SYSTEMPATH_AVR_TOOLS_DIR
AVR_TOOLS_DIR = $(SYSTEMPATH_AVR_TOOLS_DIR)
$(call show_config_variable,AVR_TOOLS_DIR,[AUTODETECTED],(found in $$PATH))
else
echo $(error No AVR tools directory found)
endif
endif # SYSTEMPATH_AVR_TOOLS_DIR
endif # BUNDLED_AVR_TOOLS_DIR
else
$(call show_config_variable,AVR_TOOLS_DIR,[USER])
# ensure we can still find avrdude.conf
ifndef AVRDUDE_CONF
ifeq ($(shell expr $(ARDUINO_VERSION) '>' 157), 1)
AVRDUDE_CONF = $(AVR_TOOLS_DIR)/etc/avrdude.conf
else
AVRDUDE_CONF = $(AVR_TOOLS_DIR)/../avrdude.conf
endif
endif
endif #ndef AVR_TOOLS_DIR
ifndef TOOLS_PATH
TOOLS_PATH = $(AVR_TOOLS_DIR)/bin
endif
ifndef ARDUINO_LIB_PATH
ARDUINO_LIB_PATH = $(ARDUINO_DIR)/libraries
$(call show_config_variable,ARDUINO_LIB_PATH,[COMPUTED],(from ARDUINO_DIR))
else
$(call show_config_variable,ARDUINO_LIB_PATH,[USER])
endif
# 1.5.x platform dependent libs path
ifndef ARDUINO_PLATFORM_LIB_PATH
ifeq ($(shell expr $(ARDUINO_VERSION) '>' 150), 1)
# only for 1.5
ARDUINO_PLATFORM_LIB_PATH = $(ARDUINO_DIR)/hardware/$(ARDMK_VENDOR)/$(ARCHITECTURE)/libraries
$(call show_config_variable,ARDUINO_PLATFORM_LIB_PATH,[COMPUTED],(from ARDUINO_DIR))
endif
else
$(call show_config_variable,ARDUINO_PLATFORM_LIB_PATH,[USER])
endif
########################################################################
# Miscellaneous
ifndef USER_LIB_PATH
USER_LIB_PATH = $(ARDUINO_SKETCHBOOK)/libraries
$(call show_config_variable,USER_LIB_PATH,[DEFAULT],(in user sketchbook))
else
$(call show_config_variable,USER_LIB_PATH,[USER])
endif
ifndef PRE_BUILD_HOOK
PRE_BUILD_HOOK = pre-build-hook.sh
$(call show_config_variable,PRE_BUILD_HOOK,[DEFAULT])
else
$(call show_config_variable,PRE_BUILD_HOOK,[USER])
endif
########################################################################
# boards.txt parsing
ifdef BOARD_SUB
BOARD_SUB := $(strip $(BOARD_SUB))
$(call show_config_variable,BOARD_SUB,[USER])
endif
ifndef BOARD_TAG
BOARD_TAG = uno
$(call show_config_variable,BOARD_TAG,[DEFAULT])
else
# Strip the board tag of any extra whitespace, since it was causing the makefile to fail
# https://github.com/sudar/Arduino-Makefile/issues/57
BOARD_TAG := $(strip $(BOARD_TAG))
$(call show_config_variable,BOARD_TAG,[USER])
endif
ifdef BOARD_CLOCK
BOARD_CLOCK := $(strip $(BOARD_CLOCK))
$(call show_config_variable,BOARD_CLOCK,[USER])
endif
# If NO_CORE is set, then we don't have to parse boards.txt file
# But the user might have to define MCU, F_CPU etc
ifeq ($(strip $(NO_CORE)),)
# Select a core from the 'cores' directory. Two main values: 'arduino' or
# 'robot', but can also hold 'tiny', for example, if using
# https://code.google.com/p/arduino-tiny alternate core.
ifndef CORE
CORE = $(call PARSE_BOARD,$(BOARD_TAG),build.core)
$(call show_config_variable,CORE,[COMPUTED],(from build.core))
else
$(call show_config_variable,CORE,[USER])
endif
# Which variant ? This affects the include path
ifndef VARIANT
VARIANT := $(call PARSE_BOARD,$(BOARD_TAG),menu.(chip|cpu).$(BOARD_SUB).build.variant)
ifndef VARIANT
VARIANT := $(call PARSE_BOARD,$(BOARD_TAG),build.variant)
endif
$(call show_config_variable,VARIANT,[COMPUTED],(from build.variant))
else
$(call show_config_variable,VARIANT,[USER])
endif
ifndef BOARD
BOARD := $(call PARSE_BOARD,$(BOARD_TAG),build.board)
ifndef BOARD
BOARD := $(shell echo $(ARCHITECTURE)_$(BOARD_TAG) | tr '[:lower:]' '[:upper:]')
endif
$(call show_config_variable,BOARD,[COMPUTED],(from build.board))
else
$(call show_config_variable,BOARD,[USER])
endif
# see if we are a caterina device like leonardo or micro
CATERINA := $(findstring caterina,$(call PARSE_BOARD,$(BOARD_TAG),menu.(chip|cpu).$(BOARD_SUB).bootloader.file))
ifndef CATERINA
# 1.5+ method if not a submenu
CATERINA := $(findstring caterina,$(call PARSE_BOARD,$(BOARD_TAG),bootloader.file))
endif
ifndef CATERINA
# 1.0 method uses deprecated bootloader.path
CATERINA := $(findstring caterina,$(call PARSE_BOARD,$(BOARD_TAG),bootloader.path))
endif
# processor stuff
ifndef MCU
MCU := $(call PARSE_BOARD,$(BOARD_TAG),menu.(chip|cpu).$(BOARD_SUB).build.mcu)
ifndef MCU
MCU := $(call PARSE_BOARD,$(BOARD_TAG),build.mcu)
endif
endif
ifndef F_CPU
ifdef BOARD_CLOCK
F_CPU := $(call PARSE_BOARD,$(BOARD_TAG),menu.(speed|clock).$(BOARD_CLOCK).build.f_cpu)
endif
ifndef F_CPU
F_CPU := $(call PARSE_BOARD,$(BOARD_TAG),menu.(chip|cpu).$(BOARD_SUB).build.f_cpu)
endif
ifndef F_CPU
F_CPU := $(call PARSE_BOARD,$(BOARD_TAG),build.f_cpu)
endif
endif
ifneq ($(CATERINA),)
# USB IDs for the caterina devices like leonardo or micro
ifndef USB_VID
USB_VID = $(call PARSE_BOARD,$(BOARD_TAG),build.vid)
endif
# coping with 2-3 methods sparkfun use for usb.pid
ifndef USB_PID
USB_PID := $(call PARSE_BOARD,$(BOARD_TAG),build.pid)
ifndef USB_PID
USB_PID := $(call PARSE_BOARD,$(BOARD_TAG),menu.(chip|cpu).$(BOARD_SUB).build.pid)
endif
endif
ifndef USB_PRODUCT
USB_PRODUCT := $(call PARSE_BOARD,$(BOARD_TAG),build.usb_product)
ifdef USB_PRODUCT
$(call show_config_variable,USB_PRODUCT,[COMPUTED])
endif
endif
ifndef USB_MANUFACTURER
USB_MANUFACTURER := $(call PARSE_BOARD,$(BOARD_TAG),build.usb_manufacturer)
ifndef USB_MANUFACTURER
USB_MANUFACTURER = "Unknown"
else
$(call show_config_variable,USB_MANUFACTURER,[COMPUTED])
endif
endif
# add caterina flag to ARD_RESET_OPTS
ARD_RESET_OPTS += --caterina
endif
# normal programming info
ifndef AVRDUDE_ARD_PROGRAMMER
AVRDUDE_ARD_PROGRAMMER := $(call PARSE_BOARD,$(BOARD_TAG),menu.(chip|cpu).$(BOARD_SUB).upload.protocol)
ifndef AVRDUDE_ARD_PROGRAMMER
AVRDUDE_ARD_PROGRAMMER := $(call PARSE_BOARD,$(BOARD_TAG),upload.protocol)
endif
endif
ifndef AVRDUDE_ARD_BAUDRATE
AVRDUDE_ARD_BAUDRATE := $(call PARSE_BOARD,$(BOARD_TAG),menu.(chip|cpu).$(BOARD_SUB).upload.speed)
ifndef AVRDUDE_ARD_BAUDRATE
AVRDUDE_ARD_BAUDRATE := $(call PARSE_BOARD,$(BOARD_TAG),upload.speed)
endif
endif
# fuses if you're using e.g. ISP
ifndef ISP_LOCK_FUSE_PRE
ISP_LOCK_FUSE_PRE = $(call PARSE_BOARD,$(BOARD_TAG),bootloader.unlock_bits)
endif
ifndef ISP_HIGH_FUSE
ifdef BOARD_CLOCK
ISP_HIGH_FUSE := $(call PARSE_BOARD,$(BOARD_TAG),menu.(speed|clock).$(BOARD_CLOCK).bootloader.high_fuses)
endif
ifndef ISP_HIGH_FUSE
ISP_HIGH_FUSE := $(call PARSE_BOARD,$(BOARD_TAG),menu.(chip|cpu).$(BOARD_SUB).bootloader.high_fuses)
endif
ifndef ISP_HIGH_FUSE
ISP_HIGH_FUSE := $(call PARSE_BOARD,$(BOARD_TAG),bootloader.high_fuses)
endif
endif
ifndef ISP_LOW_FUSE
ifdef BOARD_CLOCK
ISP_LOW_FUSE := $(call PARSE_BOARD,$(BOARD_TAG),menu.(speed|clock).$(BOARD_CLOCK).bootloader.low_fuses)
endif
ifndef ISP_LOW_FUSE
ISP_LOW_FUSE := $(call PARSE_BOARD,$(BOARD_TAG),menu.(chip|cpu).$(BOARD_SUB).bootloader.low_fuses)
endif
ifndef ISP_LOW_FUSE
ISP_LOW_FUSE := $(call PARSE_BOARD,$(BOARD_TAG),bootloader.low_fuses)
endif
endif
ifndef ISP_EXT_FUSE
ifdef BOARD_CLOCK
ISP_EXT_FUSE := $(call PARSE_BOARD,$(BOARD_TAG),menu.(speed|clock).$(BOARD_CLOCK).bootloader.extended_fuses)
endif
ifndef ISP_EXT_FUSE
ISP_EXT_FUSE := $(call PARSE_BOARD,$(BOARD_TAG),menu.(chip|cpu).$(BOARD_SUB).bootloader.extended_fuses)
endif
ifndef ISP_EXT_FUSE
ISP_EXT_FUSE := $(call PARSE_BOARD,$(BOARD_TAG),bootloader.extended_fuses)
endif
endif
ifndef BOOTLOADER_PATH
BOOTLOADER_PATH = $(call PARSE_BOARD,$(BOARD_TAG),bootloader.path)
endif
ifndef BOOTLOADER_FILE
BOOTLOADER_FILE := $(call PARSE_BOARD,$(BOARD_TAG),menu.(chip|cpu).$(BOARD_SUB).bootloader.file)
ifndef BOOTLOADER_FILE
BOOTLOADER_FILE := $(call PARSE_BOARD,$(BOARD_TAG),bootloader.file)
endif
endif
ifndef ISP_LOCK_FUSE_POST
ISP_LOCK_FUSE_POST = $(call PARSE_BOARD,$(BOARD_TAG),bootloader.lock_bits)
endif
ifndef HEX_MAXIMUM_SIZE
HEX_MAXIMUM_SIZE := $(call PARSE_BOARD,$(BOARD_TAG),menu.(chip|cpu).$(BOARD_SUB).upload.maximum_size)
ifndef HEX_MAXIMUM_SIZE
HEX_MAXIMUM_SIZE := $(call PARSE_BOARD,$(BOARD_TAG),upload.maximum_size)
endif
endif
endif
# Everything gets built in here (include BOARD_TAG now)
ifndef OBJDIR
OBJDIR = build-$(BOARD_TAG)
ifdef BOARD_SUB
OBJDIR = build-$(BOARD_TAG)-$(BOARD_SUB)
endif
$(call show_config_variable,OBJDIR,[COMPUTED],(from BOARD_TAG))
else
$(call show_config_variable,OBJDIR,[USER])
endif
# Now that we have ARDUINO_DIR, ARDMK_VENDOR, ARCHITECTURE and CORE,
# we can set ARDUINO_CORE_PATH.
ifndef ARDUINO_CORE_PATH
ifeq ($(strip $(CORE)),)
ARDUINO_CORE_PATH = $(ARDUINO_DIR)/hardware/$(ARDMK_VENDOR)/$(ARCHITECTURE)/cores/arduino
$(call show_config_variable,ARDUINO_CORE_PATH,[DEFAULT])
else
ARDUINO_CORE_PATH = $(ALTERNATE_CORE_PATH)/cores/$(CORE)
ifeq ($(wildcard $(ARDUINO_CORE_PATH)),)
ARDUINO_CORE_PATH = $(ARDUINO_DIR)/hardware/$(ARDMK_VENDOR)/$(ARCHITECTURE)/cores/$(CORE)
$(call show_config_variable,ARDUINO_CORE_PATH,[COMPUTED],(from ARDUINO_DIR, BOARD_TAG and boards.txt))
else
$(call show_config_variable,ARDUINO_CORE_PATH,[COMPUTED],(from ALTERNATE_CORE_PATH, BOARD_TAG and boards.txt))
endif
endif
else
$(call show_config_variable,ARDUINO_CORE_PATH,[USER])
endif
########################################################################
# Reset
ifndef RESET_CMD
ARD_RESET_ARDUINO_PATH := $(shell which ard-reset-arduino 2> /dev/null)
ifndef ARD_RESET_ARDUINO_PATH
# same level as *.mk in bin directory when checked out from git
# or in $PATH when packaged
ARD_RESET_ARDUINO_PATH = $(ARDMK_DIR)/bin/ard-reset-arduino
endif
ARD_RESET_ARDUINO := $(PYTHON_CMD) $(ARD_RESET_ARDUINO_PATH)
ifneq (,$(findstring CYGWIN,$(shell uname -s)))
# confirm user is using default cygwin unix Python (which uses ttySx) and not Windows Python (which uses COMx)
ifeq ($(PYTHON_CMD),/usr/bin/python)
RESET_CMD = $(ARD_RESET_ARDUINO) $(ARD_RESET_OPTS) $(DEVICE_PATH)
else
RESET_CMD = $(ARD_RESET_ARDUINO) $(ARD_RESET_OPTS) $(call get_monitor_port)
endif
else
RESET_CMD = $(ARD_RESET_ARDUINO) $(ARD_RESET_OPTS) $(call get_monitor_port)
endif
$(call show_config_variable,RESET_CMD,[COMPUTED],(from PYTHON_CMD, ARD_RESET_OPTS and MONITOR_PORT))
else
$(call show_config_variable,RESET_CMD,[USER])
endif
ifneq ($(CATERINA),)
ERROR_ON_CATERINA = $(error On $(BOARD_TAG), raw_xxx operation is not supported)
else
ERROR_ON_CATERINA =
endif
########################################################################
# Local sources
LOCAL_C_SRCS ?= $(wildcard *.c)
LOCAL_CPP_SRCS ?= $(wildcard *.cpp)
LOCAL_CC_SRCS ?= $(wildcard *.cc)
LOCAL_PDE_SRCS ?= $(wildcard *.pde)
LOCAL_INO_SRCS ?= $(wildcard *.ino)
LOCAL_AS_SRCS ?= $(wildcard *.S)
LOCAL_SRCS = $(LOCAL_C_SRCS) $(LOCAL_CPP_SRCS) \
$(LOCAL_CC_SRCS) $(LOCAL_PDE_SRCS) \
$(LOCAL_INO_SRCS) $(LOCAL_AS_SRCS)
LOCAL_OBJ_FILES = $(LOCAL_C_SRCS:.c=.c.o) $(LOCAL_CPP_SRCS:.cpp=.cpp.o) \
$(LOCAL_CC_SRCS:.cc=.cc.o) $(LOCAL_PDE_SRCS:.pde=.pde.o) \
$(LOCAL_INO_SRCS:.ino=.ino.o) $(LOCAL_AS_SRCS:.S=.S.o)
LOCAL_OBJS = $(patsubst %,$(OBJDIR)/%,$(LOCAL_OBJ_FILES))
ifeq ($(words $(LOCAL_SRCS)), 0)
$(error At least one source file (*.ino, *.pde, *.cpp, *c, *cc, *.S) is needed)
endif
# CHK_SOURCES is used by flymake
# flymake creates a tmp file in the same directory as the file under edition
# we must skip the verification in this particular case
ifeq ($(strip $(CHK_SOURCES)),)
ifeq ($(strip $(NO_CORE)),)
# Ideally, this should just check if there are more than one file
ifneq ($(words $(LOCAL_PDE_SRCS) $(LOCAL_INO_SRCS)), 1)
ifeq ($(words $(LOCAL_PDE_SRCS) $(LOCAL_INO_SRCS)), 0)
$(call show_config_info,No .pde or .ino files found. If you are compiling .c or .cpp files then you need to explicitly include Arduino header files)
else
#TODO: Support more than one file. https://github.com/sudar/Arduino-Makefile/issues/49
$(error Need exactly one .pde or .ino file. This makefile doesn\'t support multiple .ino/.pde files yet)
endif
endif
endif
endif
# core sources
ifeq ($(strip $(NO_CORE)),)
ifdef ARDUINO_CORE_PATH
CORE_C_SRCS = $(wildcard $(ARDUINO_CORE_PATH)/*.c)
CORE_C_SRCS += $(wildcard $(ARDUINO_CORE_PATH)/$(TOOL_PREFIX)-libc/*.c)
CORE_CPP_SRCS = $(wildcard $(ARDUINO_CORE_PATH)/*.cpp)
CORE_AS_SRCS = $(wildcard $(ARDUINO_CORE_PATH)/*.S)
# ArduinoCore-API
CORE_C_SRCS += $(wildcard $(ARDUINO_CORE_PATH)/api/*.c)
CORE_CPP_SRCS += $(wildcard $(ARDUINO_CORE_PATH)/api/*.cpp)
# USB Core if samd or sam
ifeq ($(findstring sam, $(strip $(ARCHITECTURE))), sam)
CORE_C_SRCS += $(wildcard $(ARDUINO_CORE_PATH)/avr/*.c) # avr core emulation files
CORE_C_SRCS += $(wildcard $(ARDUINO_CORE_PATH)/USB/*.c)
CORE_CPP_SRCS += $(wildcard $(ARDUINO_CORE_PATH)/USB/*.cpp)
endif
ifneq ($(strip $(NO_CORE_MAIN_CPP)),)
CORE_CPP_SRCS := $(filter-out %main.cpp, $(CORE_CPP_SRCS))
$(call show_config_info,NO_CORE_MAIN_CPP set so core library will not include main.cpp,[MANUAL])
endif
# Add core files for sam devices in CORE_OJBS filtering specific paths
ifdef SAM_CORE_PATH
SAM_CORE_OBJ_FILES = $(SAM_CORE_C_SRCS:.c=.c.o) $(SAM_CORE_CPP_SRCS:.cpp=.cpp.o) $(SAM_CORE_AS_SRCS:.S=.S.o)
# variant core files
CORE_OBJS += $(patsubst $(SAM_CORE_PATH)/%, \
$(OBJDIR)/core/%, $(filter $(SAM_CORE_PATH)/%, $(SAM_CORE_OBJ_FILES)))
# libsam on Due
ifdef SAM_LIBSAM_PATH
CORE_OBJS += $(patsubst $(SAM_LIBSAM_PATH)/source/%, \
$(OBJDIR)/core/%, $(filter $(SAM_LIBSAM_PATH)/source/%, $(SAM_CORE_OBJ_FILES)))
endif
# chip sources on Due
ifdef SAM_SYSTEM_PATH
CORE_OBJS += $(patsubst $(SAM_SYSTEM_PATH)/source/%, \
$(OBJDIR)/core/%, $(filter $(SAM_SYSTEM_PATH)/source/%, $(SAM_CORE_OBJ_FILES)))
endif
endif
CORE_OBJ_FILES = $(CORE_C_SRCS:.c=.c.o) $(CORE_CPP_SRCS:.cpp=.cpp.o) $(CORE_AS_SRCS:.S=.S.o)
CORE_OBJS += $(patsubst $(ARDUINO_CORE_PATH)/%, \
$(OBJDIR)/core/%,$(CORE_OBJ_FILES))
endif
else
$(call show_config_info,NO_CORE set so core library will not be built,[MANUAL])
endif
########################################################################
# Determine ARDUINO_LIBS automatically
ifndef ARDUINO_LIBS
# automatically determine included libraries
ARDUINO_LIBS += $(filter $(notdir $(wildcard $(ARDUINO_DIR)/libraries/*)), \
$(shell sed -ne 's/^ *\# *include *[<\"]\(.*\)\.h[>\"]/\1/p' $(LOCAL_SRCS)))
ARDUINO_LIBS += $(filter $(notdir $(wildcard $(ARDUINO_SKETCHBOOK)/libraries/*)), \
$(shell sed -ne 's/^ *\# *include *[<\"]\(.*\)\.h[>\"]/\1/p' $(LOCAL_SRCS)))
ARDUINO_LIBS += $(filter $(notdir $(wildcard $(USER_LIB_PATH)/*)), \
$(shell sed -ne 's/^ *\# *include *[<\"]\(.*\)\.h[>\"]/\1/p' $(LOCAL_SRCS)))
ARDUINO_LIBS += $(filter $(notdir $(wildcard $(ARDUINO_PLATFORM_LIB_PATH)/*)), \
$(shell sed -ne 's/^ *\# *include *[<\"]\(.*\)\.h[>\"]/\1/p' $(LOCAL_SRCS)))
endif
########################################################################