From 0aa8e478e70ee12555c5a493c9a2c22a46c8d939 Mon Sep 17 00:00:00 2001 From: heck Date: Fri, 20 Sep 2024 20:59:56 +0200 Subject: [PATCH] Add GNU make based build system --- Makefile | 13 +++++++++++++ Makefile.conf | 35 +++++++++++++++++++++++++++++++++++ build.conf.example | 13 +++++++++++++ src/Makefile | 19 +++++++++++++++++++ 4 files changed, 80 insertions(+) create mode 100644 Makefile create mode 100644 Makefile.conf create mode 100644 build.conf.example create mode 100644 src/Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..5c6a46a --- /dev/null +++ b/Makefile @@ -0,0 +1,13 @@ +.PHONY: all flash clean + +all: compile flash + +compile: + $(MAKE) -C src + +flash: + $(MAKE) -C src program + +clean: + $(MAKE) -C src clean + diff --git a/Makefile.conf b/Makefile.conf new file mode 100644 index 0000000..a08f091 --- /dev/null +++ b/Makefile.conf @@ -0,0 +1,35 @@ +HERE:=$(dir $(lastword $(MAKEFILE_LIST))) + +# Project Name +TARGET?=blink + +# Configure for debugging +# common configurations: +# use DEBUG = 1 and OPT = -Og for debugging +# or DEBUG = 0 and OPT = -O3 for performance +DEBUG=0 +OPT=-O3 + +# (optional) Includes FatFS source files within project. +#USE_FATFS = 1 + +# Relative to dir 'src' +LIBDAISY_DIR=../../heck_libDaisyWrong +DAISYSP_DIR=../../heck_DaisySPWrong + + CXXFLAGS+=-Wall -Wno-unused -Wno-reorder-ctor -Wno-switch + +######### Overrides from build.conf ######### +-include $(HERE)build.conf + +ifneq (,$(findstring g++,$(CXX))) + CXXFLAGS+=-fdiagnostics-color=always +else ifneq (,$(findstring clang,$(CXX))) + CXXFLAGS+=-fcolor-diagnostics +endif + +ifeq ($(DEBUG),1) + CXXFLAGS+=-g -O0 +else + CXXFLAGS+=-DNDEBUG=1 -O3 +endif diff --git a/build.conf.example b/build.conf.example new file mode 100644 index 0000000..2c71c04 --- /dev/null +++ b/build.conf.example @@ -0,0 +1,13 @@ +# Build config +# also, infos for the build system about the dev environment + +# TARGET sets the program to compile and flash +# the name of the main cxx file without the prefix 'main_' +TARGET=blink +#TARGET=testtone + +DEBUG=0 + +# Daisy dependencies relative to dir 'src' +LIBDAISY_DIR=../../heck_libDaisy +DAISYSP_DIR=../../heck_DaisySP diff --git a/src/Makefile b/src/Makefile new file mode 100644 index 0000000..e527aa0 --- /dev/null +++ b/src/Makefile @@ -0,0 +1,19 @@ +include ../Makefile.conf + +ALL_SRC=$(wildcard *.cc) +TARGET_SRC=main_$(TARGET).cc +MODULES_SRC=$(filter-out main_%,$(ALL_SRC)) +CXX_SRC=$(MODULES_SRC) $(TARGET_SRC) + +$(info CXXFLAGS: $(CXXFLAGS)) +$(info SOURCES: $(ALL_SRC)) +$(info MODULES: $(MODULES_SRC)) +$(info TARGET_SRC: $(TARGET_SRC)) +$(info CXX_SRC: $(CXX_SRC)) + +# libDaisy Makefile variables +CPPFLAGS=$(CXXFLAGS) +SYSTEM_FILES_DIR=$(LIBDAISY_DIR)/core +CPP_SOURCES=$(CXX_SRC) + +include $(SYSTEM_FILES_DIR)/Makefile