X-Git-Url: http://git.nikiroo.be/?p=nikiroo-utils.git;a=blobdiff_plain;f=Makefile.base;h=3143778872e7de4e4f0e25d5afb82443dd860bc4;hp=939658815593b027f05dd2a522a26fdf186327c1;hb=632cc690ac07130a51a947ee0f0b2bfae10b6595;hpb=8afbf87208c7da2278434afab6f98e62815930ef diff --git a/Makefile.base b/Makefile.base index 9396588..3143778 100644 --- a/Makefile.base +++ b/Makefile.base @@ -1,3 +1,8 @@ +# Makefile base template +# +# Version: +# - 1.0.0: add a version comment + # Required parameters (the commented out ones are supposed to change per project): #MAIN = path to main java source to compile @@ -7,9 +12,10 @@ #TEST = path to main test source to compile #JAR_FLAGS += a list of things to pack, each usually prefixed with "-C bin/" #SJAR_FLAGS += a list of things to pack, each usually prefixed with "-C src/", for *-sources.jar files +#TEST_PARAMS = any parameter to pass to the test runnable when "test-run" JAVAC = javac -JAVAC_FLAGS += -encoding UTF-8 -d ./bin/ -cp ./src/ -Xdiags:verbose +JAVAC_FLAGS += -encoding UTF-8 -d ./bin/ -cp ./src/ JAVA = java JAVA_FLAGS += -cp ./bin/ JAR = jar @@ -34,7 +40,7 @@ RJAR_FLAGS += -jar all: build jar -.PHONY: all clean mrproper mrpropre build run jrun jar resources install libs love +.PHONY: all clean mrproper mrpropre build run jrun jar resources test-resources install libs love bin: @mkdir -p bin @@ -50,7 +56,7 @@ build: resources $(JAVAC) $(JAVAC_FLAGS) "src/$$sup.java" ; \ done -test: +test: test-resources @[ -e bin/$(MAIN).class ] || echo You need to build the sources @[ -e bin/$(MAIN).class ] @echo Compiling test program... @@ -63,14 +69,16 @@ test: clean: rm -rf bin/ @echo Removing sources taken from libs... - @for lib in libs/*-sources.jar; do \ - basename "$$lib"; \ - jar tf "$$lib" | while read -r ln; do \ - [ -f "src/$$ln" ] && rm "src/$$ln"; \ - done; \ - jar tf "$$lib" | tac | while read -r ln; do \ - [ -d "src/$$ln" ] && rmdir "src/$$ln" 2>/dev/null || true; \ - done; \ + @for lib in libs/*-sources.jar libs/*-sources.patch.jar; do \ + if [ "$$lib" != 'libs/*-sources.jar' -a "$$lib" != 'libs/*-sources.patch.jar' ]; then \ + basename "$$lib"; \ + jar tf "$$lib" | while read -r ln; do \ + [ -f "src/$$ln" ] && rm "src/$$ln"; \ + done; \ + jar tf "$$lib" | tac | while read -r ln; do \ + [ -d "src/$$ln" ] && rmdir "src/$$ln" 2>/dev/null || true; \ + done; \ + fi \ done mrproper: mrpropre @@ -86,7 +94,18 @@ love: resources: libs @echo Copying resources into bin/... - @cd src && find . | grep -v '\.java$$' | while read -r ln; do \ + @cd src && find . | grep -v '\.java$$' | grep -v '/test/' | while read -r ln; do \ + if [ -f "$$ln" ]; then \ + dir="`dirname "$$ln"`"; \ + mkdir -p "../bin/$$dir" ; \ + cp "$$ln" "../bin/$$ln" ; \ + fi ; \ + done + @cp VERSION bin/ + +test-resources: resources + @echo Copying test resources into bin/... + @cd src && find . | grep -v '\.java$$' | grep '/test/' | while read -r ln; do \ if [ -f "$$ln" ]; then \ dir="`dirname "$$ln"`"; \ mkdir -p "../bin/$$dir" ; \ @@ -96,9 +115,11 @@ resources: libs libs: bin @[ -e bin/libs -o ! -d libs ] || echo Extracting sources from libs... - @[ -e bin/libs -o ! -d libs ] || (cd src && for lib in ../libs/*-sources.jar; do \ - basename "$$lib"; \ - jar xf "$$lib"; \ + @[ -e bin/libs -o ! -d libs ] || (cd src && for lib in ../libs/*-sources.jar ../libs/*-sources.patch.jar; do \ + if [ "$$lib" != '../libs/*-sources.jar' -a "$$lib" != '../libs/*-sources.patch.jar' ]; then \ + basename "$$lib"; \ + jar xf "$$lib"; \ + fi \ done ) @[ ! -d libs ] || touch bin/libs @@ -134,7 +155,7 @@ run-test: @[ "$(TEST)" = "" -o -e "bin/$(TEST).class" ] @echo Running tests for "$(NAME)"... @[ "$(TEST)" != "" ] || echo No test sources defined. - [ "$(TEST)" = "" ] || $(JAVA) $(JAVA_FLAGS) $(TEST) + [ "$(TEST)" = "" ] || ( clear ; $(JAVA) $(JAVA_FLAGS) $(TEST) $(TEST_PARAMS) ) install: @[ -e $(NAME).jar ] || echo You need to build the jar @@ -142,6 +163,6 @@ install: mkdir -p "$(PREFIX)/lib" "$(PREFIX)/bin" cp $(NAME).jar "$(PREFIX)/lib/" echo "#!/bin/sh" > "$(PREFIX)/bin/$(NAME)" - echo "$(RJAR) $(RJAR_FLAGS) \"$(PREFIX)/lib/$(NAME).jar\" \"$$@\"" >> "$(PREFIX)/bin/$(NAME)" + echo "$(RJAR) $(RJAR_FLAGS) \"$(PREFIX)/lib/$(NAME).jar\" \"\$$@\"" >> "$(PREFIX)/bin/$(NAME)" chmod a+rx "$(PREFIX)/bin/$(NAME)"