Mercurial > hg > beaglert
changeset 260:afdddd5f189f prerelease
Synced main Makefile with IDE Makefile
author | Liam Donovan <l.b.donovan@qmul.ac.uk> |
---|---|
date | Mon, 16 May 2016 14:32:21 +0100 |
parents | abd3657016ea |
children | f51132ee0080 de37582ce6f3 |
files | Makefile |
diffstat | 1 files changed, 68 insertions(+), 53 deletions(-) [+] |
line wrap: on
line diff
--- a/Makefile Mon May 16 12:16:59 2016 +0100 +++ b/Makefile Mon May 16 14:32:21 2016 +0100 @@ -1,14 +1,25 @@ # BeagleRT # Low-latency, real-time audio and sensor processing on BeagleBone Black -# (c) 2015 Andrew McPherson, Victor Zappi, Giulio Moro +# (c) 2016 Andrew McPherson, Victor Zappi, Giulio Moro, Liam Donovan # Centre for Digital Music, Queen Mary University of London # This Makefile is intended for use on the BeagleBone Black itself # and not for cross-compiling +# set the project to be compiled by calling: make all PROJECT=<project_name> + +# if the PROJECT variable is not set, throw an error and exit +# otherwise, calling make clean without setting PROJECT results in entire projects directory being rm -rf'ed +ifndef PROJECT + $(error PROJECT is not set) +endif + +PROJECT_DIR := $(abspath projects/$(PROJECT)) + RM := rm -rf STATIC_LIBS := ./libprussdrv.a ./libNE10.a -LIBS := -lrt -lnative -lxenomai -lsndfile +LIBS := -lrt -lnative -lxenomai -lsndfile + # refresh library cache and check if libpd is there TEST_LIBPD := $(shell ldconfig; ldconfig -p | grep "libpd\.so") ifeq ($(strip $(TEST_LIBPD)), ) @@ -43,19 +54,19 @@ C_FLAGS += --fast-math endif -INCLUDES := -I./source -I./include -I/usr/include/ne10 -I/usr/xenomai/include -I/usr/arm-linux-gnueabihf/include/xenomai/include -I/usr/arm-linux-gnueabihf/include/ne10 +INCLUDES := -I$(PROJECT_DIR) -I./include -I/usr/include/ne10 -I/usr/xenomai/include -I/usr/arm-linux-gnueabihf/include/xenomai/include -I/usr/arm-linux-gnueabihf/include/ne10 -ASM_SRCS := $(wildcard source/*.S) -ASM_OBJS := $(addprefix build/source/,$(notdir $(ASM_SRCS:.S=.o))) -ASM_DEPS := $(addprefix build/source/,$(notdir $(ASM_SRCS:.S=.d))) +ASM_SRCS := $(wildcard $(PROJECT_DIR)/*.S) +ASM_OBJS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(ASM_SRCS:.S=.o))) +ASM_DEPS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(ASM_SRCS:.S=.d))) -C_SRCS := $(wildcard source/*.c) -C_OBJS := $(addprefix build/source/,$(notdir $(C_SRCS:.c=.o))) -C_DEPS := $(addprefix build/source/,$(notdir $(C_SRCS:.c=.d))) +C_SRCS := $(wildcard $(PROJECT_DIR)/*.c) +C_OBJS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(C_SRCS:.c=.o))) +C_DEPS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(C_SRCS:.c=.d))) -CPP_SRCS := $(wildcard source/*.cpp) -CPP_OBJS := $(addprefix build/source/,$(notdir $(CPP_SRCS:.cpp=.o))) -CPP_DEPS := $(addprefix build/source/,$(notdir $(CPP_SRCS:.cpp=.d))) +CPP_SRCS := $(wildcard $(PROJECT_DIR)/*.cpp) +CPP_OBJS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(CPP_SRCS:.cpp=.o))) +CPP_DEPS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(CPP_SRCS:.cpp=.d))) # Core BeagleRT sources CORE_CPP_SRCS = $(filter-out core/default_main.cpp, $(wildcard core/*.cpp)) @@ -79,38 +90,38 @@ # syntax = check syntax syntax: SYNTAX_FLAG := -fsyntax-only -syntax: BeagleRT +syntax: SYNTAX # Rule for BeagleRT core C++ files build/core/%.o: ./core/%.cpp - @echo 'Building file: $<' - @echo 'Invoking: C++ Compiler' - $(CXX) $(SYNTAX_FLAG) $(INCLUDES) $(CPP_FLAGS) -Wall -c -fmessage-length=0 -U_FORTIFY_SOURCE -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" - @echo 'Finished building: $<' + @echo 'Building $(notdir $<)...' +# @echo 'Invoking: C++ Compiler' + @$(CXX) $(SYNTAX_FLAG) $(INCLUDES) $(CPP_FLAGS) -Wall -c -fmessage-length=0 -U_FORTIFY_SOURCE -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" + @echo ' ...done' @echo ' ' # Rule for user-supplied C++ files -build/source/%.o: ./source/%.cpp - @echo 'Building file: $<' - @echo 'Invoking: C++ Compiler' - $(CXX) $(SYNTAX_FLAG) $(INCLUDES) $(CPP_FLAGS) -Wall -c -fmessage-length=0 -U_FORTIFY_SOURCE -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" - @echo 'Finished building: $<' +$(PROJECT_DIR)/build/%.o: $(PROJECT_DIR)/%.cpp + @echo 'Building $(notdir $<)...' +# @echo 'Invoking: C++ Compiler' + @$(CXX) $(SYNTAX_FLAG) $(INCLUDES) $(CPP_FLAGS) -Wall -c -fmessage-length=0 -U_FORTIFY_SOURCE -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" + @echo ' ...done' @echo ' ' # Rule for user-supplied C files -build/source/%.o: ./source/%.c - @echo 'Building file: $<' - @echo 'Invoking: C Compiler' - $(CC) $(SYNTAX_FLAG) $(INCLUDES) $(C_FLAGS) -Wall -c -fmessage-length=0 -U_FORTIFY_SOURCE -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" -std=c99 - @echo 'Finished building: $<' +$(PROJECT_DIR)/build/%.o: $(PROJECT_DIR)/%.c + @echo 'Building $(notdir $<)...' +# @echo 'Invoking: C Compiler' + @$(CC) $(SYNTAX_FLAG) $(INCLUDES) $(C_FLAGS) -Wall -c -fmessage-length=0 -U_FORTIFY_SOURCE -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" -std=c99 + @echo ' ...done' @echo ' ' # Rule for user-supplied assembly files -build/source/%.o: ./source/%.S - @echo 'Building file: $<' - @echo 'Invoking: GCC Assembler' - as -o "$@" "$<" - @echo 'Finished building: $<' +$(PROJECT_DIR)/build/%.o: $(PROJECT_DIR)/%.S + @echo 'Building $(notdir $<)...' +# @echo 'Invoking: GCC Assembler' + @as -o "$@" "$<" + @echo ' ...done' @echo ' ' # This is a nasty kludge: we want to be able to optionally link in a default @@ -119,29 +130,33 @@ # we want to link in the default main file or not. The kludge is the mess of a shell script # line below. Surely there's a better way to do this? BeagleRT: $(CORE_OBJS) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS) - $(eval NEXT_TARGET := $(shell bash -c 'if [ `nm build/source/*.o | grep -w T | grep -w main | wc -l` == '0' ]; then echo "BeagleRT_with_main"; else echo "BeagleRT_without_main"; fi')) - $(MAKE) $(NEXT_TARGET) - @echo 'Finished building target: $@' - @echo ' ' -# $(MAKE) --no-print-directory post-build + $(eval NEXT_TARGET := $(shell bash -c 'if [ `nm $(PROJECT_DIR)/build/*.o | grep -w T | grep -w main | wc -l` == '0' ]; then echo "BeagleRT_with_main"; else echo "BeagleRT_without_main"; fi')) + @$(MAKE) $(NEXT_TARGET) +# @echo 'Finished building target: $@' +# @echo ' ' +# $(MAKE) --no-print-directory post-build # Rule for building BeagleRT including the default main file (no user-supplied main()) BeagleRT_with_main: $(CORE_OBJS) $(DEFAULT_MAIN_OBJS) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS) - @echo 'Building target: $@' - @echo 'Invoking: C++ Linker' - $(CXX) $(SYNTAX_FLAG) -L/usr/xenomai/lib -L/usr/arm-linux-gnueabihf/lib -L/usr/arm-linux-gnueabihf/lib/xenomai -L/usr/lib/arm-linux-gnueabihf -pthread -Wpointer-arith -o "BeagleRT" $(CORE_OBJS) $(DEFAULT_MAIN_OBJS) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS) $(LIBS) - + @echo 'Linking default main.cpp...' +# @echo 'Invoking: C++ Linker' + @$(CXX) $(SYNTAX_FLAG) -L/usr/xenomai/lib -L/usr/arm-linux-gnueabihf/lib -L/usr/arm-linux-gnueabihf/lib/xenomai -L/usr/lib/arm-linux-gnueabihf -pthread -Wpointer-arith -o "$(PROJECT_DIR)/$(PROJECT)" $(CORE_OBJS) $(DEFAULT_MAIN_OBJS) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS) $(LIBS) + @echo ' ...done' + # Rule for building BeagleRT without the default main file (user-supplied main()) BeagleRT_without_main: $(CORE_OBJS) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS) - @echo 'Building target: $@' - @echo 'Invoking: C++ Linker' - $(CXX) $(SYNTAX_FLAG) -L/usr/xenomai/lib -L/usr/arm-linux-gnueabihf/lib -L/usr/arm-linux-gnueabihf/lib/xenomai -L/usr/lib/arm-linux-gnueabihf -pthread -Wpointer-arith -o "BeagleRT" $(CORE_OBJS) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS) $(LIBS) + @echo 'Linking main.cpp from project...' +# @echo 'Invoking: C++ Linker' + @$(CXX) $(SYNTAX_FLAG) -L/usr/xenomai/lib -L/usr/arm-linux-gnueabihf/lib -L/usr/arm-linux-gnueabihf/lib/xenomai -L/usr/lib/arm-linux-gnueabihf -pthread -Wpointer-arith -o "$(PROJECT_DIR)/$(PROJECT)" $(CORE_OBJS) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS) $(LIBS) + @echo ' ...done' + +# Other Targets: +# This rule compiles c and c++ source files without output or linking +SYNTAX: $(C_OBJS) $(CPP_OBJS) -# Other Targets: - -# Remove the temporary user-supplied source, plus the objects built from them -sourceclean: - -$(RM) source/* build/source/* BeagleRT +# Remove the project's build objects & binary +projectclean: + -$(RM) $(PROJECT_DIR)/build/* $(PROJECT_DIR)/$(PROJECT) -@echo ' ' # Remove all the built objects, including the core BeagleRT objects @@ -150,12 +165,12 @@ -@echo ' ' # Remove only the user-generated objects -clean: - -$(RM) build/source/* BeagleRT - -@echo ' ' +#clean: +# -$(RM) build/source/* BeagleRT +# -@echo ' ' post-build: # Nothing to do here (for now) -.PHONY: all clean distclean sourceclean dependents debug +.PHONY: all clean distclean projectclean dependents debug .SECONDARY: post-build