From b82e7eee52f72200b9f4a615c299056c4e09e071 Mon Sep 17 00:00:00 2001 From: Piotr Esden-Tempski Date: Mon, 13 Aug 2012 15:23:07 -0700 Subject: Examples detect if they are being built in src dir. If an example is in the libopencm3 source directory it will use the locally built library instead of the system library. When you copy an example out of the libopencm3 tree it will automatically detect it and build using the system wide installation. --- examples/lm3s/Makefile.include | 11 ++++++++--- examples/lpc13xx/Makefile.include | 11 ++++++++--- examples/lpc17xx/Makefile.include | 11 ++++++++--- examples/lpc43xx/Makefile.include | 11 ++++++++--- examples/stm32/f1/Makefile.include | 11 ++++++++--- examples/stm32/f2/Makefile.include | 11 ++++++++--- examples/stm32/f4/Makefile.include | 11 ++++++++--- 7 files changed, 56 insertions(+), 21 deletions(-) diff --git a/examples/lm3s/Makefile.include b/examples/lm3s/Makefile.include index c119846..4d774be 100644 --- a/examples/lm3s/Makefile.include +++ b/examples/lm3s/Makefile.include @@ -24,9 +24,14 @@ CC = $(PREFIX)-gcc LD = $(PREFIX)-gcc OBJCOPY = $(PREFIX)-objcopy OBJDUMP = $(PREFIX)-objdump -# Uncomment this line if you want to use the installed (not local) library. -# TOOLCHAIN_DIR := $(shell dirname `which $(CC)`)/../$(PREFIX) -TOOLCHAIN_DIR = ../../../.. +ifeq ($(shell ls ../../../../../lib/libopencm3_lm3s.a 2>/dev/null),) +TOOLCHAIN_DIR := $(shell dirname `which $(CC)`)/../$(PREFIX) +else +ifeq ($(V),1) +$(info We seem to be building the example in the source directory. Using local library!) +endif +TOOLCHAIN_DIR := ../../../.. +endif CFLAGS += -O0 -g3 -Wall -Wextra -I$(TOOLCHAIN_DIR)/include -fno-common \ -mcpu=cortex-m3 -mthumb -MD LDSCRIPT ?= $(BINARY).ld diff --git a/examples/lpc13xx/Makefile.include b/examples/lpc13xx/Makefile.include index 47d906c..afd0524 100644 --- a/examples/lpc13xx/Makefile.include +++ b/examples/lpc13xx/Makefile.include @@ -24,9 +24,14 @@ CC = $(PREFIX)-gcc LD = $(PREFIX)-gcc OBJCOPY = $(PREFIX)-objcopy OBJDUMP = $(PREFIX)-objdump -# Uncomment this line if you want to use the installed (not local) library. -# TOOLCHAIN_DIR := $(shell dirname `which $(CC)`)/../$(PREFIX) -TOOLCHAIN_DIR = ../../../.. +ifeq ($(shell ls ../../../../../lib/libopencm3_lpc13xx.a 2>/dev/null),) +TOOLCHAIN_DIR := $(shell dirname `which $(CC)`)/../$(PREFIX) +else +ifeq ($(V),1) +$(info We seem to be building the example in the source directory. Using local library!) +endif +TOOLCHAIN_DIR := ../../../.. +endif CFLAGS += -Os -g -Wall -Wextra -I$(TOOLCHAIN_DIR)/include -fno-common \ -mcpu=cortex-m3 -mthumb -MD LDSCRIPT ?= $(BINARY).ld diff --git a/examples/lpc17xx/Makefile.include b/examples/lpc17xx/Makefile.include index 92df4b1..f620a72 100644 --- a/examples/lpc17xx/Makefile.include +++ b/examples/lpc17xx/Makefile.include @@ -24,9 +24,14 @@ CC = $(PREFIX)-gcc LD = $(PREFIX)-gcc OBJCOPY = $(PREFIX)-objcopy OBJDUMP = $(PREFIX)-objdump -# Uncomment this line if you want to use the installed (not local) library. -# TOOLCHAIN_DIR := $(shell dirname `which $(CC)`)/../$(PREFIX) -TOOLCHAIN_DIR = ../../../.. +ifeq ($(shell ls ../../../../../lib/libopencm3_lpc17xx.a 2>/dev/null),) +TOOLCHAIN_DIR := $(shell dirname `which $(CC)`)/../$(PREFIX) +else +ifeq ($(V),1) +$(info We seem to be building the example in the source directory. Using local library!) +endif +TOOLCHAIN_DIR := ../../../.. +endif CFLAGS += -O0 -g -Wall -Wextra -I$(TOOLCHAIN_DIR)/include -fno-common \ -mcpu=cortex-m3 -mthumb -MD LDSCRIPT ?= $(BINARY).ld diff --git a/examples/lpc43xx/Makefile.include b/examples/lpc43xx/Makefile.include index 074192a..b4717cd 100644 --- a/examples/lpc43xx/Makefile.include +++ b/examples/lpc43xx/Makefile.include @@ -27,9 +27,14 @@ LD = $(PREFIX)-gcc OBJCOPY = $(PREFIX)-objcopy OBJDUMP = $(PREFIX)-objdump GDB = $(PREFIX)-gdb -# Uncomment this line if you want to use the installed (not local) library. -# TOOLCHAIN_DIR := $(shell dirname `which $(CC)`)/../$(PREFIX) -TOOLCHAIN_DIR = ../../../.. +ifeq ($(shell ls ../../../../../lib/libopencm3_lpc43xx.a 2>/dev/null),) +TOOLCHAIN_DIR := $(shell dirname `which $(CC)`)/../$(PREFIX) +else +ifeq ($(V),1) +$(info We seem to be building the example in the source directory. Using local library!) +endif +TOOLCHAIN_DIR := ../../../.. +endif CFLAGS += -O2 -g -Wall -Wextra -I$(TOOLCHAIN_DIR)/include -fno-common \ -mcpu=cortex-m4 -mthumb -MD \ -mfloat-abi=hard -mfpu=fpv4-sp-d16 diff --git a/examples/stm32/f1/Makefile.include b/examples/stm32/f1/Makefile.include index 31c6dcc..66865b8 100644 --- a/examples/stm32/f1/Makefile.include +++ b/examples/stm32/f1/Makefile.include @@ -25,9 +25,14 @@ LD = $(PREFIX)-gcc OBJCOPY = $(PREFIX)-objcopy OBJDUMP = $(PREFIX)-objdump GDB = $(PREFIX)-gdb -# Uncomment this line if you want to use the installed (not local) library. -#TOOLCHAIN_DIR := $(shell dirname `which $(CC)`)/../$(PREFIX) -TOOLCHAIN_DIR = ../../../../.. +ifeq ($(shell ls ../../../../../lib/libopencm3_stm32f1.a 2>/dev/null),) +TOOLCHAIN_DIR := $(shell dirname `which $(CC)`)/../$(PREFIX) +else +ifeq ($(V),1) +$(info We seem to be building the example in the source directory. Using local library!) +endif +TOOLCHAIN_DIR := ../../../../.. +endif ARCH_FLAGS = -mthumb -mcpu=cortex-m3 -msoft-float CFLAGS += -Os -g -Wall -Wextra -I$(TOOLCHAIN_DIR)/include \ -fno-common $(ARCH_FLAGS) -MD -DSTM32F1 diff --git a/examples/stm32/f2/Makefile.include b/examples/stm32/f2/Makefile.include index f68da43..93f6ce6 100644 --- a/examples/stm32/f2/Makefile.include +++ b/examples/stm32/f2/Makefile.include @@ -26,9 +26,14 @@ LD = $(PREFIX)-gcc OBJCOPY = $(PREFIX)-objcopy OBJDUMP = $(PREFIX)-objdump GDB = $(PREFIX)-gdb -# Uncomment this line if you want to use the installed (not local) library. -#TOOLCHAIN_DIR := $(shell dirname `which $(CC)`)/../$(PREFIX) -TOOLCHAIN_DIR = ../../../../.. +ifeq ($(shell ls ../../../../../lib/libopencm3_stm32f2.a 2>/dev/null),) +TOOLCHAIN_DIR := $(shell dirname `which $(CC)`)/../$(PREFIX) +else +ifeq ($(V),1) +$(info We seem to be building the example in the source directory. Using local library!) +endif +TOOLCHAIN_DIR := ../../../../.. +endif CFLAGS += -Os -g -Wall -Wextra -I$(TOOLCHAIN_DIR)/include \ -fno-common -mcpu=cortex-m3 -mthumb -msoft-float -MD -DSTM32F2 LDSCRIPT ?= $(BINARY).ld diff --git a/examples/stm32/f4/Makefile.include b/examples/stm32/f4/Makefile.include index 42e7162..2e915ce 100644 --- a/examples/stm32/f4/Makefile.include +++ b/examples/stm32/f4/Makefile.include @@ -26,9 +26,14 @@ LD = $(PREFIX)-gcc OBJCOPY = $(PREFIX)-objcopy OBJDUMP = $(PREFIX)-objdump GDB = $(PREFIX)-gdb -# Uncomment this line if you want to use the installed (not local) library. -#TOOLCHAIN_DIR := $(shell dirname `which $(CC)`)/../$(PREFIX) -TOOLCHAIN_DIR = ../../../../.. +ifeq ($(shell ls ../../../../../lib/libopencm3_stm32f4.a 2>/dev/null),) +TOOLCHAIN_DIR := $(shell dirname `which $(CC)`)/../$(PREFIX) +else +ifeq ($(V),1) +$(info We seem to be building the example in the source directory. Using local library!) +endif +TOOLCHAIN_DIR := ../../../../.. +endif CFLAGS += -Os -g -Wall -Wextra -I$(TOOLCHAIN_DIR)/include \ -fno-common -mcpu=cortex-m4 -mthumb -msoft-float -MD -DSTM32F4 LDSCRIPT ?= $(BINARY).ld -- cgit v1.2.3