Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 0c4549a400
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 97 lines (81 sloc) 2.726 kb
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

{% from 'Makefile.common.jinja' import transform_sketches with context %}
{% set src_build_dir = e.build_dir|pjoin(e.src_dir|basename) %}

{#
# Macros to transform *.c and *.cpp -> *.o
#}
{% macro compile(filemap, compiler) %}
{% for source, target in filemap %}
{{ target.path }} : {{ source.path }}
@echo {{ (source.dirname|basename|pjoin(source.filename))|colorize('yellow') }}
@mkdir -p {{ target.path|dirname }}
@{{ compiler }} -o $@ -c $^
{% endfor %}
{% endmacro %}

{% macro compile_c(filemap, warning=True) %}
{{ compile(filemap, e.cc ~ ' ' ~ e.cflags ~ (' -Wall' if warning else ' -w')) }}
{% endmacro %}

{% macro compile_cpp(filemap, warning=True) %}
{{ compile(filemap, e.cxx ~ ' ' ~ e.cflags ~ ' ' ~ e.cxxflags ~ (' -Wall' if warning else ' -w')) }}
{% endmacro %}


{#
# Macro to build an AVR library
# source_dir - dir where *.c and *.cpp are
# name - desired library name without suffix and prefix,
# e.g. Ethernet
# add_to - list where result path should be added
#}
{% macro build_library(source_dir, name, add_to) %}
{% set libdir = e.build_dir|pjoin(name) %}
{% set c = source_dir|glob('*.c')|filemap(libdir, e.names.obj) %}
{% set cpp = (source_dir|glob('*.cpp'))|filemap(libdir, e.names.obj) %}
{% set libpath = libdir|pjoin(name|libname) %}
{% set libobjs = c.target_paths() + cpp.target_paths() %}
{{ compile_c(c, warning=False) }}
{{ compile_cpp(cpp, warning=False) }}
{{ libpath }} : {{ libobjs }}
@echo {{ ('Linking ' ~ name|libname) |colorize('green') }}
@{{ e.ar }} rcs $@ $^
{% do add_to.insert(0, libpath) %}
{% endmacro %}

{#
# library sources -> *.a
#}
{% set libs = SpaceList() %}
{{ build_library(e.arduino_core_dir, 'core', add_to=libs) }}
{% for libdir in e.extra_libs %}
{{ build_library(libdir, libdir|basename, add_to=libs) }}
{% endfor %}

{#
# sketches -> *.cpp
#}
{% set sketch_cpps = SpaceList() %}
{{ transform_sketches(e.src_dir, sketch_cpps) }}

{#
# *.c -> *.o
#}
{% set c = e.src_dir|glob('*.c')|filemap(src_build_dir, e.names.obj) %}
{{ compile_c(c) }}

{#
# *.cpp -> *.o
#}
{% set cpp = (e.src_dir|glob('*.cpp') + sketch_cpps)|filemap(src_build_dir, e.names.obj) %}
{{ compile_cpp(cpp) }}

{#
# *.o -> elf
#}
{% set objs = c.target_paths() + cpp.target_paths() + libs %}
{% set elf = e.build_dir|pjoin('firmware.elf') %}
{{ elf }} : {{ objs }}
@echo {{ 'Linking firmware.elf'|colorize('green') }}
@{{ e.cc }} {{ e.elfflags }} -o $@ $^ -lm

{#
# elf -> hex
#}
{{ e.hex_path }} : {{ elf }}
@echo {{ ('Converting to ' ~ e.hex_filename)|colorize('green') }}
@{{ e.objcopy }} -O ihex -R .eeprom $^ $@

include {{ e.deps }}

all : {{ e.hex_path }}

{#
vim:noexpandtab filetype=jinja
#}
Something went wrong with that request. Please try again.