annotate Makefile @ 333:4edf9a840a2a prerelease

Makefile syncs buffer to disk after building. Closes #1698
author Giulio Moro <giuliomoro@yahoo.it>
date Sat, 04 Jun 2016 18:53:42 +0100
parents cfdf0003e6e8
children ff98d79abf49
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@331 29 OUTPUT_FILE?=$(PROJECT_DIR)/$(PROJECT)
giuliomoro@331 30 COMMAND_LINE_OPTIONS?=$(CL)
giuliomoro@331 31 RUN_COMMAND?=$(OUTPUT_FILE) $(COMMAND_LINE_OPTIONS)
giuliomoro@331 32 BELA_STARTUP_SCRIPT?=/root/BeagleRT_startup.sh
giuliomoro@331 33 BELA_AUDIO_THREAD_NAME?=beaglert-audio
giuliomoro@302 34 SCREEN_NAME?=BeagleRT
giuliomoro@302 35
giuliomoro@304 36 #TODO: run these lines only if the command is not syntax or
giuliomoro@267 37 $(shell mkdir -p $(PROJECT_DIR)/build)
giuliomoro@64 38 RM := rm -rf
giuliomoro@64 39 STATIC_LIBS := ./libprussdrv.a ./libNE10.a
l@260 40 LIBS := -lrt -lnative -lxenomai -lsndfile
l@260 41
giuliomoro@244 42 # refresh library cache and check if libpd is there
giuliomoro@326 43 #TEST_LIBPD := $(shell ldconfig; ldconfig -p | grep "libpd\.so") # safest but slower way of checking
giuliomoro@326 44 LIBPD_PATH = /usr/lib/libpd.so
giuliomoro@326 45 TEST_LIBPD := $(shell which $(LIBPD_PATH))
giuliomoro@326 46 ifneq ($(strip $(TEST_LIBPD)), )
giuliomoro@244 47 # if libpd is there, link it in
giuliomoro@244 48 LIBS += -lpd -lpthread_rt
giuliomoro@244 49 endif
giuliomoro@64 50
giuliomoro@241 51 CPP_FLAGS := -O3 -march=armv7-a -mtune=cortex-a8 -mfloat-abi=hard -mfpu=neon -ftree-vectorize
giuliomoro@241 52 C_FLAGS := $(CPP_FLAGS)
giuliomoro@241 53
giuliomoro@241 54 ifndef COMPILER
giuliomoro@241 55 # check whether clang is installed
giuliomoro@295 56 # TEST_COMPILER := $(shell which clang)
giuliomoro@302 57 ifneq ($(strip $(TEST_COMPILER)), )
giuliomoro@302 58 if it is installed, use it
giuliomoro@302 59 COMPILER := clang
giuliomoro@302 60 else
giuliomoro@241 61 COMPILER := gcc
giuliomoro@302 62 endif
giuliomoro@241 63 endif
giuliomoro@241 64
giuliomoro@241 65 ifeq ($(COMPILER), clang)
giuliomoro@306 66 CC=clang
giuliomoro@306 67 CXX=clang++
giuliomoro@302 68 CPP_FLAGS += -DNDEBUG
giuliomoro@302 69 C_FLAGS += -DNDEBUG
giuliomoro@241 70 else
giuliomoro@241 71 CC=gcc
giuliomoro@241 72 CXX=g++
giuliomoro@241 73 CPP_FLAGS += --fast-math
giuliomoro@241 74 C_FLAGS += --fast-math
giuliomoro@241 75 endif
giuliomoro@241 76
l@260 77 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 78
l@260 79 ASM_SRCS := $(wildcard $(PROJECT_DIR)/*.S)
l@260 80 ASM_OBJS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(ASM_SRCS:.S=.o)))
l@260 81 ASM_DEPS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(ASM_SRCS:.S=.d)))
giuliomoro@64 82
l@260 83 C_SRCS := $(wildcard $(PROJECT_DIR)/*.c)
l@260 84 C_OBJS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(C_SRCS:.c=.o)))
l@260 85 C_DEPS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(C_SRCS:.c=.d)))
giuliomoro@64 86
l@260 87 CPP_SRCS := $(wildcard $(PROJECT_DIR)/*.cpp)
l@260 88 CPP_OBJS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(CPP_SRCS:.cpp=.o)))
l@260 89 CPP_DEPS := $(addprefix $(PROJECT_DIR)/build/,$(notdir $(CPP_SRCS:.cpp=.d)))
giuliomoro@64 90
giuliomoro@301 91 # Core Bela sources
giuliomoro@186 92 CORE_CPP_SRCS = $(filter-out core/default_main.cpp, $(wildcard core/*.cpp))
giuliomoro@186 93 CORE_OBJS := $(addprefix build/core/,$(notdir $(CORE_CPP_SRCS:.cpp=.o)))
giuliomoro@186 94 CORE_CPP_DEPS := $(addprefix build/core/,$(notdir $(CORE_CPP_SRCS:.cpp=.d)))
giuliomoro@64 95
andrewm@318 96 CORE_ASM_SRCS := $(wildcard core/*.S)
andrewm@318 97 CORE_ASM_OBJS := $(addprefix build/core/,$(notdir $(CORE_ASM_SRCS:.S=.o)))
andrewm@318 98 CORE_ASM_DEPS := $(addprefix build/core/,$(notdir $(CORE_ASM_SRCS:.S=.d)))
andrewm@318 99
andrewm@318 100
giuliomoro@64 101 # Objects for a system-supplied default main() file, if the user
giuliomoro@64 102 # only wants to provide the render functions.
giuliomoro@64 103 DEFAULT_MAIN_CPP_SRCS := ./core/default_main.cpp
giuliomoro@64 104 DEFAULT_MAIN_OBJS := ./build/core/default_main.o
giuliomoro@64 105 DEFAULT_MAIN_CPP_DEPS := ./build/core/default_main.d
andrewm@68 106
giuliomoro@301 107 # all = build Bela
andrewm@69 108 all: SYNTAX_FLAG :=
giuliomoro@301 109 all: Bela
andrewm@68 110
giuliomoro@301 111 # debug = buildBela debug
giuliomoro@209 112 debug: CPP_FLAGS=-g
giuliomoro@209 113 debug: C_FLAGS=-g
giuliomoro@209 114 debug: all
giuliomoro@209 115
andrewm@69 116 # syntax = check syntax
andrewm@69 117 syntax: SYNTAX_FLAG := -fsyntax-only
l@260 118 syntax: SYNTAX
andrewm@69 119
giuliomoro@302 120
giuliomoro@302 121
giuliomoro@301 122 # Rule for Bela core C++ files
giuliomoro@64 123 build/core/%.o: ./core/%.cpp
l@260 124 @echo 'Building $(notdir $<)...'
l@260 125 # @echo 'Invoking: C++ Compiler'
l@260 126 @$(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 127 @echo ' ...done'
giuliomoro@64 128 @echo ' '
andrewm@68 129
andrewm@318 130 # Rule for Bela core ASM files
andrewm@318 131 build/core/%.o: ./core/%.S
andrewm@318 132 @echo 'Building $(notdir $<)...'
andrewm@318 133 # @echo 'Invoking: GCC Assembler'
andrewm@318 134 @as -o "$@" "$<"
andrewm@318 135 @echo ' ...done'
andrewm@318 136 @echo ' '
andrewm@318 137
giuliomoro@64 138 # Rule for user-supplied C++ files
l@260 139 $(PROJECT_DIR)/build/%.o: $(PROJECT_DIR)/%.cpp
l@260 140 @echo 'Building $(notdir $<)...'
l@260 141 # @echo 'Invoking: C++ Compiler'
l@260 142 @$(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 143 @echo ' ...done'
giuliomoro@64 144 @echo ' '
andrewm@68 145
giuliomoro@64 146 # Rule for user-supplied C files
l@260 147 $(PROJECT_DIR)/build/%.o: $(PROJECT_DIR)/%.c
l@260 148 @echo 'Building $(notdir $<)...'
l@260 149 # @echo 'Invoking: C Compiler'
giuliomoro@287 150 $(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 151 @echo ' ...done'
giuliomoro@64 152 @echo ' '
andrewm@68 153
giuliomoro@64 154 # Rule for user-supplied assembly files
l@260 155 $(PROJECT_DIR)/build/%.o: $(PROJECT_DIR)/%.S
l@260 156 @echo 'Building $(notdir $<)...'
l@260 157 # @echo 'Invoking: GCC Assembler'
l@260 158 @as -o "$@" "$<"
l@260 159 @echo ' ...done'
giuliomoro@64 160 @echo ' '
giuliomoro@64 161
giuliomoro@64 162 # This is a nasty kludge: we want to be able to optionally link in a default
giuliomoro@64 163 # main file if the user hasn't supplied one. We check for the presence of the main()
giuliomoro@64 164 # function, and conditionally call one of two recursive make targets depending on whether
giuliomoro@64 165 # we want to link in the default main file or not. The kludge is the mess of a shell script
giuliomoro@64 166 # line below. Surely there's a better way to do this?
giuliomoro@326 167 $(OUTPUT_FILE): $(CORE_ASM_OBJS) $(CORE_OBJS) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS) $(DEFAULT_MAIN_OBJS)
giuliomoro@287 168 $(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 169 @echo 'Invoking: C++ linker'
andrewm@318 170 @$(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_ASM_OBJS) $(CORE_OBJS) $(DEFAULT_MAIN_CONDITIONAL) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS) $(LIBS)
giuliomoro@287 171 @echo 'Finished building target: $@'
giuliomoro@333 172 @sync
l@260 173 # Other Targets:
l@260 174 # This rule compiles c and c++ source files without output or linking
l@260 175 SYNTAX: $(C_OBJS) $(CPP_OBJS)
giuliomoro@64 176
l@260 177 # Remove the project's build objects & binary
l@260 178 projectclean:
giuliomoro@326 179 -$(RM) $(PROJECT_DIR)/build/* $(OUTPUT_FILE)
giuliomoro@64 180 -@echo ' '
giuliomoro@64 181
giuliomoro@301 182 # Remove all the built objects, including the core Bela objects
giuliomoro@64 183 distclean:
giuliomoro@326 184 -$(RM) build/source/* $(CORE_OBJS) $(CORE_CPP_DEPS) $(DEFAULT_MAIN_OBJS) $(DEFAULT_MAIN_CPP_DEPS) $(OUTPUT_FILE)
giuliomoro@64 185 -@echo ' '
giuliomoro@64 186
giuliomoro@326 187 Bela: $(OUTPUT_FILE)
giuliomoro@326 188
giuliomoro@302 189 runfg: run
giuliomoro@326 190 run: stop Bela
giuliomoro@327 191 @echo "Running $(RUN_COMMAND)"
giuliomoro@327 192 @cd $(PROJECT_DIR) && $(RUN_COMMAND)
giuliomoro@302 193 runscreen: stop $(OUTPUT_FILE)
giuliomoro@327 194 @echo "Running $(RUN_COMMAND) in a screen"
giuliomoro@327 195 @cd $(PROJECT_DIR) && screen -S $(SCREEN_NAME) -d -m $(RUN_COMMAND)
giuliomoro@313 196 runscreenfg: stop $(OUTPUT_FILE)
giuliomoro@327 197 @echo "Running $(RUN_COMMAND) in a screen"
giuliomoro@327 198 @cd $(PROJECT_DIR) && screen -S $(SCREEN_NAME) -m $(RUN_COMMAND)
giuliomoro@313 199 FIFO_NAME=/tmp/belafifo
giuliomoro@313 200 runscreenfifo: stop $(OUTPUT_FILE)
giuliomoro@313 201 @echo "Running $(RUN_COMMAND), piping output to $(FIFO_NAME)"
giuliomoro@313 202 @rm -rf $(FIFO_NAME)
giuliomoro@313 203 @mkfifo $(FIFO_NAME)
giuliomoro@327 204 @cd $(PROJECT_DIR)
giuliomoro@315 205 @screen -S $(SCREEN_NAME) -d -m stdbuf -e 0 -i 0 -o 0 bash -c "$(RUN_COMMAND) &> $(FIFO_NAME)"
giuliomoro@315 206 @cat /tmp/belafifo
giuliomoro@302 207
giuliomoro@331 208 STARTUP_COMMAND=printf "\#!/bin/sh\n\#\n\# This file is autogenerated by Bela. Do not edit!\n\necho Running Bela...\nscreen -S $(SCREEN_NAME) -d -m %s $(RUN_COMMAND) %s\n"
giuliomoro@331 209 nostartup:
giuliomoro@331 210 @echo "Disabling BeagleRT at startup..."
giuliomoro@331 211 @printf "#!/bin/sh\n#\n\n# This file is autogenerated by Bela. Do not edit!\n\n# Run on startup disabled -- nothing to do here" > $BELA_STARTUP_SCRIPT
giuliomoro@331 212
giuliomoro@331 213 startuploop: Bela
giuliomoro@331 214 @echo "Enabling Bela at startup in a loop..."
giuliomoro@331 215 @$(STARTUP_COMMAND) 'bash -c "while sleep 0.5 ; do echo Running Bela...;' '; done"' > $(BELA_STARTUP_SCRIPT)
giuliomoro@331 216
giuliomoro@331 217 startup: Bela
giuliomoro@331 218 @echo "Enabling Bela at startup..."
giuliomoro@331 219 @$(STARTUP_COMMAND) > $(BELA_STARTUP_SCRIPT)
giuliomoro@331 220
giuliomoro@302 221 stop:
giuliomoro@302 222 @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 223 # Remove only the user-generated objects
l@260 224 #clean:
giuliomoro@301 225 # -$(RM) build/source/* Bela
l@260 226 # -@echo ' '
giuliomoro@64 227
giuliomoro@64 228 post-build:
giuliomoro@64 229 # Nothing to do here (for now)
giuliomoro@64 230
giuliomoro@326 231 .PHONY: all clean distclean projectclean dependents debug run runfg runscreen stop
giuliomoro@64 232 .SECONDARY: post-build