Advertisement
Guest User

Untitled

a guest
Sep 26th, 2013
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 22.44 KB | None | 0 0
  1. ########################################################################
  2. #
  3. # Arduino command line tools Makefile
  4. # System part (i.e. project independent)
  5. #
  6. # Copyright (C) 2010,2011,2012 Martin Oldfield <m@mjo.tc>, based on
  7. # work that is copyright Nicholas Zambetti, David A. Mellis & Hernando
  8. # Barragan.
  9. #
  10. # This file is free software; you can redistribute it and/or modify it
  11. # under the terms of the GNU Lesser General Public License as
  12. # published by the Free Software Foundation; either version 2.1 of the
  13. # License, or (at your option) any later version.
  14. #
  15. # Adapted from Arduino 0011 Makefile by M J Oldfield
  16. #
  17. # Original Arduino adaptation by mellis, eighthave, oli.keller
  18. #
  19. # Version 0.1  17.ii.2009  M J Oldfield
  20. #
  21. #         0.2  22.ii.2009  M J Oldfield
  22. #                          - fixes so that the Makefile actually works!
  23. #                          - support for uploading via ISP
  24. #                          - orthogonal choices of using the Arduino for
  25. #                            tools, libraries and uploading
  26. #
  27. #         0.3  21.v.2010   M J Oldfield
  28. #                          - added proper license statement
  29. #                          - added code from Philip Hands to reset
  30. #                            Arduino prior to upload
  31. #
  32. #         0.4  25.v.2010   M J Oldfield
  33. #                          - tweaked reset target on Philip Hands' advice
  34. #
  35. #         0.5  23.iii.2011 Stefan Tomanek
  36. #                          - added ad-hoc library building
  37. #              17.v.2011   M J Oldfield
  38. #                          - grabbed said version from Ubuntu
  39. #
  40. #         0.6  22.vi.2011  M J Oldfield
  41. #                          - added ard-parse-boards supports
  42. #                          - added -lc to linker opts,
  43. #                            on Fabien Le Lez's advice
  44. #
  45. #         0.7  12.vii.2011 M J Oldfield
  46. #                          - moved -lm to the end of linker opts,
  47. #                        to solve Frank Knopf's problem;
  48. #                          - added -F to stty opts: Craig Hollabaugh
  49. #                        reckons it's good for Ubuntu
  50. #
  51. #         0.8  12.ii.2012  M J Oldfield
  52. #                          - Patches for Arduino 1.0 IDE:
  53. #                              support .ino files;
  54. #                              handle board 'variants';
  55. #                              tweaked compile flags.
  56. #                          - Build a library from all the system
  57. #                            supplied code rather than linking the .o
  58. #                            files directly.
  59. #                          - Let TARGET default to current directory
  60. #                as per Daniele Vergini's patch.
  61. #                          - Add support for .c files in system
  62. #                            libraries: Dirk-Willem van Gulik and Evan
  63. #                            Goldenberg both reported this and
  64. #                            provided patches in the same spirit.
  65. #
  66. #          0.9 26.iv.2012  M J Oldfield
  67. #                          - Allow the punter to specify boards.txt
  68. #                            file and parser independently (after
  69. #                            Peplin and Brotchie on github)
  70. #              - Support user libraries (Peplin's patch)
  71. #                          - Remove main.cpp if NO_CORE_MAIN_CPP is
  72. #                            defined (ex Peplin)
  73. #                          - Added a monitor target which talks to the
  74. #                            Arduino serial port (Peplin's suggestion)
  75. #                          - Rejigged PATH calculations for general
  76. #                            tidiness (ex Peplin)
  77. #                          - Moved the reset target to Perl for
  78. #                            clarity and better error handling (ex
  79. #                            Daniele Vergini)
  80. #
  81. #          0.10 17.ix.12   M J Oldfield
  82. #            - Added installation notes for Fedora (ex Rickard Lindberg).
  83. #            - Changed size target so that it looks at the ELF object,
  84. #              not the hexfile (ex Jared Szechy and Scott Howard).
  85. #            - Fixed ARDUNIO typo in README.md (ex Kalin Kozhuharov).
  86. #            - Tweaked OBJDIR handling (ex Matthias Urlichs and Scott Howard).
  87. #            - Changed the name of the Debian/Ubuntu package (ex
  88. #              Scott Howard).
  89. #            - Only set AVRDUDE_CONF if it's not set (ex Tom Hall).
  90. #            - Added support for USB_PID/VID used by the Leonardo (ex Dan
  91. #              Villiom Podlaski Christiansen and Marc Plano-Lesay).
  92. #                      
  93. ########################################################################
  94. #
  95. # PATHS YOU NEED TO SET UP
  96. #
  97. # I've reworked the way paths to executables are constructed in this
  98. # version (0.9) of the Makefile.
  99. #
  100. # We need to worry about three different sorts of file:
  101. #
  102. # 1. Things which are included in this distribution e.g. ard-parse-boards
  103. #    => ARDMK_DIR
  104. #
  105. # 2. Things which are always in the Arduino distribution e.g.
  106. #    boards.txt, libraries, &c.
  107. #    => ARDUINO_DIR
  108. #
  109. # 3. Things which might be bundled with the Arduino distribution, but
  110. #    might come from the system. Most of the toolchain is like this:
  111. #    on Linux it's supplied by the system.
  112. #    => AVR_TOOLS_DIR
  113. #
  114. # Having set these three variables, we can work out the rest assuming
  115. # that things are canonically arranged beneath the directories defined
  116. # above.
  117. #
  118. # On the Mac you might want to set:
  119. #
  120. #   ARDUINO_DIR   = /Applications/Arduino.app/Contents/Resources/Java
  121. #   ARDMK_DIR     = /usr/local
  122. #
  123. # On Debian systems, you might prefer:
  124. #
  125. #   ARDUINO_DIR   = /usr/share/arduino
  126. #   ARDMK_DIR     = /usr
  127. #   AVR_TOOLS_DIR = /usr
  128. #
  129. # You can either set these up in the Makefile, or put them in your
  130. # environment e.g. in your .bashrc
  131. #
  132. # If you don't install the ard-... binaries to /usr/local/bin, but
  133. # instead copy them to e.g. /home/mjo/arduino.mk/bin then set
  134. #   ARDML_DIR = /home/mjo/arduino.mk
  135. #
  136. ########################################################################
  137. #
  138. # DEPENDENCIES
  139. #
  140. # The Perl programs need a couple of libraries:
  141. #    YAML
  142. #    Device::SerialPort
  143. #
  144. ########################################################################
  145. #
  146. # STANDARD ARDUINO WORKFLOW
  147. #
  148. # Given a normal sketch directory, all you need to do is to create
  149. # a small Makefile which defines a few things, and then includes this one.
  150. #
  151. # For example:
  152. #
  153. #       ARDUINO_LIBS = Ethernet Ethernet/utility SPI
  154. #       BOARD_TAG    = uno
  155. #       ARDUINO_PORT = /dev/cu.usb*
  156. #
  157. #       include /usr/share/arduino/Arduino.mk
  158. #
  159. # Hopefully these will be self-explanatory but in case they're not:
  160. #
  161. #    ARDUINO_LIBS - A list of any libraries used by the sketch (we
  162. #                   assume these are in
  163. #                   $(ARDUINO_DIR)/hardware/libraries
  164. #
  165. #    ARDUINO_PORT - The port where the Arduino can be found (only needed
  166. #                   when uploading
  167. #
  168. #    BOARD_TAG    - The ard-parse-boards tag for the board e.g. uno or mega
  169. #                   'make show_boards' shows a list
  170. #
  171. # Once this file has been created the typical workflow is just
  172. #
  173. #   $ make upload
  174. #
  175. # All of the object files are created in the build-cli subdirectory
  176. # All sources should be in the current directory and can include:
  177. #  - at most one .pde or .ino file which will be treated as C++ after
  178. #    the standard Arduino header and footer have been affixed.
  179. #  - any number of .c, .cpp, .s and .h files
  180. #
  181. # Included libraries are built in the build-cli/libs subdirectory.
  182. #
  183. # Besides make upload you can also
  184. #   make             - no upload
  185. #   make clean       - remove all our dependencies
  186. #   make depends     - update dependencies
  187. #   make reset       - reset the Arduino by tickling DTR on the serial port
  188. #   make raw_upload  - upload without first resetting
  189. #   make show_boards - list all the boards defined in boards.txt
  190. #   make monitor     - connect to the Arduino's serial port
  191. #
  192. ########################################################################
  193. #
  194. # SERIAL MONITOR
  195. #
  196. # The serial monitor just invokes the GNU screen program with suitable
  197. # options. For more information see screen (1) and search for
  198. # 'character special device'.
  199. #
  200. # The really useful thing to know is that ^A-k gets you out!
  201. #
  202. # The fairly useful thing to know is that you can bind another key to
  203. # escape too, by creating $HOME{.screenrc} containing e.g.
  204. #
  205. #    bindkey ^C kill
  206. #
  207. # If you want to change the baudrate, just set MONITOR_BAUDRATE. If you
  208. # don't set it, it defaults to 9600 baud.
  209. #
  210. ########################################################################
  211. #
  212. # PATHS
  213. #
  214. # I've reworked the way paths to executables are constructed in this
  215. # version of Makefile.
  216. #
  217. # We need to worry about three different sorts of file:
  218. #
  219. # 1. Things which are included in this distribution e.g. ard-parse-boards
  220. #    => ARDMK_DIR
  221. #
  222. # 2. Things which are always in the Arduino distribution e.g.
  223. #    boards.txt, libraries, &c.
  224. #    => ARDUINO_DIR
  225. #
  226. # 3. Things which might be bundled with the Arduino distribution, but
  227. #    might come from the system. Most of the toolchain is like this:
  228. #    on Linux it's supplied by the system.
  229. #    => AVR_TOOLS_DIR
  230. #
  231. # Having set these three variables, we can work out the rest assuming
  232. # that things are canonically arranged beneath the directories defined
  233. # above.
  234. #
  235. # So, on the Mac you might want to set:
  236. #
  237. #   ARDUINO_DIR   = /Applications/Arduino.app/Contents/Resources/Java
  238. #   ARDMK_DIR     = /usr/local
  239. #
  240. # On Debian systems, you might prefer:
  241. #
  242. #   ARDUINO_DIR   = /usr/share/arduino
  243. #   ARDMK_DIR     = /usr
  244. #   AVR_TOOLS_DIR = /usr
  245. #
  246. #
  247. #  
  248. #
  249. ########################################################################
  250. #
  251. # ARDUINO WITH ISP
  252. #
  253. # You need to specify some details of your ISP programmer and might
  254. # also need to specify the fuse values:
  255. #
  256. #     ISP_PROG     = -c stk500v2
  257. #     ISP_PORT     = /dev/ttyACM0
  258. #
  259. # You might also need to set the fuse bits, but typically they'll be
  260. # read from boards.txt, based on the BOARD_TAG variable:
  261. #    
  262. #     ISP_LOCK_FUSE_PRE  = 0x3f
  263. #     ISP_LOCK_FUSE_POST = 0xcf
  264. #     ISP_HIGH_FUSE      = 0xdf
  265. #     ISP_LOW_FUSE       = 0xff
  266. #     ISP_EXT_FUSE       = 0x01
  267. #
  268. # I think the fuses here are fine for uploading to the ATmega168
  269. # without bootloader.
  270. #
  271. # To actually do this upload use the ispload target:
  272. #
  273. #    make ispload
  274. #
  275. #
  276. ########################################################################
  277.  
  278. ########################################################################
  279. #
  280. # Default TARGET to cwd (ex Daniele Vergini)
  281. ifndef TARGET
  282. TARGET  = $(notdir $(CURDIR))
  283. endif
  284.  
  285. ########################################################################
  286.  
  287. #
  288. # Arduino version number
  289. ifndef ARDUINO_VERSION
  290. ARDUINO_VERSION = 100
  291. endif
  292.  
  293. ########################################################################
  294. # Arduino and system paths
  295. #
  296. ifdef ARDUINO_DIR
  297.  
  298. ifndef AVR_TOOLS_DIR
  299. AVR_TOOLS_DIR     = $(ARDUINO_DIR)/hardware/tools/avr
  300. # The avrdude bundled with Arduino can't find its config
  301. ifndef AVRDUDE_CONF
  302. AVRDUDE_CONF      = $(AVR_TOOLS_DIR)/etc/avrdude.conf
  303. endif
  304. endif
  305.  
  306. ifndef AVR_TOOLS_PATH
  307. AVR_TOOLS_PATH    = $(AVR_TOOLS_DIR)/bin
  308. endif
  309.  
  310. ARDUINO_LIB_PATH  = $(ARDUINO_DIR)/libraries
  311. ARDUINO_CORE_PATH = $(ARDUINO_DIR)/hardware/arduino/cores/arduino
  312. ARDUINO_VAR_PATH  = $(ARDUINO_DIR)/hardware/arduino/variants
  313.  
  314. else
  315.  
  316. echo $(error "ARDUINO_DIR is not defined")
  317.  
  318. endif
  319.  
  320. ########################################################################
  321. # Makefile distribution path
  322. #
  323. ifndef ARDMK_PATH
  324. ARDMK_PATH = /usr/bin
  325. endif
  326.  
  327. ########################################################################
  328. # Miscellanea
  329. #
  330. ifndef ARDUINO_SKETCHBOOK
  331. ARDUINO_SKETCHBOOK = $(HOME)/sketchbook
  332. endif
  333.  
  334. ifndef USER_LIB_PATH
  335. USER_LIB_PATH = $(ARDUINO_SKETCHBOOK)/libraries
  336. endif
  337.  
  338. ########################################################################
  339. # Serial monitor (just a screen wrapper)
  340. #
  341. # Quite how to construct the monitor command seems intimately tied
  342. # to the command we're using (here screen). So, read the screen docs
  343. # for more information (search for 'character special device').
  344. #
  345. ifndef MONITOR_BAUDRATE
  346. MONITOR_BAUDRATE = 9600
  347. endif
  348.  
  349. ifndef MONITOR_CMD
  350. MONITOR_CMD = screen
  351. endif
  352.  
  353. ########################################################################
  354. # Reset
  355. ifndef RESET_CMD
  356. RESET_CMD = $(ARDMK_PATH)/ard-reset-arduino $(ARD_RESET_OPTS)
  357. endif
  358.  
  359. ########################################################################
  360. # boards.txt parsing
  361. #
  362. ifndef BOARD_TAG
  363. BOARD_TAG   = uno
  364. endif
  365.  
  366. ifndef BOARDS_TXT
  367. BOARDS_TXT  = $(ARDUINO_DIR)/hardware/arduino/boards.txt
  368. endif
  369.  
  370. ifndef PARSE_BOARD
  371. PARSE_BOARD = $(ARDMK_PATH)/ard-parse-boards
  372. endif
  373.  
  374. ifndef PARSE_BOARD_OPTS
  375. PARSE_BOARD_OPTS = --boards_txt=$(BOARDS_TXT)
  376. endif
  377.  
  378. ifndef PARSE_BOARD_CMD
  379. PARSE_BOARD_CMD = $(PARSE_BOARD) $(PARSE_BOARD_OPTS)
  380. endif
  381.  
  382. # Which variant ? This affects the include path
  383. ifndef VARIANT
  384. VARIANT = $(shell $(PARSE_BOARD_CMD) $(BOARD_TAG) build.variant)
  385. endif
  386.  
  387. # processor stuff
  388. ifndef MCU
  389. MCU   = $(shell $(PARSE_BOARD_CMD) $(BOARD_TAG) build.mcu)
  390. endif
  391.  
  392. ifndef F_CPU
  393. F_CPU = $(shell $(PARSE_BOARD_CMD) $(BOARD_TAG) build.f_cpu)
  394. endif
  395.  
  396. # USB IDs for the Leonardo
  397. ifndef USB_VID
  398. USB_VID = $(shell $(PARSE_BOARD_CMD) $(BOARD_TAG) build.vid)
  399. endif
  400.  
  401. ifndef USB_PID
  402. USB_PID = $(shell $(PARSE_BOARD_CMD) $(BOARD_TAG) build.pid)
  403. endif
  404.  
  405. # normal programming info
  406. ifndef AVRDUDE_ARD_PROGRAMMER
  407. AVRDUDE_ARD_PROGRAMMER = $(shell $(PARSE_BOARD_CMD) $(BOARD_TAG) upload.protocol)
  408. endif
  409.  
  410. ifndef AVRDUDE_ARD_BAUDRATE
  411. AVRDUDE_ARD_BAUDRATE   = $(shell $(PARSE_BOARD_CMD) $(BOARD_TAG) upload.speed)
  412. endif
  413.  
  414. # fuses if you're using e.g. ISP
  415. ifndef ISP_LOCK_FUSE_PRE
  416. ISP_LOCK_FUSE_PRE  = $(shell $(PARSE_BOARD_CMD) $(BOARD_TAG) bootloader.unlock_bits)
  417. endif
  418.  
  419. ifndef ISP_LOCK_FUSE_POST
  420. ISP_LOCK_FUSE_POST = $(shell $(PARSE_BOARD_CMD) $(BOARD_TAG) bootloader.lock_bits)
  421. endif
  422.  
  423. ifndef ISP_HIGH_FUSE
  424. ISP_HIGH_FUSE      = $(shell $(PARSE_BOARD_CMD) $(BOARD_TAG) bootloader.high_fuses)
  425. endif
  426.  
  427. ifndef ISP_LOW_FUSE
  428. ISP_LOW_FUSE       = $(shell $(PARSE_BOARD_CMD) $(BOARD_TAG) bootloader.low_fuses)
  429. endif
  430.  
  431. ifndef ISP_EXT_FUSE
  432. ISP_EXT_FUSE       = $(shell $(PARSE_BOARD_CMD) $(BOARD_TAG) bootloader.extended_fuses)
  433. endif
  434.  
  435. # Everything gets built in here (include BOARD_TAG now)
  436. ifndef OBJDIR
  437. OBJDIR        = build-$(BOARD_TAG)
  438. endif
  439.  
  440. ########################################################################
  441. # Local sources
  442. #
  443. LOCAL_C_SRCS    = $(wildcard *.c)
  444. LOCAL_CPP_SRCS  = $(wildcard *.cpp)
  445. LOCAL_CC_SRCS   = $(wildcard *.cc)
  446. LOCAL_PDE_SRCS  = $(wildcard *.pde)
  447. LOCAL_INO_SRCS  = $(wildcard *.ino)
  448. LOCAL_AS_SRCS   = $(wildcard *.S)
  449. LOCAL_OBJ_FILES = $(LOCAL_C_SRCS:.c=.o)   $(LOCAL_CPP_SRCS:.cpp=.o) \
  450.         $(LOCAL_CC_SRCS:.cc=.o)   $(LOCAL_PDE_SRCS:.pde=.o) \
  451.         $(LOCAL_INO_SRCS:.ino=.o) $(LOCAL_AS_SRCS:.S=.o)
  452. LOCAL_OBJS      = $(patsubst %,$(OBJDIR)/%,$(LOCAL_OBJ_FILES))
  453.  
  454. # Dependency files
  455. DEPS            = $(LOCAL_OBJS:.o=.d)
  456.  
  457. # core sources
  458. ifeq ($(strip $(NO_CORE)),)
  459. ifdef ARDUINO_CORE_PATH
  460. CORE_C_SRCS     = $(wildcard $(ARDUINO_CORE_PATH)/*.c)
  461. CORE_CPP_SRCS   = $(wildcard $(ARDUINO_CORE_PATH)/*.cpp)
  462.  
  463. ifneq ($(strip $(NO_CORE_MAIN_CPP)),)
  464. CORE_CPP_SRCS := $(filter-out %main.cpp, $(CORE_CPP_SRCS))
  465. endif
  466.  
  467. CORE_OBJ_FILES  = $(CORE_C_SRCS:.c=.o) $(CORE_CPP_SRCS:.cpp=.o)
  468. CORE_OBJS       = $(patsubst $(ARDUINO_CORE_PATH)/%,  \
  469.             $(OBJDIR)/%,$(CORE_OBJ_FILES))
  470. endif
  471. endif
  472.  
  473.  
  474. ########################################################################
  475. # Rules for making stuff
  476. #
  477.  
  478. # The name of the main targets
  479. TARGET_HEX = $(OBJDIR)/$(TARGET).hex
  480. TARGET_ELF = $(OBJDIR)/$(TARGET).elf
  481. TARGETS    = $(OBJDIR)/$(TARGET).*
  482. CORE_LIB   = $(OBJDIR)/libcore.a
  483.  
  484. # A list of dependencies
  485. DEP_FILE   = $(OBJDIR)/depends.mk
  486.  
  487. # Names of executables
  488. CC      = $(AVR_TOOLS_PATH)/avr-gcc
  489. CXX     = $(AVR_TOOLS_PATH)/avr-g++
  490. OBJCOPY = $(AVR_TOOLS_PATH)/avr-objcopy
  491. OBJDUMP = $(AVR_TOOLS_PATH)/avr-objdump
  492. AR      = $(AVR_TOOLS_PATH)/avr-ar
  493. SIZE    = $(AVR_TOOLS_PATH)/avr-size
  494. NM      = $(AVR_TOOLS_PATH)/avr-nm
  495. REMOVE  = rm -f
  496. MV      = mv -f
  497. CAT     = cat
  498. ECHO    = echo
  499.  
  500. # General arguments
  501. SYS_LIBS      = $(patsubst %,$(ARDUINO_LIB_PATH)/%,$(ARDUINO_LIBS))
  502. USER_LIBS     = $(patsubst %,$(USER_LIB_PATH)/%,$(ARDUINO_LIBS))
  503. SYS_INCLUDES  = $(patsubst %,-I%,$(SYS_LIBS))
  504. USER_INCLUDES = $(patsubst %,-I%,$(USER_LIBS))
  505. LIB_C_SRCS    = $(wildcard $(patsubst %,%/*.c,$(SYS_LIBS)))
  506. LIB_CPP_SRCS  = $(wildcard $(patsubst %,%/*.cpp,$(SYS_LIBS)))
  507. USER_LIB_CPP_SRCS   = $(wildcard $(patsubst %,%/*.cpp,$(USER_LIBS)))
  508. USER_LIB_C_SRCS     = $(wildcard $(patsubst %,%/*.c,$(USER_LIBS)))
  509. LIB_OBJS      = $(patsubst $(ARDUINO_LIB_PATH)/%.c,$(OBJDIR)/libs/%.o,$(LIB_C_SRCS)) \
  510.         $(patsubst $(ARDUINO_LIB_PATH)/%.cpp,$(OBJDIR)/libs/%.o,$(LIB_CPP_SRCS))
  511. USER_LIB_OBJS = $(patsubst $(USER_LIB_PATH)/%.cpp,$(OBJDIR)/libs/%.o,$(USER_LIB_CPP_SRCS)) \
  512.         $(patsubst $(USER_LIB_PATH)/%.c,$(OBJDIR)/libs/%.o,$(USER_LIB_C_SRCS))
  513.  
  514. CPPFLAGS      = -mmcu=$(MCU) -DF_CPU=$(F_CPU) -DARDUINO=$(ARDUINO_VERSION) \
  515.             -I. -I$(ARDUINO_CORE_PATH) -I$(ARDUINO_VAR_PATH)/$(VARIANT) \
  516.             $(SYS_INCLUDES) $(USER_INCLUDES) -g -Os -w -Wall \
  517.             -DUSB_VID=$(USB_VID) -DUSB_PID=$(USB_PID) \
  518.             -ffunction-sections -fdata-sections
  519.  
  520. CFLAGS        = -std=gnu99
  521. CXXFLAGS      = -fno-exceptions
  522. ASFLAGS       = -mmcu=$(MCU) -I. -x assembler-with-cpp
  523. LDFLAGS       = -mmcu=$(MCU) -Wl,--gc-sections -Os
  524.  
  525. # Expand and pick the first port
  526. ARD_PORT      = $(firstword $(wildcard $(ARDUINO_PORT)))
  527.  
  528. # Implicit rules for building everything (needed to get everything in
  529. # the right directory)
  530. #
  531. # Rather than mess around with VPATH there are quasi-duplicate rules
  532. # here for building e.g. a system C++ file and a local C++
  533. # file. Besides making things simpler now, this would also make it
  534. # easy to change the build options in future
  535.  
  536. # library sources
  537. $(OBJDIR)/libs/%.o: $(ARDUINO_LIB_PATH)/%.c
  538.     mkdir -p $(dir $@)
  539.     $(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
  540.  
  541. $(OBJDIR)/libs/%.o: $(ARDUINO_LIB_PATH)/%.cpp
  542.     mkdir -p $(dir $@)
  543.     $(CC) -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@
  544.  
  545. $(OBJDIR)/libs/%.o: $(USER_LIB_PATH)/%.cpp
  546.     mkdir -p $(dir $@)
  547.     $(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
  548.  
  549. $(OBJDIR)/libs/%.o: $(USER_LIB_PATH)/%.c
  550.     mkdir -p $(dir $@)
  551.     $(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
  552.  
  553. # normal local sources
  554. # .o rules are for objects, .d for dependency tracking
  555. # there seems to be an awful lot of duplication here!!!
  556. $(OBJDIR)/%.o: %.c
  557.     $(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
  558.  
  559. $(OBJDIR)/%.o: %.cc
  560.     $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@
  561.  
  562. $(OBJDIR)/%.o: %.cpp
  563.     $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@
  564.  
  565. $(OBJDIR)/%.o: %.S
  566.     $(CC) -c $(CPPFLAGS) $(ASFLAGS) $< -o $@
  567.  
  568. $(OBJDIR)/%.o: %.s
  569.     $(CC) -c $(CPPFLAGS) $(ASFLAGS) $< -o $@
  570.  
  571. $(OBJDIR)/%.d: %.c
  572.     $(CC) -MM $(CPPFLAGS) $(CFLAGS) $< -MF $@ -MT $(@:.d=.o)
  573.  
  574. $(OBJDIR)/%.d: %.cc
  575.     $(CXX) -MM $(CPPFLAGS) $(CXXFLAGS) $< -MF $@ -MT $(@:.d=.o)
  576.  
  577. $(OBJDIR)/%.d: %.cpp
  578.     $(CXX) -MM $(CPPFLAGS) $(CXXFLAGS) $< -MF $@ -MT $(@:.d=.o)
  579.  
  580. $(OBJDIR)/%.d: %.S
  581.     $(CC) -MM $(CPPFLAGS) $(ASFLAGS) $< -MF $@ -MT $(@:.d=.o)
  582.  
  583. $(OBJDIR)/%.d: %.s
  584.     $(CC) -MM $(CPPFLAGS) $(ASFLAGS) $< -MF $@ -MT $(@:.d=.o)
  585.  
  586. # the pde -> cpp -> o file
  587. $(OBJDIR)/%.cpp: %.pde
  588.     $(ECHO) '#include "WProgram.h"' > $@
  589.     $(CAT)  $< >> $@
  590.  
  591. # the ino -> cpp -> o file
  592. $(OBJDIR)/%.cpp: %.ino
  593.     $(ECHO) '#include <Arduino.h>' > $@
  594.     $(CAT)  $< >> $@
  595.  
  596. $(OBJDIR)/%.o: $(OBJDIR)/%.cpp
  597.     $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@
  598.  
  599. $(OBJDIR)/%.d: $(OBJDIR)/%.cpp
  600.     $(CXX) -MM $(CPPFLAGS) $(CXXFLAGS) $< -MF $@ -MT $(@:.d=.o)
  601.  
  602. # core files
  603. $(OBJDIR)/%.o: $(ARDUINO_CORE_PATH)/%.c
  604.     $(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
  605.  
  606. $(OBJDIR)/%.o: $(ARDUINO_CORE_PATH)/%.cpp
  607.     $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@
  608.  
  609. # various object conversions
  610. $(OBJDIR)/%.hex: $(OBJDIR)/%.elf
  611.     $(OBJCOPY) -O ihex -R .eeprom $< $@
  612.  
  613. $(OBJDIR)/%.eep: $(OBJDIR)/%.elf
  614.     -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
  615.         --change-section-lma .eeprom=0 -O ihex $< $@
  616.  
  617. $(OBJDIR)/%.lss: $(OBJDIR)/%.elf
  618.     $(OBJDUMP) -h -S $< > $@
  619.  
  620. $(OBJDIR)/%.sym: $(OBJDIR)/%.elf
  621.     $(NM) -n $< > $@
  622.  
  623. ########################################################################
  624. #
  625. # Avrdude
  626. #
  627. ifndef AVRDUDE
  628. AVRDUDE          = $(AVR_TOOLS_PATH)/avrdude
  629. endif
  630.  
  631. AVRDUDE_COM_OPTS = -q -V -p $(MCU)
  632. ifdef AVRDUDE_CONF
  633. AVRDUDE_COM_OPTS += -C $(AVRDUDE_CONF)
  634. endif
  635.  
  636. AVRDUDE_ARD_OPTS = -c $(AVRDUDE_ARD_PROGRAMMER) -b $(AVRDUDE_ARD_BAUDRATE) -P $(ARD_PORT) $(AVRDUDE_ARD_EXTRAOPTS)
  637.  
  638. ifndef ISP_PROG
  639. ISP_PROG       = -c stk500v2
  640. endif
  641.  
  642. AVRDUDE_ISP_OPTS = -P $(ISP_PORT) $(ISP_PROG)
  643.  
  644.  
  645. ########################################################################
  646. #
  647. # Explicit targets start here
  648. #
  649.  
  650. all:        $(OBJDIR) $(TARGET_HEX)
  651.  
  652. $(TARGET_HEX): bin/$(TARGET)
  653.  
  654. $(OBJDIR):
  655.         mkdir $(OBJDIR)
  656.  
  657. $(TARGET_ELF):  $(LOCAL_OBJS) $(CORE_LIB) $(OTHER_OBJS)
  658.         $(CC) $(LDFLAGS) -o $@ $(LOCAL_OBJS) $(CORE_LIB) $(OTHER_OBJS) -lc -lm
  659.  
  660. $(CORE_LIB):    $(CORE_OBJS) $(LIB_OBJS) $(USER_LIB_OBJS)
  661.         $(AR) rcs $@ $(CORE_OBJS) $(LIB_OBJS) $(USER_LIB_OBJS)
  662.  
  663. $(DEP_FILE):    $(OBJDIR) $(DEPS)
  664.         cat $(DEPS) > $(DEP_FILE)
  665.  
  666. upload:     reset raw_upload
  667.  
  668. raw_upload: $(TARGET_HEX)
  669.         $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ARD_OPTS) \
  670.             -U flash:w:$(TARGET_HEX):i
  671.  
  672. reset:     
  673.         $(RESET_CMD) $(ARD_PORT)
  674.  
  675. # stty on MacOS likes -F, but on Debian it likes -f redirecting
  676. # stdin/out appears to work but generates a spurious error on MacOS at
  677. # least. Perhaps it would be better to just do it in perl ?
  678. reset_stty:    
  679.         for STTYF in 'stty -F' 'stty --file' 'stty -f' 'stty <' ; \
  680.           do $$STTYF /dev/tty >/dev/null 2>&1 && break ; \
  681.         done ; \
  682.         $$STTYF $(ARD_PORT)  hupcl ; \
  683.         (sleep 0.1 2>/dev/null || sleep 1) ; \
  684.         $$STTYF $(ARD_PORT) -hupcl
  685.  
  686. ispload:    $(TARGET_HEX)
  687.         $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ISP_OPTS) -e \
  688.             -U lock:w:$(ISP_LOCK_FUSE_PRE):m \
  689.             -U hfuse:w:$(ISP_HIGH_FUSE):m \
  690.             -U lfuse:w:$(ISP_LOW_FUSE):m \
  691.             -U efuse:w:$(ISP_EXT_FUSE):m
  692.         $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ISP_OPTS) -D \
  693.             -U flash:w:$(TARGET_HEX):i
  694.         $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ISP_OPTS) \
  695.             -U lock:w:$(ISP_LOCK_FUSE_POST):m
  696.  
  697. clean:
  698.         $(REMOVE) $(LOCAL_OBJS) $(CORE_OBJS) $(LIB_OBJS) $(CORE_LIB) $(TARGETS) $(DEP_FILE) $(DEPS) $(USER_LIB_OBJS)
  699.  
  700. depends:    $(DEPS)
  701.         cat $(DEPS) > $(DEP_FILE)
  702.  
  703. size:       $(OBJDIR) $(TARGET_ELF)
  704.         $(SIZE) -C --mcu=$(MCU) $(TARGET_ELF)
  705.  
  706. show_boards:   
  707.         $(PARSE_BOARD_CMD) --boards
  708.  
  709. monitor:
  710.         $(MONITOR_CMD) $(ARD_PORT) $(MONITOR_BAUDRATE)
  711.  
  712. .PHONY: all clean depends upload raw_upload reset reset_stty size show_boards monitor
  713.  
  714. include $(DEP_FILE)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement