From 19fbf4e5823dc2beea8e3923fc604f6e581a6a52 Mon Sep 17 00:00:00 2001 From: BuFran Date: Fri, 5 Jul 2013 19:34:48 +0200 Subject: [PATCH] Add the linker generator makefile Example of use is included in the file header --- ld/Makefile.linker | 68 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 ld/Makefile.linker diff --git a/ld/Makefile.linker b/ld/Makefile.linker new file mode 100644 index 00000000..6e32cfb3 --- /dev/null +++ b/ld/Makefile.linker @@ -0,0 +1,68 @@ +## +## This file is part of the libopencm3 project. +## +## Copyright (C) 2013 Frantisek Burian +## +## Linker script generator feature +## ------------------------------- +## +## This generator will generate .ld linker script file in the project +## directory for the specified device, and this script will be automatically +## used as main linker script during the build process. +## +## WARNING: You must include this file after all shared variables are setup, +## and before the command section begins. Ideal place of the include is exactly +## after the all: rule in Your makefile. +## +## Options +## ------- +## +## This feature is configured by specifying variable DEVICE= +## in the makefile of Your project. +## +## WARNING Please don't forget to specify full name of the chip you are using. +## Many chip families have device specific letters specified on the end of +## device name string. +## +## Example: +## -------- +## +## @code +## DEVICE=stm32f407vgt6 +## <... common makefile code ...> +## all: images +## +## include /ld/Makefile.linker +## +## images: <....> +## @endcode + +## +## This library is free software: you can redistribute it and/or modify +## it under the terms of the GNU Lesser General Public License as published by +## the Free Software Foundation, either version 3 of the License, or +## (at your option) any later version. +## +## This library 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 Lesser General Public License for more details. +## +## You should have received a copy of the GNU Lesser General Public License +## along with this library. If not, see . +## + +ifneq ($(DEVICE),) + +LDSCRIPT=$(DEVICE).ld +LD_PARAMS=$(shell awk -v PAT="$(DEVICE)" -f $(TOOLCHAIN_DIR)/scripts/genlink.awk $(TOOLCHAIN_DIR)/ld/devices.data 2>/dev/null) + +$(LDSCRIPT):$(TOOLCHAIN_DIR)/lib/linker.ld.S +ifeq ($(LD_PARAMS),) + $(error unknown device $(DEVICE) for the linker. Cannot generate ldscript) +endif + @#printf " GENLNK $(subst $(shell pwd)/,,$(@))\n" + $(Q)$(CC) $(LD_PARAMS) -P -E $< > $@ + +GENFILES += $(LDSCRIPT) +endif