From c5ccf598a6e23909dead9ac8b413fb42925ee5f4 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Sun, 10 Oct 2021 11:54:35 +0200 Subject: Share flags between lib and test programs --- Makefile.lib | 12 +++--------- core.nix | 9 ++++++++- flags.mk | 12 ++++++++++++ test.nix | 2 +- test/Makefile | 13 ++----------- 5 files changed, 26 insertions(+), 22 deletions(-) create mode 100644 flags.mk diff --git a/Makefile.lib b/Makefile.lib index ce5787c..d776318 100644 --- a/Makefile.lib +++ b/Makefile.lib @@ -1,13 +1,7 @@ -MCU = IMXRT1062 -MCU_DEF = ARDUINO_TEENSY40 +include flags.mk -OPTIONS = -DF_CPU=600000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH -OPTIONS += -D__$(MCU)__ -DARDUINO=10813 -DTEENSYDUINO=154 -D$(MCU_DEF) - -CPU_OPTIONS = -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -mthumb - -CPPFLAGS = -Wall -g -O2 $(CPU_OPTIONS) -MMD $(OPTIONS) -I. -ffunction-sections -fdata-sections -I. -CXXFLAGS = -std=gnu++14 -felide-constructors -fno-exceptions -fpermissive -fno-rtti -Wno-error=narrowing +CPPFLAGS += -I. +CXXFLAGS += -std=gnu++14 C_FILES := $(wildcard *.c) CPP_FILES := $(wildcard *.cpp) diff --git a/core.nix b/core.nix index 6a98e55..fba64e7 100644 --- a/core.nix +++ b/core.nix @@ -23,6 +23,10 @@ pkgs.stdenvNoCC.mkDerivation rec { pushd teensy4 rm main.cpp cp ${./Makefile.lib} Makefile + substitute ${./flags.mk} flags.mk \ + --subst-var-by TEENSY_INCLUDE . \ + --subst-var-by TEENSY_LIB . + cp ${./flags.mk} flags.mk make ar rvs libteensy-core.a *.o popd @@ -36,7 +40,10 @@ pkgs.stdenvNoCC.mkDerivation rec { cp -r debug $out/include/ cp -r util $out/include/ cp libteensy-core.a $out/lib/ - cp imxrt1062.ld $out/lib/ + substitute ${./flags.mk} $out/include/flags.mk \ + --subst-var-by TEENSY_INCLUDE $out/include \ + --subst-var-by TEENSY_LIB $out/lib + cp imxrt1062.ld $out/include/IMXRT1062.ld popd ''; } diff --git a/flags.mk b/flags.mk new file mode 100644 index 0000000..e17ac2d --- /dev/null +++ b/flags.mk @@ -0,0 +1,12 @@ +MCU = IMXRT1062 +MCU_DEF = ARDUINO_TEENSY40 + +OPTIONS = -DF_CPU=600000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH +OPTIONS += -D__$(MCU)__ -DARDUINO=10813 -DTEENSYDUINO=154 -D$(MCU_DEF) + +CPU_OPTIONS = -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -mthumb + +CPPFLAGS = -Wall -g -O2 $(CPU_OPTIONS) -MMD $(OPTIONS) -ffunction-sections -fdata-sections +CXXFLAGS = -felide-constructors -fno-exceptions -fpermissive -fno-rtti -Wno-error=narrowing -I@TEENSY_INCLUDE@ + +LDFLAGS = -T@TEENSY_INCLUDE@/$(MCU).ld -L@TEENSY_LIB@ -Os -Wl,--gc-sections,--relax $(CPU_OPTIONS) diff --git a/test.nix b/test.nix index e6329a8..8945759 100644 --- a/test.nix +++ b/test.nix @@ -16,7 +16,7 @@ pkgs.stdenv.mkDerivation rec { export OBJCOPY=arm-none-eabi-objcopy export SIZE=arm-none-eabi-size - export LDFLAGS="-T${teensy-core}/lib/imxrt1062.ld -L${teensy-core}/lib" + export TEENSY_PATH=${teensy-core} make ''; diff --git a/test/Makefile b/test/Makefile index 0891b70..3bf5a70 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,15 +1,6 @@ -MCU = IMXRT1062 -MCU_DEF = ARDUINO_TEENSY40 +include $(TEENSY_PATH)/include/flags.mk -OPTIONS = -DF_CPU=600000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH -OPTIONS += -D__$(MCU)__ -DARDUINO=10813 -DTEENSYDUINO=154 -D$(MCU_DEF) - -CPU_OPTIONS = -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -mthumb - -CPPFLAGS = $(NIX_CFLAGS_COMPILE) -Wall -g -O2 $(CPU_OPTIONS) -MMD $(OPTIONS) -I. -ffunction-sections -fdata-sections -CXXFLAGS = -std=gnu++20 -felide-constructors -fno-exceptions -fpermissive -fno-rtti -Wno-error=narrowing - -LDFLAGS += -Os -Wl,--gc-sections,--relax $(CPU_OPTIONS) +CXXFLAGS += -std=gnu++20 LIBS = -lm -lstdc++ -lteensy-core -- cgit v1.2.3