Use make flags to help control where the library is installed

Where the library is installed has quite an affect on what -L and -I
flags are used.  If you install into the toolchain, you don't want
to use them at all, but if you install out of tree (/opt/mycm3 for
example) you need to specify the -L and -I flags.

Update the documentation and the example makefiles to support this
This commit is contained in:
Karl Palsson 2012-07-04 21:45:14 +00:00
parent 507a1742dc
commit f1f1aa84f3
3 changed files with 43 additions and 8 deletions

View File

@ -19,7 +19,13 @@
PREFIX ?= arm-none-eabi
#PREFIX ?= arm-elf
ifeq ($(DETECT_TOOLCHAIN),)
DESTDIR ?= /usr/local
else
DESTDIR ?= $(shell dirname $(shell readlink -f $(shell which $(PREFIX)-gcc)))/..
endif
INCDIR = $(DESTDIR)/$(PREFIX)/include
LIBDIR = $(DESTDIR)/$(PREFIX)/lib
SHAREDIR = $(DESTDIR)/$(PREFIX)/share/libopencm3/scripts

24
README
View File

@ -48,7 +48,8 @@ Example projects
The library ships with a few small example projects which illustrate how
individual subsystems of the microcontrollers can be configured and used with
libopencm3.
libopencm3. The makefiles are generally useable for your own projects with
only minimal changes for the libopencm3 install path (See Installation)
For flashing the 'miniblink' example (after you built libopencm3 and the
examples by typing 'make' at the top-level directory) onto the Olimex
@ -79,16 +80,23 @@ Installation
$ make install
This will install the library in /usr/local. If you want to install it
elsewhere, use the following syntax:
This will install the library into /usr/local. (permissions permitting)
$ DESTDIR=/opt make install
If you want to install it elsewhere, use the following syntax:
The recommended location is to install into your toolchain directory, e.g.
/home/someuser/sat for a toolchain built using the summon-arm-toolchain
script from https://github.com/esden/summon-arm-toolchain.
$ make DESTDIR=/opt/libopencm3 install
$ DESTDIR=~/sat make install
If you want to attempt to install into your toolchain, use this:
$ make DETECT_TOOLCHAIN=1 install
Note: If you install this into your toolchain, you don't need to pass
any extra -L or -I flags into your projects. However, this also means
you must NOT pass any -L or -I flags that point into the toolchain. This
_will_ confuse the linker. (ie, for summon-arm-toolchain, do NOT pass
-L/home/user/sat/lib) Common symptoms of confusing
the linker are hard faults caused by branches into arm code.
You can use objdump to check for this in your final elf.
Coding style and development guidelines

View File

@ -45,6 +45,15 @@ LDFLAGS += --static -Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group \
-L$(TOOLCHAIN_DIR)/lib \
-T$(LDSCRIPT) -nostartfiles -Wl,--gc-sections \
$(ARCH_FLAGS) -mfix-cortex-m3-ldrd
ifneq ($(OPENCM3_DIR),)
CFLAGS += -I$(OPENCM3_DIR)/include
LDFLAGS += -L$(OPENCM3_DIR)/lib -L$(OPENCM3_DIR)/lib/stm32/f1
SCRIPT_DIR = $(OPENCM3_DIR)/share
else
SCRIPT_DIR = $(shell dirname $(shell readlink -f $(shell which $(PREFIX)-gcc)))/../$(PREFIX)/share
endif
OBJS += $(BINARY).o
OOCD ?= openocd
@ -53,6 +62,9 @@ OOCD_BOARD ?= olimex_stm32_h103
# Black magic probe specific variables
# Set the BMP_PORT to a serial port and then BMP is used for flashing
BMP_PORT ?=
# texane/stlink can be used by uncommenting this...
# or defining it in your own makefiles
#STLINK_PORT ?= :4242
# Be silent per default, but 'make V=1' will show all compiler calls.
ifneq ($(V),1)
@ -107,6 +119,7 @@ clean:
$(Q)rm -f *.srec
$(Q)rm -f *.list
ifeq ($(STLINK_PORT),)
ifeq ($(BMP_PORT),)
ifeq ($(OOCD_SERIAL),)
%.flash: %.hex
@ -140,6 +153,14 @@ else
-x $(TOOLCHAIN_DIR)/scripts/black_magic_probe_flash.scr \
$(*).elf
endif
else
%.flash: %.elf
@echo " GDB $(*).elf (flash)"
$(Q)$(GDB) --batch \
-ex 'target extended-remote $(STLINK_PORT)' \
-x $(SCRIPT_DIR)/libopencm3/scripts/stlink_flash.scr \
$(*).elf
endif
.PHONY: images clean