diff --git a/examples/lm3s/Makefile.include b/examples/lm3s/Makefile.include index c1198462..4d774bea 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 47d906cf..afd0524c 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 92df4b12..f620a72f 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 074192a6..b4717cdd 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 31c6dccd..66865b85 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 f68da433..93f6ce6d 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 42e7162d..2e915ce7 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