Build system

Command line options for make

All option names must be lower case for not to override internals.

target=<target>
mcu=<mcu>
f_cpu=<frequency>
use="<use1> <use2>"
defines="<define1> <define2>"
cflags="<flag1> <flag2>"

Directly add these to CFLAGS.

ldflags="<flag1> <flag2>"

Directly add these to LDFLAGS.

Makefile options

TARGET = <TARGET>

In Makefile you MUST use upper case for target value. In command line you can also use lower case.

Define default target in Makefile:

TARGET = X86

Then compile using another target:

make target=avr
MCU_<TARGET> = <MCU>

Target specific default MCU. Could be ATmega8 for AVR targets or 16F87 for 8-bit PIC targets.

Define default MCU in Makefile:

TARGET = X86
MCU_AVR = atmega328p
MCU_PIC8 = 16f84a

Then compile using another MCU:

make target=avr mcu=atmega8
make target=pic8 mcu=16f87
F_CPU = <FREQUENCY>

Generic default CPU clock speed needed by some targets like AVR and 8-bit PIC.

Define in Makefile:

F_CPU = 1000000

Then override from command line:

make f_cpu=8000000
F_CPU_<TARGET> = <FREQUENCY>

Same as F_CPU_<TARGET> but TARGET specific.

F_CPU_<MCU> = <FREQUENCY>

Same as F_CPU_<TARGET> but MCU specific.

USE += ...

Add used components. Normally you want some since almost nothing is included as default.

Makefile with I2C and logging enabled:

USE += I2C LOG

Then compile by adding GPIO and using I2C in bitbang mode (which needs GPIO):

make use="gpio i2c_bitbang"
USE_<TARGET> += ...

Same as USE but TARGET specific.

USE_<MCU> += ...

Same as USE but MCU specific.

DEFINES += ...

Add defines. This basically is a shorthand for CFLAGS += -D<DEFINE>.

Usage in Makefile:

DEFINES += MY_DEFINE OTHER_DEFINE
DEFINES += MY_PI=3.1415

From command line:

make defines="CMD_DEFINE1 CMD_DEFINE2=123"
DEFINES_<TARGET> += ...

Same as DEFINES but TARGET specific.

DEFINES_<MCU> += ...

Same as DEFINES but MCU specific.

CFLAGS += ...

Compiler flags.

CFLAGS_<TARGET> += ...

Compiler flags.

CFLAGS_<MCU> += ...

Compiler flags.

LDFLAGS += ...

Linker flags.

LDFLAGS_<TARGET> += ...

Linker flags.

LDFLAGS_<MCU> += ...

Linker flags.