2016-07-14 21:10:51 +02:00
|
|
|
#! /usr/bin/make -f
|
|
|
|
#---
|
|
|
|
#
|
|
|
|
# gint project Makefile.
|
|
|
|
#
|
|
|
|
#---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#---
|
|
|
|
# Project variables.
|
|
|
|
#---
|
|
|
|
|
|
|
|
# Modules
|
2016-08-29 11:29:07 +02:00
|
|
|
modules-gint = core clock keyboard mmu mpu rtc screen timer \
|
2016-11-05 22:00:23 +01:00
|
|
|
bopti display gray tales events
|
2016-08-08 15:01:33 +02:00
|
|
|
modules-libc = setjmp string stdio stdlib time
|
2016-07-14 21:10:51 +02:00
|
|
|
|
|
|
|
# Targets
|
|
|
|
target-g1a = gintdemo.g1a
|
|
|
|
target-lib = libgint.a
|
|
|
|
target-std = libc.a
|
|
|
|
|
|
|
|
# Tools
|
2016-11-05 22:00:23 +01:00
|
|
|
cc = sh3eb-elf-gcc
|
|
|
|
as = sh3eb-elf-as
|
|
|
|
ar = sh3eb-elf-ar
|
|
|
|
ob = sh3eb-elf-objcopy
|
|
|
|
wr = g1a-wrapper
|
2016-07-14 21:10:51 +02:00
|
|
|
|
|
|
|
# Flags
|
2016-07-28 18:12:07 +02:00
|
|
|
cflags = -m3 -mb -nostdlib -I include -ffreestanding -std=c11 -Os \
|
2016-11-05 22:00:23 +01:00
|
|
|
-W -Wall -Wextra -pedantic @gcc.cfg
|
2016-07-14 21:10:51 +02:00
|
|
|
|
|
|
|
# Demo application (could be done better)
|
|
|
|
demo-src = $(notdir $(wildcard demo/*.[cs]))
|
2016-07-28 18:12:07 +02:00
|
|
|
demo-dep = $(wildcard demo/*.h)
|
2016-07-14 21:10:51 +02:00
|
|
|
demo-ld = demo/gintdemo.ld
|
|
|
|
demo-icon = demo/icon.bmp
|
|
|
|
demo-res = $(notdir $(wildcard demo/resources/*))
|
|
|
|
demo-obj = $(patsubst %,build/demo_%.o,$(demo-src) $(demo-res))
|
|
|
|
demo-elf = build/gintdemo.elf
|
|
|
|
demo-bin = build/gintdemo.bin
|
2016-07-25 22:38:47 +02:00
|
|
|
demo-libs = -L. -lgint -lc -lgcc
|
2016-07-14 21:10:51 +02:00
|
|
|
|
2016-07-25 09:04:22 +02:00
|
|
|
# Specific objects
|
|
|
|
obj-lib-spec = build/display_font_system.bmp.o
|
|
|
|
obj-std-spec =
|
|
|
|
|
2016-11-05 22:00:23 +01:00
|
|
|
# Configuration files
|
|
|
|
config = gcc.cfg
|
2016-07-14 21:10:51 +02:00
|
|
|
|
|
|
|
#---
|
|
|
|
# Automatic variables.
|
|
|
|
#---
|
|
|
|
|
|
|
|
# Modules are subfolders of src/.
|
|
|
|
modules = $(modules-gint) $(modules-libc)
|
|
|
|
|
|
|
|
define n
|
|
|
|
# This is a newline character.
|
|
|
|
|
|
|
|
endef
|
|
|
|
|
2016-11-05 22:00:23 +01:00
|
|
|
ifeq ("$(wildcard $(config))","")
|
|
|
|
$(error "Configuration files are missing. Did you ./configure?")
|
|
|
|
endif
|
|
|
|
|
2016-07-14 21:10:51 +02:00
|
|
|
# Module-scope variables.
|
|
|
|
$(foreach mod, $(modules), $(eval \
|
|
|
|
mod-$(mod)-c = $(notdir $(wildcard src/$(mod)/*.c)) $n\
|
|
|
|
mod-$(mod)-asm = $(notdir $(wildcard src/$(mod)/*.s)) $n\
|
|
|
|
mod-$(mod)-src = $$(mod-$(mod)-c)$$(mod-$(mod)-asm) $n\
|
|
|
|
mod-$(mod)-obj = $$(patsubst %,build/$(mod)_%.o,$$(mod-$(mod)-src)) \
|
|
|
|
))
|
|
|
|
|
|
|
|
# Target-scope variables.
|
2016-07-25 09:04:22 +02:00
|
|
|
obj-std = $(foreach mod,$(modules-libc),$(mod-$(mod)-obj)) $(obj-std-spec)
|
|
|
|
obj-lib = $(foreach mod,$(modules-gint),$(mod-$(mod)-obj)) $(obj-lib-spec)
|
|
|
|
|
|
|
|
# Dependencies
|
|
|
|
hdr-dep = $(wildcard include/*.h include/internals/*.h)
|
2016-07-14 21:10:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#---
|
|
|
|
# Rule templates.
|
|
|
|
#---
|
2016-05-05 11:49:05 +02:00
|
|
|
|
2016-11-05 22:00:23 +01:00
|
|
|
#ifndef VERBOSE
|
|
|
|
#$(note "default full log")
|
|
|
|
#VERBOSE =
|
|
|
|
#endif
|
|
|
|
|
2016-07-06 11:28:51 +02:00
|
|
|
# C source file template:
|
|
|
|
# $1 module name
|
2016-07-14 21:10:51 +02:00
|
|
|
# $2 filename
|
2016-07-28 18:12:07 +02:00
|
|
|
# $3 dependencies
|
2016-07-06 11:28:51 +02:00
|
|
|
define rule-c-source
|
2016-11-05 22:00:23 +01:00
|
|
|
build/$1_$2.o: src/$1/$2 $3 $(config)
|
|
|
|
$(if $(VERBOSE),,@ printf '\e[34;1msrc \u00bb\e[0m cc $$<\n')
|
|
|
|
$(if $(VERBOSE),,@) $(cc) -c $$< -o $$@ $(cflags) -I src/$1
|
2016-07-14 21:10:51 +02:00
|
|
|
endef
|
|
|
|
|
|
|
|
# asm source file template:
|
|
|
|
# $1 module name
|
|
|
|
# $2 filename
|
|
|
|
define rule-asm-source
|
2016-11-05 22:00:23 +01:00
|
|
|
build/$1_$2.o: src/$1/$2 $(config)
|
|
|
|
$(if $(VERBOSE),,@ printf '\e[34;1msrc \u00bb\e[0m as $$<\n')
|
|
|
|
$(if $(VERBOSE),,@) $(as) -c $$< -o $$@
|
2016-07-06 11:28:51 +02:00
|
|
|
endef
|
2016-05-05 11:49:05 +02:00
|
|
|
|
2016-07-14 21:10:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
#---
|
|
|
|
# Building.
|
|
|
|
#---
|
|
|
|
|
|
|
|
# Generic rules
|
|
|
|
|
2016-11-11 10:43:13 +01:00
|
|
|
all: $(config) $(target-std) $(target-lib) $(target-g1a)
|
2016-11-05 22:00:23 +01:00
|
|
|
@ printf '\e[32;1mmsg \u00bb\e[0m All done!\n'
|
2016-07-14 21:10:51 +02:00
|
|
|
|
|
|
|
build:
|
2016-11-11 10:43:13 +01:00
|
|
|
$(if $(VERBOSE),,@ printf '\e[35;1mdir \u00bb\e[0m mkdir $@\n')
|
|
|
|
$(if $(VERBOSE),,@) mkdir -p $@
|
|
|
|
|
|
|
|
$(obj-std) $(obj-lib) $(demo-obj): | build
|
2016-11-05 22:00:23 +01:00
|
|
|
|
|
|
|
$(target-std): $(config) $(obj-std)
|
|
|
|
$(if $(VERBOSE),,@ printf '\e[35;1mlib \u00bb\e[0m ar $@\n')
|
|
|
|
$(if $(VERBOSE),,@) $(ar) rcs $@ $(obj-std)
|
|
|
|
@ printf '\e[32;1mmsg \u00bb\e[0m Succesfully built libc ('
|
|
|
|
@ printf $$(stat -c %s $@)
|
|
|
|
@ printf ' bytes)\n\n'
|
|
|
|
|
|
|
|
$(target-lib): $(config) $(target-std) $(obj-lib)
|
|
|
|
$(if $(VERBOSE),,@ printf '\e[35;1mlib \u00bb\e[0m ar $@\n')
|
|
|
|
$(if $(VERBOSE),,@) $(ar) rcs $@ $(obj-lib)
|
|
|
|
@ printf '\e[32;1mmsg \u00bb\e[0m Succesfully built libgint ('
|
|
|
|
@ printf $$(stat -c %s $@)
|
|
|
|
@ printf ' bytes)\n\n'
|
|
|
|
|
|
|
|
$(target-g1a): $(config) $(target-std) $(target-lib) $(demo-obj)
|
|
|
|
$(if $(VERBOSE),,@ printf '\e[35;1mexe \u00bb\e[0m ld -o $(demo-elf)\n')
|
|
|
|
$(if $(VERBOSE),,@) $(cc) -o $(demo-elf) $(cflags) -T $(demo-ld) $(demo-obj) $(demo-libs)
|
|
|
|
$(if $(VERBOSE),,@ printf '\e[35;1mexe \u00bb\e[0m objcopy -o $(demo-bin)\n')
|
|
|
|
$(if $(VERBOSE),,@) $(ob) -R .comment -R .bss -O binary $(demo-elf) $(demo-bin)
|
|
|
|
$(if $(VERBOSE),,@ printf '\e[35;1mexe \u00bb\e[0m g1a-wrapper -o $@\n')
|
|
|
|
$(if $(VERBOSE),,@) $(wr) $(demo-bin) -o $@ -i $(demo-icon)
|
|
|
|
@ printf '\e[32;1mmsg \u00bb\e[0m Succesfully built demo application ('
|
|
|
|
@ printf $$(stat -c %s $@)
|
|
|
|
@ printf ' bytes)\n\n'
|
2016-07-14 21:10:51 +02:00
|
|
|
|
|
|
|
# Automated rules
|
|
|
|
|
|
|
|
$(foreach mod,$(modules), \
|
|
|
|
$(foreach source,$(mod-$(mod)-c), $(eval \
|
2016-07-28 18:12:07 +02:00
|
|
|
$(call rule-c-source,$(mod),$(source),$(hdr-dep)))) \
|
2016-07-14 21:10:51 +02:00
|
|
|
$(foreach source,$(mod-$(mod)-asm), $(eval \
|
|
|
|
$(call rule-asm-source,$(mod),$(source)))) \
|
|
|
|
)
|
|
|
|
|
2016-07-25 09:04:22 +02:00
|
|
|
# Specific rules
|
|
|
|
|
2016-07-14 21:10:51 +02:00
|
|
|
# This one should not be optimized. It makes __attribute__((interrupt_handler))
|
2016-11-05 22:00:23 +01:00
|
|
|
# buggy... maybe. Anyway there's some bug in this file that I can't fix now.
|
|
|
|
build/core_gint.c.o: src/core/gint.c $(mod-core-dep) $(config)
|
|
|
|
$(if $(VERBOSE),,@ printf '\e[34;1msrc \u00bb\e[0m cc $<\n')
|
|
|
|
$(if $(VERBOSE),,@) $(cc) -c $< -o $@ $(cflags) -I src/core -O0
|
2016-07-25 09:04:22 +02:00
|
|
|
|
|
|
|
build/display_font_system.bmp.o: src/display/font_system.bmp
|
2016-11-05 22:00:23 +01:00
|
|
|
$(if $(VERBOSE),,@ printf '\e[36;1mres \u00bb\e[0m fxconv $<\n')
|
|
|
|
$(if $(VERBOSE),,@) fxconv $< -o $@ --font -n gint_font_system
|
2016-07-14 21:10:51 +02:00
|
|
|
|
|
|
|
# Demo application
|
|
|
|
|
2016-11-05 22:00:23 +01:00
|
|
|
build/demo_%.c.o: demo/%.c $(hdr-dep) $(demo-dep) $(config)
|
|
|
|
$(if $(VERBOSE),,@ printf '\e[34;1msrc \u00bb\e[0m cc $<\n')
|
|
|
|
$(if $(VERBOSE),,@) $(cc) -c $< -o $@ $(cflags)
|
2016-07-14 21:10:51 +02:00
|
|
|
|
2016-07-25 09:04:22 +02:00
|
|
|
build/demo_font_%.bmp.o: demo/resources/font_%.bmp
|
2016-11-05 22:00:23 +01:00
|
|
|
$(if $(VERBOSE),,@ printf '\e[36;1mres \u00bb\e[0m fxconv $<\n')
|
|
|
|
$(if $(VERBOSE),,@) fxconv $< -o $@ --font -n $(patsubst demo/resources/%.bmp,res_%,$<)
|
2016-07-25 09:04:22 +02:00
|
|
|
|
2016-07-14 21:10:51 +02:00
|
|
|
build/demo_%.bmp.o: demo/resources/%.bmp
|
2016-11-05 22:00:23 +01:00
|
|
|
$(if $(VERBOSE),,@ printf '\e[36;1mres \u00bb\e[0m fxconv $<\n')
|
|
|
|
$(if $(VERBOSE),,@) fxconv $< -o $@ -n $(patsubst demo/resources/%.bmp,res_%,$<)
|
2016-07-14 21:10:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#---
|
|
|
|
# Cleaning and others.
|
|
|
|
#---
|
|
|
|
|
|
|
|
clean:
|
2016-11-11 10:43:13 +01:00
|
|
|
@ rm -rf build
|
2016-07-14 21:10:51 +02:00
|
|
|
|
|
|
|
mrproper: clean
|
|
|
|
@ rm -f $(target-g1a) $(target-lib) $(target-std)
|
2016-11-05 22:00:23 +01:00
|
|
|
@ rm -f $(config)
|
2016-07-14 21:10:51 +02:00
|
|
|
|
|
|
|
distclean: mrproper
|
|
|
|
|
|
|
|
install:
|
2016-08-29 11:29:07 +02:00
|
|
|
p7 send -f $(target-g1a)
|
2016-07-14 21:10:51 +02:00
|
|
|
|
|
|
|
|
2016-11-11 10:43:13 +01:00
|
|
|
.PHONY: all clean mrproper distclean install help
|