Mercurial > hg > beaglert
changeset 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 | 8fecfcbaf2f0 |
children | 771a0920c626 |
files | Makefile |
diffstat | 1 files changed, 29 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/Makefile Tue May 17 18:16:26 2016 +0100 +++ b/Makefile Wed May 18 01:46:32 2016 +0100 @@ -11,10 +11,23 @@ # if the PROJECT variable is not set, throw an error and exit # otherwise, we could have unexpected data loss when calling clean without it ifndef PROJECT - $(error PROJECT is not set) + ifndef EXAMPLE + $(error PROJECT or EXAMPLE should be set) + endif endif -PROJECT_DIR := $(abspath projects/$(PROJECT)) +ifndef EXAMPLE + PROJECT_DIR := $(abspath projects/$(PROJECT)) +endif + +ifdef EXAMPLE + PROJECT?=exampleTempProject + PROJECT_DIR?=$(abspath projects/$(PROJECT)) + $(shell rm -rf $(PROJECT_DIR)) + $(shell cp -r examples/$(EXAMPLE) $(PROJECT_DIR)) + EXAMPLE:=that +endif + $(shell mkdir -p $(PROJECT_DIR)/build) RM := rm -rf STATIC_LIBS := ./libprussdrv.a ./libNE10.a @@ -112,7 +125,7 @@ $(PROJECT_DIR)/build/%.o: $(PROJECT_DIR)/%.c @echo 'Building $(notdir $<)...' # @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 + $(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 ' ...done' @echo ' ' @@ -129,27 +142,12 @@ # function, and conditionally call one of two recursive make targets depending on whether # we want to link in the default main file or not. The kludge is the mess of a shell script # line below. Surely there's a better way to do this? -BeagleRT: $(CORE_OBJS) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS) - $(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')) - @$(MAKE) $(NEXT_TARGET) -# @echo 'Finished building target: $@' -# @echo ' ' -# $(MAKE) --no-print-directory post-build +BeagleRT: $(CORE_OBJS) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS) $(DEFAULT_MAIN_OBJS) + $(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')) + @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 "$(PROJECT_DIR)/$(PROJECT)" $(CORE_OBJS) $(DEFAULT_MAIN_CONDITIONAL) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS) $(LIBS) + @echo 'Finished building target: $@' -# 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 'Linking default main.cpp...' -# @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 "$(PROJECT_DIR)/$(PROJECT)" $(CORE_OBJS) $(DEFAULT_MAIN_OBJS) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS) $(LIBS) - @echo ' ...done' - -# 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 'Linking main.cpp from project...' -# @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 "$(PROJECT_DIR)/$(PROJECT)" $(CORE_OBJS) $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS) $(STATIC_LIBS) $(LIBS) - @echo ' ...done' - # Other Targets: # This rule compiles c and c++ source files without output or linking SYNTAX: $(C_OBJS) $(CPP_OBJS) @@ -163,7 +161,14 @@ distclean: -$(RM) build/source/* $(CORE_OBJS) $(CORE_CPP_DEPS) $(DEFAULT_MAIN_OBJS) $(DEFAULT_MAIN_CPP_DEPS) BeagleRT -@echo ' ' +OUTPUT_FILE="$(PROJECT_DIR)/$(PROJECT)" +$(OUTPUT_FILE): BeagleRT +run: $(OUTPUT_FILE) + @echo "Running $(OUTPUT_FILE)" + @$(OUTPUT_FILE) + + # Remove only the user-generated objects #clean: # -$(RM) build/source/* BeagleRT @@ -172,5 +177,5 @@ post-build: # Nothing to do here (for now) -.PHONY: all clean distclean projectclean dependents debug +.PHONY: all clean distclean projectclean dependents debug run .SECONDARY: post-build