changeset 241:adfe95c3cd73

Flexible Makefile: tries to use clang if available. Defaults to gcc otherwise
author Giulio Moro <giuliomoro@yahoo.it>
date Mon, 18 Apr 2016 03:04:34 +0100
parents 1fd334f64f0a
children db76215feb69
files Makefile
diffstat 1 files changed, 36 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Thu Apr 14 15:44:38 2016 +0100
+++ b/Makefile	Mon Apr 18 03:04:34 2016 +0100
@@ -10,9 +10,34 @@
 STATIC_LIBS := ./libprussdrv.a ./libNE10.a
 LIBS := -lrt -lnative -lxenomai -lsndfile -lpd 
 
+CPP_FLAGS := -O3 -march=armv7-a -mtune=cortex-a8 -mfloat-abi=hard -mfpu=neon -ftree-vectorize 
+C_FLAGS := $(CPP_FLAGS)
+
+ifndef COMPILER
+# check whether clang is installed
+    TEST_COMPILER := $(shell which clang)
+  ifneq ($(strip $(TEST_COMPILER)), )
+    # if it is installed, use it
+    COMPILER := clang
+  else
+    COMPILER := gcc
+  endif
+endif
+
+ifeq ($(COMPILER), clang)
+  CC=clang
+  CXX=clang++
+  CPP_FLAGS +=
+  C _FLAGS +=
+else
+  CC=gcc
+  CXX=g++
+  CPP_FLAGS += --fast-math
+  C_FLAGS += --fast-math
+endif
+
 INCLUDES := -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)))
@@ -36,9 +61,6 @@
 DEFAULT_MAIN_OBJS := ./build/core/default_main.o
 DEFAULT_MAIN_CPP_DEPS := ./build/core/default_main.d
 
-CPP_FLAGS=-O3 -march=armv7-a -mtune=cortex-a8 -mfloat-abi=hard -mfpu=neon --fast-math -ftree-vectorize 
-C_FLAGS=-O3 -march=armv7-a -mtune=cortex-a8 -mfloat-abi=hard -mfpu=neon --fast-math -ftree-vectorize 
-
 # all = build BeagleRT 
 all: SYNTAX_FLAG :=
 all: BeagleRT
@@ -55,24 +77,24 @@
 # Rule for BeagleRT core C++ files
 build/core/%.o: ./core/%.cpp
 	@echo 'Building file: $<'
-	@echo 'Invoking: GCC C++ Compiler'
-	g++ $(SYNTAX_FLAG) $(INCLUDES) $(CPP_FLAGS) -Wall -c -fmessage-length=0 -U_FORTIFY_SOURCE -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<"
+	@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 ' '
 
 # Rule for user-supplied C++ files
 build/source/%.o: ./source/%.cpp
 	@echo 'Building file: $<'
-	@echo 'Invoking: GCC C++ Compiler'
-	g++ $(SYNTAX_FLAG) $(INCLUDES) $(CPP_FLAGS) -Wall -c -fmessage-length=0 -U_FORTIFY_SOURCE -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<"
+	@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 ' '
 
 # Rule for user-supplied C files
 build/source/%.o: ./source/%.c
 	@echo 'Building file: $<'
-	@echo 'Invoking: GCC C Compiler'
-	gcc $(SYNTAX_FLAG) $(INCLUDES) $(C_FLAGS) -Wall -c -fmessage-length=0 -U_FORTIFY_SOURCE -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" -std=c99 -mfpu=neon
+	@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: $<'
 	@echo ' '
 
@@ -99,14 +121,14 @@
 # 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: GCC C++ Linker'
-	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)
+	@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)
 
 # 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: GCC C++ Linker'
-	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)
+	@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)
 
 # Other Targets: