diff options
Diffstat (limited to 'libopencm3/mk')
-rw-r--r-- | libopencm3/mk/README | 119 | ||||
-rw-r--r-- | libopencm3/mk/gcc-config.mk | 37 | ||||
-rw-r--r-- | libopencm3/mk/gcc-rules.mk | 56 | ||||
-rw-r--r-- | libopencm3/mk/genlink-config.mk | 34 | ||||
-rw-r--r-- | libopencm3/mk/genlink-rules.mk | 25 |
5 files changed, 271 insertions, 0 deletions
diff --git a/libopencm3/mk/README b/libopencm3/mk/README new file mode 100644 index 0000000..59efbbb --- /dev/null +++ b/libopencm3/mk/README @@ -0,0 +1,119 @@ +------------------------------------------------------------------------------- +README +------------------------------------------------------------------------------- + + This directory contains makefile modular support files, that can be used in +your project. + + Each module is packaged with two inclusion makefiles, <module>-config.mk and +<module>-rules.mk. The first one defines some new variables for the make, or +appends values to the existing variables for the make. The second defines rules +for support building. + + So in your project, the <module>-config.mk should be included at some place, +where you are defining variables (near the beginning of the file), and file +<module>-rules.mk should be included in the rules part of makefile (somewhere +near to the end of file). + +Example makefile using gcc compiler module: + +>>>>>> +OBJS += foo.o bar.o + +CFLAGS += -O0 -g +CPPFLAGS += -MD -MP $(@F).d +CPPFLAGS += $(DEFS) +CPPFLAGS += $(INCS) +LDFLAGS += --static --nostartfiles +LDLIBS += -Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group +# parameters for gcc module +PREFIX = arm-elf + +include $(OPENCM3_DIR)/mk/gcc-config.mk + +.PHONY: clean all + +all: binary.images + +%.images: %.elf %.hex + +include $(OPENCM3_DIR)/mk/gcc-rules.mk + +clean: + $(Q)$(RM) -rf binary.* *.o *.d + +-include $(OBJS:.o=.d) +<<<<<< + + +MODULES +======= + +------------------------------------------------------------------------------- +gcc +------------------------------------------------------------------------------- + + This module adds an extended support for GCC toolchain. This adds rules, +neccessary for compiling C and C++ files into elf binary, and rules for +generation of bin, hex, or srec output files for flashing. + +Variables to control the build process (should be set in your makefile): +------------------------------------------------------------------------ + +CFLAGS C compiler flags +CXXFLAGS C++ compiler flags +CPPFLAGS C preprocessor flags (used for C and for C++ compiler) +LDFLAGS Linker flags +ARCH_FLAGS Architecture specification flags (-mcpu, -march etc ) + +Variables to tell gcc about project dependencies and input files +---------------------------------------------------------------- + +LDSCRIPT Linker script file name (can be generated or fixed) +LIBDEPS Array of library filenames that shoud be rebuilt if needed +LDLIBS Array of libraries to be linked with (array of -l<libname>) +OBJS Array of object files to be built + + +------------------------------------------------------------------------------- +genlink +------------------------------------------------------------------------------- + + This module adds an support for the user to the linker script generator. The +linker script will be generated as the file $(DEVICE).ld in the project folder, +and automatically used for the linking process. + +Variables to control the build process (should be set in your makefile): +------------------------------------------------------------------------ + +DEVICE The full device part name used for the compilation process. +OPENCM3_DIR The root path of libopencm3 library. + +Output variables from this module: +---------------------------------- + +DEFS (appended) + - Appended definitions specified in chip database file. + ! Ensure that you have line 'CPPFLAGS += $(DEFS)' in your makefile. + +ARCH_FLAGS (replaced) + - Architecture build flags for specified chip. + * No needed to handle this variable if you use module <gcc> too. + +LDSCRIPT (replaced) + - Linker script generated file. + * No needed to handle this variable if you use module <gcc> too. + +OPENCM3_LIBNAME (replaced) + - The right libopencm3 library base name to be linked with. + ! Ensure that you have line 'LDLIBS += -l$(OPENCM3_LIBNAME)' in your makefile. + ! Ensure that you have line 'LDFLAGS += -L$(OPENCM3_DIR)/lib' in your makefile. + ! Ensure that you have rule '$(OPENCM3_DIR)/lib/lib$(OPENCM3_LIBNAME).a:' + to be the library archive succesfully built when needed. + +Temporary variables that you should not use in your makefile: +------------------------------------------------------------- + +GENLINK_DEFS +GENLINK_ARCH +GENLINK_LIB diff --git a/libopencm3/mk/gcc-config.mk b/libopencm3/mk/gcc-config.mk new file mode 100644 index 0000000..8c92424 --- /dev/null +++ b/libopencm3/mk/gcc-config.mk @@ -0,0 +1,37 @@ +## +## This file is part of the libopencm3 project. +## +## Copyright (C) 2014 Frantisek Burian <BuFran@seznam.cz> +## +## 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 <http://www.gnu.org/licenses/>. +## + +############################################################################### +# The support makefile for GCC compiler toolchain, the rules part. +# +# please read mk/README for specification how to use this file in your project + + +PREFIX ?= arm-none-eabi +#PREFIX ?= arm-elf + +CC := $(PREFIX)-gcc +CXX := $(PREFIX)-g++ +LD := $(PREFIX)-gcc +AR := $(PREFIX)-ar +AS := $(PREFIX)-as +OBJCOPY := $(PREFIX)-objcopy +OBJDUMP := $(PREFIX)-objdump +GDB := $(PREFIX)-gdb +SIZE := $(PREFIX)-size diff --git a/libopencm3/mk/gcc-rules.mk b/libopencm3/mk/gcc-rules.mk new file mode 100644 index 0000000..821912b --- /dev/null +++ b/libopencm3/mk/gcc-rules.mk @@ -0,0 +1,56 @@ +## +## This file is part of the libopencm3 project. +## +## Copyright (C) 2014 Frantisek Burian <BuFran@seznam.cz> +## +## 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 <http://www.gnu.org/licenses/>. +## + +############################################################################### +# The support makefile for GCC compiler toolchain, the rules part. +# +# please read mk/README for specification how to use this file in your project +# + +%.bin: %.elf + @printf " OBJCOPY $@\n" + $(Q)$(OBJCOPY) -Obinary $< $@ + +%.hex: %.elf + @printf " OBJCOPY $@\n" + $(Q)$(OBJCOPY) -Oihex $< $@ + +%.srec: %.elf + @printf " OBJCOPY $@\n" + $(Q)$(OBJCOPY) -Osrec $< $@ + +%.list: %.elf + @printf " OBJDUMP $@\n" + $(Q)$(OBJDUMP) -S $< > $@ + +%.elf: $(OBJS) $(LDSCRIPT) $(LIBDEPS) + @printf " LD $(*).elf\n" + $(Q)$(LD) $(OBJS) $(LDLIBS) $(LDFLAGS) -T$(LDSCRIPT) $(ARCH_FLAGS) -o $@ + +%.o: %.c + @printf " CC $<\n" + $(Q)$(CC) $(CFLAGS) $(CPPFLAGS) $(ARCH_FLAGS) -o $@ -c $< + +%.o: %.cxx + @printf " CXX $<\n" + $(Q)$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(ARCH_FLAGS) -o $@ -c $< + +%.o: %.cpp + @printf " CXX $(*).cpp\n" + $(Q)$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(ARCH_FLAGS) -o $@ -c $< diff --git a/libopencm3/mk/genlink-config.mk b/libopencm3/mk/genlink-config.mk new file mode 100644 index 0000000..6994934 --- /dev/null +++ b/libopencm3/mk/genlink-config.mk @@ -0,0 +1,34 @@ +## +## This file is part of the libopencm3 project. +## +## Copyright (C) 2014 Frantisek Burian <BuFran@seznam.cz> +## +## 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 <http://www.gnu.org/licenses/>. +## + +ifeq ($(DEVICE),) +$(error no DEVICE specified for linker script generator) +endif + +LDSCRIPT = $(DEVICE).ld + +GENLINK_DEFS :=$(shell awk -v PAT="$(DEVICE)" -v MODE="DEFS" -f $(OPENCM3_DIR)/scripts/genlink.awk $(OPENCM3_DIR)/ld/devices.data 2>/dev/null) +GENLINK_ARCH :=$(shell awk -v PAT="$(DEVICE)" -v MODE="ARCH" -f $(OPENCM3_DIR)/scripts/genlink.awk $(OPENCM3_DIR)/ld/devices.data 2>/dev/null) +GENLINK_LIB :=$(shell awk -v PAT="$(DEVICE)" -v MODE="LIB" -f $(OPENCM3_DIR)/scripts/genlink.awk $(OPENCM3_DIR)/ld/devices.data 2>/dev/null) + +DEFS += $(GENLINK_DEFS) +ARCH_FLAGS := $(GENLINK_ARCH) +OPENCM3_LIBNAME := $(strip $(subst -l,,$(GENLINK_LIB))) + +GENFILES += $(LDSCRIPT) diff --git a/libopencm3/mk/genlink-rules.mk b/libopencm3/mk/genlink-rules.mk new file mode 100644 index 0000000..99bd1f3 --- /dev/null +++ b/libopencm3/mk/genlink-rules.mk @@ -0,0 +1,25 @@ +## +## This file is part of the libopencm3 project. +## +## Copyright (C) 2014 Frantisek Burian <BuFran@seznam.cz> +## +## 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 <http://www.gnu.org/licenses/>. +## + +$(LDSCRIPT):$(OPENCM3_DIR)/ld/linker.ld.S +ifeq ($(GENLINK_DEFS),) + $(error unknown device $(DEVICE) for the linker. Cannot generate ldscript) +endif + @printf " GENLNK $@\n" + $(Q)$(CPP) $(GENLINK_DEFS) -P -E $< > $@ |