Mercurial > hg > beaglert
comparison Makefile @ 287:4815ed0f21de prerelease
Makefile refactoring:
- avoids recursive call to build with/without main
- takes EXAMPLE parameter. Copies the examples/$(EXAMPLE) folder to projects/$(PROJECT) and $PROJECT defaults to exampleTestProject
- you can now `make run` (TODO: currently re-links, should instead run without linking)
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Wed, 18 May 2016 01:46:32 +0100 |
parents | 247a182adb6d |
children | e63d35c6ae96 |
comparison
equal
deleted
inserted
replaced
286:8fecfcbaf2f0 | 287:4815ed0f21de |
---|---|
9 # set the project to be compiled by calling: make all PROJECT=<project_name> | 9 # set the project to be compiled by calling: make all PROJECT=<project_name> |
10 | 10 |
11 # if the PROJECT variable is not set, throw an error and exit | 11 # if the PROJECT variable is not set, throw an error and exit |
12 # otherwise, we could have unexpected data loss when calling clean without it | 12 # otherwise, we could have unexpected data loss when calling clean without it |
13 ifndef PROJECT | 13 ifndef PROJECT |
14 $(error PROJECT is not set) | 14 ifndef EXAMPLE |
15 $(error PROJECT or EXAMPLE should be set) | |
16 endif | |
15 endif | 17 endif |
16 | 18 |
17 PROJECT_DIR := $(abspath projects/$(PROJECT)) | 19 ifndef EXAMPLE |
20 PROJECT_DIR := $(abspath projects/$(PROJECT)) | |
21 endif | |
22 | |
23 ifdef EXAMPLE | |
24 PROJECT?=exampleTempProject | |
25 PROJECT_DIR?=$(abspath projects/$(PROJECT)) | |
26 $(shell rm -rf $(PROJECT_DIR)) | |
27 $(shell cp -r examples/$(EXAMPLE) $(PROJECT_DIR)) | |
28 EXAMPLE:=that | |
29 endif | |
30 | |
18 $(shell mkdir -p $(PROJECT_DIR)/build) | 31 $(shell mkdir -p $(PROJECT_DIR)/build) |
19 RM := rm -rf | 32 RM := rm -rf |
20 STATIC_LIBS := ./libprussdrv.a ./libNE10.a | 33 STATIC_LIBS := ./libprussdrv.a ./libNE10.a |
21 LIBS := -lrt -lnative -lxenomai -lsndfile | 34 LIBS := -lrt -lnative -lxenomai -lsndfile |
22 | 35 |
110 | 123 |
111 # Rule for user-supplied C files | 124 # Rule for user-supplied C files |
112 $(PROJECT_DIR)/build/%.o: $(PROJECT_DIR)/%.c | 125 $(PROJECT_DIR)/build/%.o: $(PROJECT_DIR)/%.c |
113 @echo 'Building $(notdir $<)...' | 126 @echo 'Building $(notdir $<)...' |
114 # @echo 'Invoking: C Compiler' | 127 # @echo 'Invoking: C Compiler' |
115 @$(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 | 128 $(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 |
116 @echo ' ...done' | 129 @echo ' ...done' |
117 @echo ' ' | 130 @echo ' ' |
118 | 131 |
119 # Rule for user-supplied assembly files | 132 # Rule for user-supplied assembly files |
120 $(PROJECT_DIR)/build/%.o: $(PROJECT_DIR)/%.S | 133 $(PROJECT_DIR)/build/%.o: $(PROJECT_DIR)/%.S |
127 # This is a nasty kludge: we want to be able to optionally link in a default | 140 # This is a nasty kludge: we want to be able to optionally link in a default |
128 # main file if the user hasn't supplied one. We check for the presence of the main() | 141 # main file if the user hasn't supplied one. We check for the presence of the main() |
129 # function, and conditionally call one of two recursive make targets depending on whether | 142 # function, and conditionally call one of two recursive make targets depending on whether |
130 # we want to link in the default main file or not. The kludge is the mess of a shell script | 143 # we want to link in the default main file or not. The kludge is the mess of a shell script |
131 # line below. Surely there's a better way to do this? | 144 # line below. Surely there's a better way to do this? |
132 BeagleRT: $(CORE_OBJS) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS) | 145 BeagleRT: $(CORE_OBJS) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS) $(DEFAULT_MAIN_OBJS) |
133 $(eval NEXT_TARGET := $(shell bash -c 'if [ `nm $(PROJECT_DIR)/build/*.o | grep -w T | grep -w main | wc -l` == '0' ]; then echo "BeagleRT_with_main"; else echo "BeagleRT_without_main"; fi')) | 146 $(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')) |
134 @$(MAKE) $(NEXT_TARGET) | 147 @echo 'Invoking: C++ linker' |
135 # @echo 'Finished building target: $@' | 148 @$(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) |
136 # @echo ' ' | 149 @echo 'Finished building target: $@' |
137 # $(MAKE) --no-print-directory post-build | |
138 | 150 |
139 # Rule for building BeagleRT including the default main file (no user-supplied main()) | |
140 BeagleRT_with_main: $(CORE_OBJS) $(DEFAULT_MAIN_OBJS) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS) | |
141 @echo 'Linking default main.cpp...' | |
142 # @echo 'Invoking: C++ Linker' | |
143 @$(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_OBJS) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS) $(LIBS) | |
144 @echo ' ...done' | |
145 | |
146 # Rule for building BeagleRT without the default main file (user-supplied main()) | |
147 BeagleRT_without_main: $(CORE_OBJS) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS) | |
148 @echo 'Linking main.cpp from project...' | |
149 # @echo 'Invoking: C++ Linker' | |
150 @$(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) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS) $(LIBS) | |
151 @echo ' ...done' | |
152 | |
153 # Other Targets: | 151 # Other Targets: |
154 # This rule compiles c and c++ source files without output or linking | 152 # This rule compiles c and c++ source files without output or linking |
155 SYNTAX: $(C_OBJS) $(CPP_OBJS) | 153 SYNTAX: $(C_OBJS) $(CPP_OBJS) |
156 | 154 |
157 # Remove the project's build objects & binary | 155 # Remove the project's build objects & binary |
161 | 159 |
162 # Remove all the built objects, including the core BeagleRT objects | 160 # Remove all the built objects, including the core BeagleRT objects |
163 distclean: | 161 distclean: |
164 -$(RM) build/source/* $(CORE_OBJS) $(CORE_CPP_DEPS) $(DEFAULT_MAIN_OBJS) $(DEFAULT_MAIN_CPP_DEPS) BeagleRT | 162 -$(RM) build/source/* $(CORE_OBJS) $(CORE_CPP_DEPS) $(DEFAULT_MAIN_OBJS) $(DEFAULT_MAIN_CPP_DEPS) BeagleRT |
165 -@echo ' ' | 163 -@echo ' ' |
164 OUTPUT_FILE="$(PROJECT_DIR)/$(PROJECT)" | |
166 | 165 |
166 $(OUTPUT_FILE): BeagleRT | |
167 run: $(OUTPUT_FILE) | |
168 @echo "Running $(OUTPUT_FILE)" | |
169 @$(OUTPUT_FILE) | |
170 | |
171 | |
167 # Remove only the user-generated objects | 172 # Remove only the user-generated objects |
168 #clean: | 173 #clean: |
169 # -$(RM) build/source/* BeagleRT | 174 # -$(RM) build/source/* BeagleRT |
170 # -@echo ' ' | 175 # -@echo ' ' |
171 | 176 |
172 post-build: | 177 post-build: |
173 # Nothing to do here (for now) | 178 # Nothing to do here (for now) |
174 | 179 |
175 .PHONY: all clean distclean projectclean dependents debug | 180 .PHONY: all clean distclean projectclean dependents debug run |
176 .SECONDARY: post-build | 181 .SECONDARY: post-build |