giuliomoro@64: # BeagleRT
giuliomoro@64: # Low-latency, real-time audio and sensor processing on BeagleBone Black
giuliomoro@64: # (c) 2015 Andrew McPherson, Victor Zappi, Giulio Moro
giuliomoro@64: # Centre for Digital Music, Queen Mary University of London
giuliomoro@64: 
giuliomoro@64: # This Makefile is intended for use on the BeagleBone Black itself
giuliomoro@64: # and not for cross-compiling
giuliomoro@64: 
giuliomoro@64: RM := rm -rf
giuliomoro@64: STATIC_LIBS := ./libprussdrv.a ./libNE10.a
giuliomoro@64: LIBS := -lrt -lnative -lxenomai
giuliomoro@64: 
andrewm@68: INCLUDES := -I/usr/include/ne10 -I/usr/xenomai/include -I/usr/arm-linux-gnueabihf/include/xenomai/include -I/usr/arm-linux-gnueabihf/include/ne10
andrewm@68: 
andrewm@68: 
giuliomoro@64: ASM_SRCS := $(wildcard source/*.S)
giuliomoro@64: ASM_OBJS := $(addprefix build/source/,$(notdir $(ASM_SRCS:.S=.o)))
giuliomoro@64: ASM_DEPS := $(addprefix build/source/,$(notdir $(ASM_SRCS:.S=.d)))
giuliomoro@64: 
giuliomoro@64: C_SRCS := $(wildcard source/*.c)
giuliomoro@64: C_OBJS := $(addprefix build/source/,$(notdir $(C_SRCS:.c=.o)))
giuliomoro@64: C_DEPS := $(addprefix build/source/,$(notdir $(C_SRCS:.c=.d)))
giuliomoro@64: 
giuliomoro@64: CPP_SRCS := $(wildcard source/*.cpp)
giuliomoro@64: CPP_OBJS := $(addprefix build/source/,$(notdir $(CPP_SRCS:.cpp=.o)))
giuliomoro@64: CPP_DEPS := $(addprefix build/source/,$(notdir $(CPP_SRCS:.cpp=.d)))
giuliomoro@64: 
giuliomoro@64: # Core BeagleRT sources
giuliomoro@64: CORE_CPP_SRCS := \
giuliomoro@64: ./core/GPIOcontrol.cpp \
giuliomoro@64: ./core/I2c_Codec.cpp \
giuliomoro@64: ./core/PRU.cpp \
giuliomoro@64: ./core/RTAudio.cpp \
giuliomoro@64: ./core/RTAudioCommandLine.cpp \
giuliomoro@64: ./core/Utilities.cpp \
giuliomoro@105: ./core/UdpClient.cpp
giuliomoro@64: 
giuliomoro@64: CORE_OBJS := \
giuliomoro@64: ./build/core/GPIOcontrol.o \
giuliomoro@64: ./build/core/I2c_Codec.o \
giuliomoro@64: ./build/core/PRU.o \
giuliomoro@64: ./build/core/RTAudio.o \
giuliomoro@64: ./build/core/RTAudioCommandLine.o \
giuliomoro@64: ./build/core/Utilities.o \
giuliomoro@105: ./build/core/UdpClient.o
giuliomoro@64: 
giuliomoro@64: CORE_CPP_DEPS := \
giuliomoro@64: ./build/core/GPIOcontrol.d \
giuliomoro@64: ./build/core/I2c_Codec.d \
giuliomoro@64: ./build/core/PRU.d \
giuliomoro@64: ./build/core/RTAudio.d \
giuliomoro@64: ./build/core/RTAudioCommandLine.d \
giuliomoro@64: ./build/core/Utilities.d \
giuliomoro@105: ./build/core/UdpClient.d
giuliomoro@64: 
giuliomoro@64: # Objects for a system-supplied default main() file, if the user
giuliomoro@64: # only wants to provide the render functions.
giuliomoro@64: DEFAULT_MAIN_CPP_SRCS := ./core/default_main.cpp
giuliomoro@64: DEFAULT_MAIN_OBJS := ./build/core/default_main.o
giuliomoro@64: DEFAULT_MAIN_CPP_DEPS := ./build/core/default_main.d
andrewm@68: 
giuliomoro@64: # All = build BeagleRT
andrewm@69: all: SYNTAX_FLAG :=
giuliomoro@64: all: BeagleRT
andrewm@68: 
andrewm@69: # syntax = check syntax
andrewm@69: syntax: SYNTAX_FLAG := -fsyntax-only
andrewm@69: syntax: BeagleRT
andrewm@69: 
giuliomoro@64: # Rule for BeagleRT core C++ files
giuliomoro@64: build/core/%.o: ./core/%.cpp
giuliomoro@64: 	@echo 'Building file: $<'
giuliomoro@64: 	@echo 'Invoking: GCC C++ Compiler'
andrewm@69: 	g++ $(SYNTAX_FLAG) $(INCLUDES) -O2 -Wall -c -fmessage-length=0 -U_FORTIFY_SOURCE -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<"
giuliomoro@64: 	@echo 'Finished building: $<'
giuliomoro@64: 	@echo ' '
andrewm@68: 
giuliomoro@64: # Rule for user-supplied C++ files
giuliomoro@64: build/source/%.o: ./source/%.cpp
giuliomoro@64: 	@echo 'Building file: $<'
giuliomoro@64: 	@echo 'Invoking: GCC C++ Compiler'
andrewm@69: 	g++ $(SYNTAX_FLAG) -I./include $(INCLUDES) -O2 -Wall -c -fmessage-length=0 -U_FORTIFY_SOURCE -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<"
giuliomoro@64: 	@echo 'Finished building: $<'
giuliomoro@64: 	@echo ' '
andrewm@68: 
giuliomoro@64: # Rule for user-supplied C files
giuliomoro@64: build/source/%.o: ./source/%.c
giuliomoro@64: 	@echo 'Building file: $<'
giuliomoro@64: 	@echo 'Invoking: GCC C Compiler'
andrewm@69: 	gcc $(SYNTAX_FLAG) -I./include $(INCLUDES) -O2 -Wall -c -fmessage-length=0 -U_FORTIFY_SOURCE -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<"
giuliomoro@64: 	@echo 'Finished building: $<'
giuliomoro@64: 	@echo ' '
andrewm@68: 
giuliomoro@64: # Rule for user-supplied assembly files
giuliomoro@64: build/source/%.o: ./source/%.S
giuliomoro@64: 	@echo 'Building file: $<'
giuliomoro@64: 	@echo 'Invoking: GCC Assembler'
giuliomoro@64: 	as  -o "$@" "$<"
giuliomoro@64: 	@echo 'Finished building: $<'
giuliomoro@64: 	@echo ' '
giuliomoro@64: 
giuliomoro@64: # This is a nasty kludge: we want to be able to optionally link in a default
giuliomoro@64: # main file if the user hasn't supplied one. We check for the presence of the main()
giuliomoro@64: # function, and conditionally call one of two recursive make targets depending on whether
giuliomoro@64: # we want to link in the default main file or not. The kludge is the mess of a shell script
giuliomoro@64: # line below. Surely there's a better way to do this?
giuliomoro@64: BeagleRT: $(CORE_OBJS) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS)
giuliomoro@64: 	$(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'))
giuliomoro@64: 	$(MAKE) $(NEXT_TARGET)
giuliomoro@64: 	@echo 'Finished building target: $@'
giuliomoro@64: 	@echo ' '
giuliomoro@64: #	$(MAKE) --no-print-directory post-build	
andrewm@68: 
giuliomoro@64: # Rule for building BeagleRT including the default main file (no user-supplied main())
giuliomoro@64: BeagleRT_with_main: $(CORE_OBJS) $(DEFAULT_MAIN_OBJS) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS)
giuliomoro@64: 	@echo 'Building target: $@'
giuliomoro@64: 	@echo 'Invoking: GCC C++ Linker'
andrewm@69: 	g++ $(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)
giuliomoro@64: 
giuliomoro@64: # Rule for building BeagleRT without the default main file (user-supplied main())
giuliomoro@64: BeagleRT_without_main: $(CORE_OBJS) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS) 
giuliomoro@64: 	@echo 'Building target: $@'
giuliomoro@64: 	@echo 'Invoking: GCC C++ Linker'
andrewm@69: 	g++ $(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)
giuliomoro@64: 
giuliomoro@64: # Other Targets:
giuliomoro@64: 
giuliomoro@64: # Remove the temporary user-supplied source, plus the objects built from them
giuliomoro@64: sourceclean:
giuliomoro@64: 	-$(RM) source/* build/source/* BeagleRT
giuliomoro@64: 	-@echo ' '	
giuliomoro@64: 
giuliomoro@64: # Remove all the built objects, including the core BeagleRT objects
giuliomoro@64: distclean:
giuliomoro@64: 	-$(RM) build/source/* $(CORE_OBJS) $(CORE_CPP_DEPS) $(DEFAULT_MAIN_OBJS) $(DEFAULT_MAIN_CPP_DEPS) BeagleRT
giuliomoro@64: 	-@echo ' '
giuliomoro@64: 
giuliomoro@64: # Remove only the user-generated objects
giuliomoro@64: clean:
giuliomoro@64: 	-$(RM) build/source/* BeagleRT
giuliomoro@64: 	-@echo ' '
giuliomoro@64: 
giuliomoro@64: post-build:
giuliomoro@64: # Nothing to do here (for now)
giuliomoro@64: 
giuliomoro@64: .PHONY: all clean distclean sourceclean dependents
giuliomoro@64: .SECONDARY: post-build