summaryrefslogtreecommitdiff
path: root/digital
diff options
context:
space:
mode:
authorNicolas Schodet2012-10-11 19:13:35 +0200
committerNicolas Schodet2012-10-21 18:56:29 +0200
commit143379df9873622ffe938592cd27e89a95361ddf (patch)
tree0b28a0da8a3545d8393f8cd02e952c53b52f7e07 /digital
parent77c08e656c86fa3e9da5de1c3abdcb45d67dc9a2 (diff)
digital/ucoolib: add ucoolib build system and basic arch module
Diffstat (limited to 'digital')
-rw-r--r--digital/ucoolib/build/arch.mk106
-rw-r--r--digital/ucoolib/build/host.mk18
-rw-r--r--digital/ucoolib/build/macros.mk17
-rw-r--r--digital/ucoolib/build/setup.mk26
-rw-r--r--digital/ucoolib/build/stm32f4.mk35
-rw-r--r--digital/ucoolib/build/top.mk58
-rw-r--r--digital/ucoolib/ucoolib/arch/Module1
-rw-r--r--digital/ucoolib/ucoolib/arch/stm32f4/stm32f4.ld6
-rw-r--r--digital/ucoolib/ucoolib/arch/syscalls.newlib.c27
9 files changed, 294 insertions, 0 deletions
diff --git a/digital/ucoolib/build/arch.mk b/digital/ucoolib/build/arch.mk
new file mode 100644
index 00000000..1d035047
--- /dev/null
+++ b/digital/ucoolib/build/arch.mk
@@ -0,0 +1,106 @@
+# ucoolib - Microcontroller object oriented library.
+#
+# Arch specific makefiles can use macros in this file to factorize build
+# system code.
+
+
+# Define standard commands.
+define arch_cmds
+$1_CC := $$($1_PREFIX)gcc
+$1_CXX := $$($1_PREFIX)g++
+$1_OBJCOPY := $$($1_PREFIX)objcopy
+$1_OBJDUMP := $$($1_PREFIX)objdump
+$1_SIZE := $$($1_PREFIX)size
+$1_COMPILE.c := $$($1_CC) $$($1_CFLAGS) $$($1_CPPFLAGS) -c
+$1_COMPILE.cc := $$($1_CXX) $$($1_CXXFLAGS) $$($1_CPPFLAGS) -c
+$1_COMPILE.S := $$($1_CC) $$($1_ASFLAGS) $$($1_CPPFLAGS) -c
+$1_LINK.c := $$($1_CC) $$($1_CFLAGS) $$($1_LDFLAGS)
+$1_LINK.cc := $$($1_CXX) $$($1_CXXFLAGS) $$($1_LDFLAGS)
+endef
+
+
+# Define build rules.
+define arch_build_rules
+
+$1_PROGS += $$(PROGS)
+$1_ELFS := $$($1_PROGS:%=%.$1$$($1_ELF_SUFFIX))
+$1_EXTRA_CLEAN :=
+
+all: all.$1
+elf: elf.$1
+
+.PHONY: all.$1 elf.$1
+
+all.$1: elf.$1
+
+elf.$1: $$($1_ELFS)
+
+define $1_PROG_template
+$$1.$1$$$$($1_ELF_SUFFIX): $$$$(patsubst %,$$(OBJDIR)/%.$1.o,\
+ $$$$(call filter_sources,$1,$$$$($$1_SOURCES)))
+ @echo "LINK [$1] $$$$@: $$$$(notdir $$$$^)"
+ $$$$Q$$$$($1_LINK.$$(call iscxx,$$($$1_SOURCES))) $$$$^ $$$$($1_LDLIBS) -o $$$$@
+endef
+$$(foreach prog,$$($1_PROGS),$$(eval $$(call $1_PROG_template,$$(prog))))
+
+$$(OBJDIR)/%.$1.o: %.c $$(COMPILE_DEPS) | $$(OBJDIR)
+ @echo "CC [$1] $$<"
+ $$Q$$($1_COMPILE.c) -o $$@ $$<
+
+$$(OBJDIR)/%.$1.o: %.cc $$(COMPILE_DEPS) | $$(OBJDIR)
+ @echo "CXX [$1] $$<"
+ $$Q$$($1_COMPILE.cc) -o $$@ $$<
+
+$$(OBJDIR)/%.$1.o: %.S $$(COMPILE_DEPS) | $$(OBJDIR)
+ @echo "AS [$1] $$<"
+ $$Q$$($1_COMPILE.S) -o $$@ $$<
+
+# Dependency checking.
+-include $$(patsubst %,$$(OBJDIR)/%.$1.d,$$(call filter_sources,$1,$$(ALL_SOURCES)))
+
+endef
+
+
+# Define listing rules.
+define arch_lst_rules
+
+lst: lst.$1
+
+.PHONY: lst.$1
+
+lst.$1: $$($1_PROGS:%=%.$1.lst)
+
+%.$1.lst: %.$1.elf
+ @echo "LST [$1] $$<"
+ $$Q$$($1_OBJDUMP) -h -S $$< > $$@
+
+$1_EXTRA_CLEAN += $$($1_PROGS:%=%.$1.lst)
+
+endef
+
+
+# Define size report rules.
+define arch_size_rules
+
+size: size.$1
+all.$1: size.$1
+
+.PHONY: size.$1
+
+size.$1: $$($1_ELFS)
+ $Q$$($1_SIZE) $$^
+
+endef
+
+
+# Define miscellaneous rules.
+define arch_misc_rules
+
+.PHONY: clean.$1
+
+clean: clean.$1
+
+clean.$1:
+ rm -f $$(OBJDIR)/*.$1.[od] $$($1_ELFS) $$($1_EXTRA_CLEAN)
+
+endef
diff --git a/digital/ucoolib/build/host.mk b/digital/ucoolib/build/host.mk
new file mode 100644
index 00000000..b061efd1
--- /dev/null
+++ b/digital/ucoolib/build/host.mk
@@ -0,0 +1,18 @@
+# ucoolib - Microcontroller object oriented library.
+#
+# Rules for Host.
+
+host_CPPFLAGS := $(CPPFLAGS) $(host_DEFS) \
+ -DTARGET_HOST=1
+host_CFLAGS := $(CFLAGS)
+host_CXXFLAGS := $(sort $(host_CFLAGS) $(CXXFLAGS))
+host_ASFLAGS := $(ASFLAGS)
+host_LDFLAGS := $(LDFLAGS)
+host_LDLIBS := $(LDLIBS) $(host_LIBS)
+
+$(eval $(call arch_cmds,host))
+
+# Rules.
+
+$(eval $(call arch_build_rules,host))
+$(eval $(call arch_misc_rules,host))
diff --git a/digital/ucoolib/build/macros.mk b/digital/ucoolib/build/macros.mk
new file mode 100644
index 00000000..8ae3244f
--- /dev/null
+++ b/digital/ucoolib/build/macros.mk
@@ -0,0 +1,17 @@
+# ucoolib - Microcontroller object oriented library.
+#
+# Usefull macros.
+
+# Return $(A) only if defined, else return B.
+# $(call defval,A,B)
+defval = $(if $(filter undefined,$(origin $1)),$2,$($1))
+
+# Filter out source file for other targets, return basenames.
+# $(call filter_sources,TARGET,SOURCES)
+filter_sources = $(call filter_sources_sub,$1,$(basename $2))
+filter_sources_sub = $(foreach t,$1 $($1_SUBTARGETS),$(filter %.$t,$2)) \
+ $(foreach f,$2,$(if $(findstring .,$f),,$f))
+
+# Test if one of the source is C++, in this case, return cc, else return c.
+# $(call iscxx,SOURCES)
+iscxx = $(if $(filter %.cc,$1),cc,c)
diff --git a/digital/ucoolib/build/setup.mk b/digital/ucoolib/build/setup.mk
new file mode 100644
index 00000000..4ccd1cc3
--- /dev/null
+++ b/digital/ucoolib/build/setup.mk
@@ -0,0 +1,26 @@
+# ucoolib - Microcontroller object oriented library.
+#
+# Setup source files according to requested products and modules configuration.
+
+TARGETS ?= host
+
+DEFAULT_MODULES ?= arch
+
+ALL_PROGS := $(PROGS) $(foreach target,$(TARGETS),$($(target)_PROGS))
+
+ALL_MODULES := $(sort $(DEFAULT_MODULES) $(MODULES) \
+ $(foreach prog,$(ALL_PROGS),$($(prog)_MODULES)))
+
+include $(ALL_MODULES:%=$(BASE)/ucoolib/%/Module)
+
+define MODULES_template
+$1_SOURCES += $$(foreach module,\
+ $$(DEFAULT_MODULES) $$(call defval,$1_MODULES,$$(MODULES)),\
+ $$($$(subst /,_,$$(module))_SOURCES)\
+)
+endef
+$(foreach prog,$(ALL_PROGS),$(eval $(call MODULES_template,$(prog))))
+
+ALL_SOURCES := $(foreach prog,$(ALL_PROGS),$($(prog)_SOURCES))
+
+COMPILE_DEPS :=
diff --git a/digital/ucoolib/build/stm32f4.mk b/digital/ucoolib/build/stm32f4.mk
new file mode 100644
index 00000000..fca60c89
--- /dev/null
+++ b/digital/ucoolib/build/stm32f4.mk
@@ -0,0 +1,35 @@
+# ucoolib - Microcontroller object oriented library.
+#
+# Rules for STM32F4.
+
+LIBOPENCM3_PATH ?= $(BASE)/lib/libopencm3
+
+stm32f4_SUBTARGETS := stm32 arm newlib
+
+stm32f4_CPPFLAGS := $(CPPFLAGS) $(stm32f4_DEFS) \
+ -DSTM32F4 -I$(LIBOPENCM3_PATH)/include \
+ -DTARGET_STM32F4=1 \
+ $(foreach sub,$(stm32f4_SUBTARGETS),-DTARGET_SUB_$(sub)=1)
+stm32f4_CFLAGS := $(CFLAGS) \
+ -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 \
+ -Wl,--gc-sections -ffunction-sections
+stm32f4_CXXFLAGS := $(sort $(stm32f4_CFLAGS) $(CXXFLAGS))
+stm32f4_ASFLAGS := $(ASFLAGS)
+stm32f4_LDSCRIPT := stm32f4.ld
+stm32f4_LDFLAGS := $(LDFLAGS) -T$(stm32f4_LDSCRIPT) \
+ -L$(BASE)/ucoolib/arch/stm32f4 \
+ -L$(LIBOPENCM3_PATH)/lib
+stm32f4_LDLIBS := -nostartfiles $(LDLIBS) $(stm32f4_LIBS) \
+ -lopencm3_stm32f4
+
+stm32f4_PREFIX := arm-none-eabi-
+$(eval $(call arch_cmds,stm32f4))
+
+stm32f4_ELF_SUFFIX = .elf
+
+# Rules.
+
+$(eval $(call arch_build_rules,stm32f4))
+$(eval $(call arch_lst_rules,stm32f4))
+$(eval $(call arch_size_rules,stm32f4))
+$(eval $(call arch_misc_rules,stm32f4))
diff --git a/digital/ucoolib/build/top.mk b/digital/ucoolib/build/top.mk
new file mode 100644
index 00000000..29e8003f
--- /dev/null
+++ b/digital/ucoolib/build/top.mk
@@ -0,0 +1,58 @@
+# ucoolib - Microcontroller object oriented library.
+#
+# Build system top file. To be included with $(BASE) pointing to the ucoolib
+# root.
+
+ifeq ($(BASE),)
+$(error BASE is not defined)
+endif
+
+include $(BASE)/build/macros.mk
+
+# General parameters.
+
+OBJDIR := obj
+
+INCLUDES := $(INCLUDES) -I$(BASE) -I$(OBJDIR)
+CPPFLAGS := $(DEFS) $(INCLUDES) -MP -MMD
+OPTIMIZE ?= -Os
+CFLAGS := -g -Wall -W -Wundef -Wno-unused-parameter \
+ -fno-exceptions $(OPTIMIZE)
+CXXFLAGS := $(CFLAGS) -fno-rtti -fno-threadsafe-statics -fno-implicit-templates
+LDFLAGS :=
+LDLIBS := $(LIBS)
+
+# Quiet, unset to see executed lines.
+Q = @
+
+# Main rules.
+
+all:
+lst:
+size:
+
+clean:
+ rmdir $(OBJDIR) 2> /dev/null || true
+
+.PHONY: all lst size clean
+
+# Modules and sources setup.
+
+include $(BASE)/build/setup.mk
+
+vpath %.cc $(ALL_MODULES:%=$(BASE)/ucoolib/%)
+vpath %.c $(ALL_MODULES:%=$(BASE)/ucoolib/%)
+vpath %.S $(ALL_MODULES:%=$(BASE)/ucoolib/%)
+
+# Objects directory.
+
+$(OBJDIR):
+ $Qmkdir -p $(OBJDIR)
+
+# Arch specific.
+
+include $(BASE)/build/arch.mk
+define TARGETS_template
+include $$(BASE)/build/$1.mk
+endef
+$(foreach target,$(TARGETS),$(eval $(call TARGETS_template,$(target))))
diff --git a/digital/ucoolib/ucoolib/arch/Module b/digital/ucoolib/ucoolib/arch/Module
new file mode 100644
index 00000000..e97fe250
--- /dev/null
+++ b/digital/ucoolib/ucoolib/arch/Module
@@ -0,0 +1 @@
+arch_SOURCES := syscalls.newlib.c
diff --git a/digital/ucoolib/ucoolib/arch/stm32f4/stm32f4.ld b/digital/ucoolib/ucoolib/arch/stm32f4/stm32f4.ld
new file mode 100644
index 00000000..ceef7af4
--- /dev/null
+++ b/digital/ucoolib/ucoolib/arch/stm32f4/stm32f4.ld
@@ -0,0 +1,6 @@
+MEMORY
+{
+ rom (rx) : ORIGIN = 0x08000000, LENGTH = 1024K
+ ram (rwx) : ORIGIN = 0x20000000, LENGTH = 128K
+}
+INCLUDE libopencm3_stm32f4.ld
diff --git a/digital/ucoolib/ucoolib/arch/syscalls.newlib.c b/digital/ucoolib/ucoolib/arch/syscalls.newlib.c
new file mode 100644
index 00000000..93b21579
--- /dev/null
+++ b/digital/ucoolib/ucoolib/arch/syscalls.newlib.c
@@ -0,0 +1,27 @@
+/* ucoolib - Microcontroller object oriented library. {{{
+ *
+ * Copyright (C) 2012 Nicolas Schodet
+ *
+ * APBTeam:
+ * Web: http://apbteam.org/
+ * Email: team AT apbteam DOT org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * }}} */
+
+/** This is needed by C++ ABI, this simple definition will do. See:
+ * http://lists.debian.org/debian-gcc/2003/07/msg00057.html */
+void *__dso_handle = (void*) &__dso_handle;