Source

pebble / Makefile.pebble

#
# Makefile for Pebble watch projects.
#
# The makefile should define:
# 	SRCS with a list of source files.
#	TARGET := project to build
#
PEBBLE_HOME := $(HOME)/build/pebble/sdk
PYTHON := python

GCC_PREFIX := $(HOME)/arm-cs-tools/bin/arm-none-eabi-

CC := $(GCC_PREFIX)gcc
LD := $(CC)
OBJCOPY := $(GCC_PREFIX)objcopy

# If no version is specified, use a default one
VERSION ?= 0.1

BUILD_TIME := $(shell date "+%s")

ARCH_FLAGS += \
	-mcpu=cortex-m3 \
	-mthumb \

CFLAGS += \
	-std=c99 \
	$(ARCH_FLAGS) \
	-g \
	-O0 \
	-Wall \
	-Wextra \
	-Wno-error=unused-function \
	-Wno-error=unused-variable \
	-Wno-error=unused-parameter \
	-fPIE \
	-I$(PEBBLE_HOME)/include \
	-I. \
	-I.. \
	-DNDEBUG \

LDFLAGS += \
	$(ARCH_FLAGS) \
	-Wl,--warn-common \
	-fPIE \
	-Wl,-Map,$(TARGET).map,--emit-relocs \
	-T$(PEBBLE_HOME)/pebble_app.ld \

LDLIBS += \
	-L$(PEBBLE_HOME)/lib \
	-lpebble \

%.bin: %.elf
	$(OBJCOPY) -O binary $< $@
	$(PYTHON) $(PEBBLE_HOME)/waftools/inject_metadata.py \
		$@

%.pbw: %.bin
	$(PYTHON) $(PEBBLE_HOME)/tools/mkbundle.py \
		--watchapp $< \
		--watchapp-timestamp $(BUILD_TIME) \
		--req-fw 1 \
		--resources app_resources.pbpack \
		--resource-map resource_map.json \
		--resources-timestamp $(BUILD_TIME) \
		-o $@ \
		-v \

all: $(TARGET).pbw
$(TARGET).elf: $(OBJS)
	$(LD) \
		$(LDFLAGS) \
		-o $@ \
		$^ \
		$(LDLIBS) \

$(TARGET).pbw: app_resources.pbpack

#
# Every object requires that the resource_ids.auto.h be up to date
#
$(OBJS): resource_ids.auto.h

clean:
	$(RM) \
		*.{o,a,pbw,pfo,elf,bin,map} \
		a.out \
		core \
		*.pbpack \
		*.pbpack.* \
		resource_ids.auto.h \

#
# Generate a font resource from a given ttf.
#
%.pfo:
	$(PYTHON) $(PEBBLE_HOME)/tools/font/fontgen.py \
		pfo \
		$(subst .,,$(suffix $(basename $@))) \
		$< \
		$@ \

#
# Generate a resource binary from all of the fonts
#
app_resources.pbpack: \
	app_resources.pbpack.manifest \
	app_resources.pbpack.table \
	app_resources.pbpack.data \

	cat > $@ $^


RESOURCES := $(FONTS) resource_map.json

app_resources.pbpack.data: $(RESOURCES)
	cat > $@ $^

app_resources.pbpack.table: $(RESOURCES)
	$(PYTHON) $(PEBBLE_HOME)/tools/pbpack_meta_data.py \
		table \
		$@ \
		$^ \

%.manifest: %.data
	$(PYTHON) $(PEBBLE_HOME)/tools/pbpack_meta_data.py \
		manifest \
		$@ \
		$(words $(RESOURCES)) \
		$(BUILD_TIME) \
		$(VERSION) \
		$< \

# This header file name is forced by <pebble_app.h>
resource_ids.auto.h: app_resources.pbpack.data $(FONTS)
	$(PYTHON) $(PEBBLE_HOME)/tools/generate_resource_code.py \
		resource_header \
		$@ \
		RESOURCES \
		$(VERSION) \
		$(BUILD_TIME) \
		pebble_os.h \
		$< \
		$(RESOURCE_LIST) \
		resource_map.json DUMMY \