annotate Makefile @ 315:868cfb137fe5 prerelease

make runscreenfifo will now output to stdout
author Giulio Moro <giuliomoro@yahoo.it>
date Fri, 27 May 2016 19:26:09 +0100
parents c770cdf3d8b2
children f7b19ea31bbb
rev   line source
giuliomoro@301 1 # Bela
giuliomoro@64 2 # Low-latency, real-time audio and sensor processing on BeagleBone Black
l@260 3 # (c) 2016 Andrew McPherson, Victor Zappi, Giulio Moro, Liam Donovan
giuliomoro@64 4 # Centre for Digital Music, Queen Mary University of London
giuliomoro@64 5
giuliomoro@64 6 # This Makefile is intended for use on the BeagleBone Black itself
giuliomoro@64 7 # and not for cross-compiling
giuliomoro@64 8
l@260 9 # set the project to be compiled by calling: make all PROJECT=<project_name>
l@260 10
l@260 11 # if the PROJECT variable is not set, throw an error and exit
giuliomoro@265 12 # otherwise, we could have unexpected data loss when calling clean without it
l@260 13 ifndef PROJECT
giuliomoro@287 14 ifndef EXAMPLE
giuliomoro@302 15 $(warning PROJECT or EXAMPLE should be set in order to build)
giuliomoro@287 16 endif
l@260 17 endif
l@260 18
giuliomoro@287 19 ifndef EXAMPLE
giuliomoro@287 20 PROJECT_DIR := $(abspath projects/$(PROJECT))
giuliomoro@287 21 endif
giuliomoro@287 22
giuliomoro@287 23 ifdef EXAMPLE
giuliomoro@287 24 PROJECT?=exampleTempProject
giuliomoro@287 25 PROJECT_DIR?=$(abspath projects/$(PROJECT))
giuliomoro@287 26 $(shell rm -rf $(PROJECT_DIR))
giuliomoro@287 27 $(shell cp -r examples/$(EXAMPLE) $(PROJECT_DIR))
giuliomoro@287 28 endif
giuliomoro@287 29
giuliomoro@302 30 SCREEN_NAME?=BeagleRT
giuliomoro@302 31
giuliomoro@304 32 #TODO: run these lines only if the command is not syntax or
giuliomoro@267 33 $(shell mkdir -p $(PROJECT_DIR)/build)
giuliomoro@64 34 RM := rm -rf
giuliomoro@64 35 STATIC_LIBS := ./libprussdrv.a ./libNE10.a
l@260 36 LIBS := -lrt -lnative -lxenomai -lsndfile
l@260 37
giuliomoro@244 38 # refresh library cache and check if libpd is there
giuliomoro@244 39 TEST_LIBPD := $(shell ldconfig; ldconfig -p | grep "libpd\.so")
giuliomoro@244 40 ifeq ($(strip $(TEST_LIBPD)), )
giuliomoro@244 41 else
giuliomoro@244 42 # if libpd is there, link it in
giuliomoro@244 43 LIBS += -lpd -lpthread_rt
giuliomoro@244 44 endif
giuliomoro@64 45
giuliomoro@241 46 CPP_FLAGS := -O3 -march=armv7-a -mtune=cortex-a8 -mfloat-abi=hard -mfpu=neon -ftree-vectorize
giuliomoro@241 47 C_FLAGS := $(CPP_FLAGS)
giuliomoro@241 48
giuliomoro@241 49 ifndef COMPILER
giuliomoro@241 50 # check whether clang is installed
giuliomoro@295 51 # TEST_COMPILER := $(shell which clang)
giuliomoro@302 52 ifneq ($(strip $(TEST_COMPILER)), )
giuliomoro@302 53 if it is installed, use it
giuliomoro@302 54 COMPILER := clang
giuliomoro@302 55 else
giuliomoro@241 56 COMPILER := gcc
giuliomoro@302 57 endif
giuliomoro@241 58 endif
giuliomoro@241 59
giuliomoro@241 60 ifeq ($(COMPILER), clang)
giuliomoro@306 61 CC=clang
giuliomoro@306 62 CXX=clang++
giuliomoro@302 63 CPP_FLAGS += -DNDEBUG
giuliomoro@302 64 C_FLAGS += -DNDEBUG
giuliomoro@241 65 else
giuliomoro@241 66 CC=gcc
giuliomoro@241 67 CXX=g++
giuliomoro@241 68 CPP_FLAGS += --fast-math
giuliomoro@241 69 C_FLAGS += --fast-math
giuliomoro@241 70 endif
giuliomoro@241 71
l@260 72 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
andrewm@68 73
l@260 74 ASM_SRCS := $(wildcard $(PROJECT_DIR)/*.S)
l@260 75 ASM_OBJS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(ASM_SRCS:.S=.o)))
l@260 76 ASM_DEPS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(ASM_SRCS:.S=.d)))
giuliomoro@64 77
l@260 78 C_SRCS := $(wildcard $(PROJECT_DIR)/*.c)
l@260 79 C_OBJS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(C_SRCS:.c=.o)))
l@260 80 C_DEPS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(C_SRCS:.c=.d)))
giuliomoro@64 81
l@260 82 CPP_SRCS := $(wildcard $(PROJECT_DIR)/*.cpp)
l@260 83 CPP_OBJS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(CPP_SRCS:.cpp=.o)))
l@260 84 CPP_DEPS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(CPP_SRCS:.cpp=.d)))
giuliomoro@64 85
giuliomoro@301 86 # Core Bela sources
giuliomoro@186 87 CORE_CPP_SRCS = $(filter-out core/default_main.cpp, $(wildcard core/*.cpp))
giuliomoro@186 88 CORE_OBJS := $(addprefix build/core/,$(notdir $(CORE_CPP_SRCS:.cpp=.o)))
giuliomoro@186 89 CORE_CPP_DEPS := $(addprefix build/core/,$(notdir $(CORE_CPP_SRCS:.cpp=.d)))
giuliomoro@64 90
giuliomoro@64 91 # Objects for a system-supplied default main() file, if the user
giuliomoro@64 92 # only wants to provide the render functions.
giuliomoro@64 93 DEFAULT_MAIN_CPP_SRCS := ./core/default_main.cpp
giuliomoro@64 94 DEFAULT_MAIN_OBJS := ./build/core/default_main.o
giuliomoro@64 95 DEFAULT_MAIN_CPP_DEPS := ./build/core/default_main.d
andrewm@68 96
giuliomoro@301 97 # all = build Bela
andrewm@69 98 all: SYNTAX_FLAG :=
giuliomoro@301 99 all: Bela
andrewm@68 100
giuliomoro@301 101 # debug = buildBela debug
giuliomoro@209 102 debug: CPP_FLAGS=-g
giuliomoro@209 103 debug: C_FLAGS=-g
giuliomoro@209 104 debug: all
giuliomoro@209 105
andrewm@69 106 # syntax = check syntax
andrewm@69 107 syntax: SYNTAX_FLAG := -fsyntax-only
l@260 108 syntax: SYNTAX
andrewm@69 109
giuliomoro@302 110
giuliomoro@302 111
giuliomoro@301 112 # Rule for Bela core C++ files
giuliomoro@64 113 build/core/%.o: ./core/%.cpp
l@260 114 @echo 'Building $(notdir $<)...'
l@260 115 # @echo 'Invoking: C++ Compiler'
l@260 116 @$(CXX) $(SYNTAX_FLAG) $(INCLUDES) $(CPP_FLAGS) -Wall -c -fmessage-length=0 -U_FORTIFY_SOURCE -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<"
l@260 117 @echo ' ...done'
giuliomoro@64 118 @echo ' '
andrewm@68 119
giuliomoro@64 120 # Rule for user-supplied C++ files
l@260 121 $(PROJECT_DIR)/build/%.o: $(PROJECT_DIR)/%.cpp
l@260 122 @echo 'Building $(notdir $<)...'
l@260 123 # @echo 'Invoking: C++ Compiler'
l@260 124 @$(CXX) $(SYNTAX_FLAG) $(INCLUDES) $(CPP_FLAGS) -Wall -c -fmessage-length=0 -U_FORTIFY_SOURCE -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<"
l@260 125 @echo ' ...done'
giuliomoro@64 126 @echo ' '
andrewm@68 127
giuliomoro@64 128 # Rule for user-supplied C files
l@260 129 $(PROJECT_DIR)/build/%.o: $(PROJECT_DIR)/%.c
l@260 130 @echo 'Building $(notdir $<)...'
l@260 131 # @echo 'Invoking: C Compiler'
giuliomoro@287 132 $(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
l@260 133 @echo ' ...done'
giuliomoro@64 134 @echo ' '
andrewm@68 135
giuliomoro@64 136 # Rule for user-supplied assembly files
l@260 137 $(PROJECT_DIR)/build/%.o: $(PROJECT_DIR)/%.S
l@260 138 @echo 'Building $(notdir $<)...'
l@260 139 # @echo 'Invoking: GCC Assembler'
l@260 140 @as -o "$@" "$<"
l@260 141 @echo ' ...done'
giuliomoro@64 142 @echo ' '
giuliomoro@64 143
giuliomoro@64 144 # This is a nasty kludge: we want to be able to optionally link in a default
giuliomoro@64 145 # main file if the user hasn't supplied one. We check for the presence of the main()
giuliomoro@64 146 # function, and conditionally call one of two recursive make targets depending on whether
giuliomoro@64 147 # we want to link in the default main file or not. The kludge is the mess of a shell script
giuliomoro@64 148 # line below. Surely there's a better way to do this?
giuliomoro@301 149 Bela: $(CORE_OBJS) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS) $(DEFAULT_MAIN_OBJS)
giuliomoro@287 150 $(eval DEFAULT_MAIN_CONDITIONAL := $(shell bash -c 'if [ `nm $(PROJECT_DIR)/build/*.o | grep -w T | grep -w main | wc -l` == '0' ]; then echo "$(DEFAULT_MAIN_OBJS)"; else echo ""; fi'))
giuliomoro@287 151 @echo 'Invoking: C++ linker'
giuliomoro@287 152 @$(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_CONDITIONAL) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS) $(LIBS)
giuliomoro@287 153 @echo 'Finished building target: $@'
andrewm@68 154
l@260 155 # Other Targets:
l@260 156 # This rule compiles c and c++ source files without output or linking
l@260 157 SYNTAX: $(C_OBJS) $(CPP_OBJS)
giuliomoro@64 158
l@260 159 # Remove the project's build objects & binary
l@260 160 projectclean:
l@260 161 -$(RM) $(PROJECT_DIR)/build/* $(PROJECT_DIR)/$(PROJECT)
giuliomoro@64 162 -@echo ' '
giuliomoro@64 163
giuliomoro@301 164 # Remove all the built objects, including the core Bela objects
giuliomoro@64 165 distclean:
giuliomoro@301 166 -$(RM) build/source/* $(CORE_OBJS) $(CORE_CPP_DEPS) $(DEFAULT_MAIN_OBJS) $(DEFAULT_MAIN_CPP_DEPS) Bela
giuliomoro@64 167 -@echo ' '
giuliomoro@287 168 OUTPUT_FILE="$(PROJECT_DIR)/$(PROJECT)"
giuliomoro@64 169
giuliomoro@301 170 $(OUTPUT_FILE): Bela
giuliomoro@313 171 COMMAND_LINE_OPTIONS=$(CL)
giuliomoro@313 172 RUN_COMMAND=$(OUTPUT_FILE) $(COMMAND_LINE_OPTIONS)
giuliomoro@302 173 runfg: run
giuliomoro@304 174 run: stop $(OUTPUT_FILE)
giuliomoro@313 175 echo "Running $(RUN_COMMAND)"
giuliomoro@313 176 $(RUN_COMMAND)
giuliomoro@302 177 runscreen: stop $(OUTPUT_FILE)
giuliomoro@313 178 echo "Running $(RUN_COMMAND) in a screen"
giuliomoro@313 179 screen -S $(SCREEN_NAME) -d -m $(RUN_COMMAND)
giuliomoro@313 180 runscreenfg: stop $(OUTPUT_FILE)
giuliomoro@313 181 echo "Running $(RUN_COMMAND) in a screen"
giuliomoro@313 182 screen -S $(SCREEN_NAME) -m $(RUN_COMMAND)
giuliomoro@313 183 FIFO_NAME=/tmp/belafifo
giuliomoro@313 184 runscreenfifo: stop $(OUTPUT_FILE)
giuliomoro@313 185 @echo "Running $(RUN_COMMAND), piping output to $(FIFO_NAME)"
giuliomoro@313 186 @rm -rf $(FIFO_NAME)
giuliomoro@313 187 @mkfifo $(FIFO_NAME)
giuliomoro@315 188 @screen -S $(SCREEN_NAME) -d -m stdbuf -e 0 -i 0 -o 0 bash -c "$(RUN_COMMAND) &> $(FIFO_NAME)"
giuliomoro@315 189 @cat /tmp/belafifo
giuliomoro@302 190
giuliomoro@302 191 BELA_AUDIO_THREAD_NAME=beaglert-audio
giuliomoro@302 192 stop:
giuliomoro@302 193 @PID=`grep $(BELA_AUDIO_THREAD_NAME) /proc/xenomai/stat | cut -d " " -f 5 | sed s/\s//g`; if [ -z $$PID ]; then echo "No process to kill"; else echo "Killing old Bela process $$PID"; kill -2 $$PID; fi; screen -X -S $(SCREEN_NAME) quit > /dev/null; exit 0;
giuliomoro@64 194 # Remove only the user-generated objects
l@260 195 #clean:
giuliomoro@301 196 # -$(RM) build/source/* Bela
l@260 197 # -@echo ' '
giuliomoro@64 198
giuliomoro@64 199 post-build:
giuliomoro@64 200 # Nothing to do here (for now)
giuliomoro@64 201
giuliomoro@287 202 .PHONY: all clean distclean projectclean dependents debug run
giuliomoro@64 203 .SECONDARY: post-build