pebble / Makefile.pebble

#
# Makefile for Pebble watch projects.
#
# The makefile should define:
# 	SRCS with a list of source files.
#	TARGET := project to build
#
# Change PEBBLE_HOME to point to the sdk directory
# and GCC_PREFIX to point to your arm-none-eabi gcc tree.
# Otherwise it should "just work".
#
PEBBLE_HOME := $(HOME)/build/pebble/sdk
GCC_PREFIX := $(HOME)/arm-cs-tools/bin/arm-none-eabi-

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

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

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

#
# If no output directory is specified, put things into ../build/
#
O ?= ../build
$(eval $(shell mkdir -p $O/src))

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$O \
	-DNDEBUG \
	-Wp,-MMD,$(dir $@).$(notdir $@).d \
        -Wp,-MT,$@ \


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

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


#
# Convert the elf file to a binary file, with
# the appended Pebble metadata.
#
%.bin: %.elf
	$(OBJCOPY) -O binary $< $@
	$(PYTHON) $(PEBBLE_HOME)/waftools/inject_metadata.py \
		$@

$O/%.o: %.c
	$(CC) $(CFLAGS) -c -o $@ $<

# 
# Bundle the binary (with pebble meta data) into an application.
#
%.pbw: %.bin
	$(PYTHON) $(PEBBLE_HOME)/tools/mkbundle.py \
		--watchapp $< \
		--watchapp-timestamp $(BUILD_TIME) \
		--req-fw 1 \
		--resources $O/app_resources.pbpack \
		--resource-map $O/resource_map.json \
		--resources-timestamp $(BUILD_TIME) \
		-o $@ \
		-v \

all: $O/$(TARGET).pbw
$O/$(TARGET).pbw: $O/app_resources.pbpack
$O/$(TARGET).elf: $(addprefix $O/,$(OBJS))
	$(LD) \
		$(LDFLAGS) \
		-o $@ \
		$^ \
		$(LDLIBS) \

# Generate a fake resource_map.json file
$O/resource_map.json:
	echo > $@ \
		'{"friendlyVersion":"'$VERSION'","versionDefName":"RESOURCES"}'


#
# Every object requires that the resource_ids.auto.h be up to date
#
$(addprefix $O/,$(OBJS)): $O/src/resource_ids.auto.h

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

#
# Generate a font resource from a given ttf.
# The fonts are specified in the leaf makefiles in $(FONT) as
#
#	path-to-font:size:resource-name
#
# A somewhat complex make rule translates this list into the
# targets for each font to be generated and as well as the
# resource list to pass into the make bundle tool.
#
map = $(foreach f,$2,$(call $1,$f))

$O/%.pfo:
	$(PYTHON) $(PEBBLE_HOME)/tools/font/fontgen.py \
		pfo \
		$(subst .,,$(suffix $(basename $@))) \
		$< \
		$@ \

mkfont_rules = \
	$(eval F = $(word 1,$1)) \
	$(eval S = $(word 2,$1)) \
	$(eval R = $(word 3,$1)) \
	$(eval $(info rules '$F' '$S' '$R')) \
	$(eval $O/$R.$S.pfo: $F) \
	$(eval FONT_LIST += $O/$R.$S.pfo) \
	$(eval RESOURCE_LIST += $O/$R.$S.pfo $R) \

mkfont = \
	$(info mkfont '$(1)') \
	$(call mkfont_rules,$(subst :, ,$1)) \

$(eval $(call map,mkfont,$(FONTS)))


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

	cat > $@ $^


RESOURCES := $(FONT_LIST) $O/resource_map.json

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

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

$O/%.manifest: $O/%.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>
$O/src/resource_ids.auto.h: \
	$O/app_resources.pbpack.data \
	$(FONT_LIST) \

	$(PYTHON) $(PEBBLE_HOME)/tools/generate_resource_code.py \
		resource_header \
		$@ \
		RESOURCES \
		$(VERSION) \
		$(BUILD_TIME) \
		pebble_os.h \
		$< \
		$(RESOURCE_LIST) \
		$O/resource_map.json DUMMY \

# Bring in all of the generated dependency files
-include $O/.*.o.d
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.