comparison Makefile @ 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 c0bf6157f67e
children b0ad11ec5d50
comparison
equal deleted inserted replaced
240:1fd334f64f0a 241:adfe95c3cd73
8 8
9 RM := rm -rf 9 RM := rm -rf
10 STATIC_LIBS := ./libprussdrv.a ./libNE10.a 10 STATIC_LIBS := ./libprussdrv.a ./libNE10.a
11 LIBS := -lrt -lnative -lxenomai -lsndfile -lpd 11 LIBS := -lrt -lnative -lxenomai -lsndfile -lpd
12 12
13 CPP_FLAGS := -O3 -march=armv7-a -mtune=cortex-a8 -mfloat-abi=hard -mfpu=neon -ftree-vectorize
14 C_FLAGS := $(CPP_FLAGS)
15
16 ifndef COMPILER
17 # check whether clang is installed
18 TEST_COMPILER := $(shell which clang)
19 ifneq ($(strip $(TEST_COMPILER)), )
20 # if it is installed, use it
21 COMPILER := clang
22 else
23 COMPILER := gcc
24 endif
25 endif
26
27 ifeq ($(COMPILER), clang)
28 CC=clang
29 CXX=clang++
30 CPP_FLAGS +=
31 C _FLAGS +=
32 else
33 CC=gcc
34 CXX=g++
35 CPP_FLAGS += --fast-math
36 C_FLAGS += --fast-math
37 endif
38
13 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 39 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
14
15 40
16 ASM_SRCS := $(wildcard source/*.S) 41 ASM_SRCS := $(wildcard source/*.S)
17 ASM_OBJS := $(addprefix build/source/,$(notdir $(ASM_SRCS:.S=.o))) 42 ASM_OBJS := $(addprefix build/source/,$(notdir $(ASM_SRCS:.S=.o)))
18 ASM_DEPS := $(addprefix build/source/,$(notdir $(ASM_SRCS:.S=.d))) 43 ASM_DEPS := $(addprefix build/source/,$(notdir $(ASM_SRCS:.S=.d)))
19 44
34 # only wants to provide the render functions. 59 # only wants to provide the render functions.
35 DEFAULT_MAIN_CPP_SRCS := ./core/default_main.cpp 60 DEFAULT_MAIN_CPP_SRCS := ./core/default_main.cpp
36 DEFAULT_MAIN_OBJS := ./build/core/default_main.o 61 DEFAULT_MAIN_OBJS := ./build/core/default_main.o
37 DEFAULT_MAIN_CPP_DEPS := ./build/core/default_main.d 62 DEFAULT_MAIN_CPP_DEPS := ./build/core/default_main.d
38 63
39 CPP_FLAGS=-O3 -march=armv7-a -mtune=cortex-a8 -mfloat-abi=hard -mfpu=neon --fast-math -ftree-vectorize
40 C_FLAGS=-O3 -march=armv7-a -mtune=cortex-a8 -mfloat-abi=hard -mfpu=neon --fast-math -ftree-vectorize
41
42 # all = build BeagleRT 64 # all = build BeagleRT
43 all: SYNTAX_FLAG := 65 all: SYNTAX_FLAG :=
44 all: BeagleRT 66 all: BeagleRT
45 67
46 # debug = buildBeagleRT debug 68 # debug = buildBeagleRT debug
53 syntax: BeagleRT 75 syntax: BeagleRT
54 76
55 # Rule for BeagleRT core C++ files 77 # Rule for BeagleRT core C++ files
56 build/core/%.o: ./core/%.cpp 78 build/core/%.o: ./core/%.cpp
57 @echo 'Building file: $<' 79 @echo 'Building file: $<'
58 @echo 'Invoking: GCC C++ Compiler' 80 @echo 'Invoking: C++ Compiler'
59 g++ $(SYNTAX_FLAG) $(INCLUDES) $(CPP_FLAGS) -Wall -c -fmessage-length=0 -U_FORTIFY_SOURCE -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" 81 $(CXX) $(SYNTAX_FLAG) $(INCLUDES) $(CPP_FLAGS) -Wall -c -fmessage-length=0 -U_FORTIFY_SOURCE -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<"
60 @echo 'Finished building: $<' 82 @echo 'Finished building: $<'
61 @echo ' ' 83 @echo ' '
62 84
63 # Rule for user-supplied C++ files 85 # Rule for user-supplied C++ files
64 build/source/%.o: ./source/%.cpp 86 build/source/%.o: ./source/%.cpp
65 @echo 'Building file: $<' 87 @echo 'Building file: $<'
66 @echo 'Invoking: GCC C++ Compiler' 88 @echo 'Invoking: C++ Compiler'
67 g++ $(SYNTAX_FLAG) $(INCLUDES) $(CPP_FLAGS) -Wall -c -fmessage-length=0 -U_FORTIFY_SOURCE -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" 89 $(CXX) $(SYNTAX_FLAG) $(INCLUDES) $(CPP_FLAGS) -Wall -c -fmessage-length=0 -U_FORTIFY_SOURCE -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<"
68 @echo 'Finished building: $<' 90 @echo 'Finished building: $<'
69 @echo ' ' 91 @echo ' '
70 92
71 # Rule for user-supplied C files 93 # Rule for user-supplied C files
72 build/source/%.o: ./source/%.c 94 build/source/%.o: ./source/%.c
73 @echo 'Building file: $<' 95 @echo 'Building file: $<'
74 @echo 'Invoking: GCC C Compiler' 96 @echo 'Invoking: C Compiler'
75 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 97 $(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
76 @echo 'Finished building: $<' 98 @echo 'Finished building: $<'
77 @echo ' ' 99 @echo ' '
78 100
79 # Rule for user-supplied assembly files 101 # Rule for user-supplied assembly files
80 build/source/%.o: ./source/%.S 102 build/source/%.o: ./source/%.S
97 # $(MAKE) --no-print-directory post-build 119 # $(MAKE) --no-print-directory post-build
98 120
99 # Rule for building BeagleRT including the default main file (no user-supplied main()) 121 # Rule for building BeagleRT including the default main file (no user-supplied main())
100 BeagleRT_with_main: $(CORE_OBJS) $(DEFAULT_MAIN_OBJS) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS) 122 BeagleRT_with_main: $(CORE_OBJS) $(DEFAULT_MAIN_OBJS) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS)
101 @echo 'Building target: $@' 123 @echo 'Building target: $@'
102 @echo 'Invoking: GCC C++ Linker' 124 @echo 'Invoking: C++ Linker'
103 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) 125 $(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)
104 126
105 # Rule for building BeagleRT without the default main file (user-supplied main()) 127 # Rule for building BeagleRT without the default main file (user-supplied main())
106 BeagleRT_without_main: $(CORE_OBJS) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS) 128 BeagleRT_without_main: $(CORE_OBJS) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS)
107 @echo 'Building target: $@' 129 @echo 'Building target: $@'
108 @echo 'Invoking: GCC C++ Linker' 130 @echo 'Invoking: C++ Linker'
109 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) 131 $(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)
110 132
111 # Other Targets: 133 # Other Targets:
112 134
113 # Remove the temporary user-supplied source, plus the objects built from them 135 # Remove the temporary user-supplied source, plus the objects built from them
114 sourceclean: 136 sourceclean: