From a73a906356c971b080c36368e71a15d87e8b8d31 Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Thu, 6 Jul 2017 07:23:47 +0200 Subject: [PATCH] Change build scripts --- Makefile | 88 -------------------------- Makefile.base | 168 ++++++++++++++++++++++++++++++++++++++++++++++++++ VERSION | 1 + configure.sh | 80 ++++++++++++++++++++++++ 4 files changed, 249 insertions(+), 88 deletions(-) delete mode 100644 Makefile create mode 100644 Makefile.base create mode 100644 VERSION create mode 100755 configure.sh diff --git a/Makefile b/Makefile deleted file mode 100644 index cc5c222..0000000 --- a/Makefile +++ /dev/null @@ -1,88 +0,0 @@ -### -### You can use this Makefile to generate an executable JAR file -### The available options are: -### - make: will create the JAR file (must be compiled before) -### - make bin/5 && make: will create a Java 1.5 JAR -### - make bin/6 && make: will create a Java 1.6 JAR -### - make bin/7 && make: will create a Java 1.7 JAR -### - make bin/8 && make: will create a Java 1.8 JAR -### - make clean: will clean temporary files -### - make mrpropre: will clean temporary files and remove the JAR file - -ALL: jvcard.jar - -bin/bin: bin/be/nikiroo/jvcard/launcher/Main.class src/be/nikiroo/jvcard/*/* src/be/nikiroo/jvcard/* - @echo You need to compile the code first: - @echo " make bin/5: will compile in Java 1.5 target mode" - @echo " make bin/6: will compile in Java 1.6 target mode" - @echo " make bin/7: will compile in Java 1.7 target mode" - @echo " make bin/8: will compile in Java 1.8 target mode" - @false - -.PHONY: ALL clean mrproper mrpropre love - -love: - @echo ...not war? - -clean: - @echo Cleaning files... - @rm -f bin/[0-9] bin/bin bin/files bin/lanterna - -mrproper: mrpropre - -mrpropre: clean - @echo Removing jar files... - @rm -f jvcard.jar jvcard-`grep "APPLICATION_VERSION" src/be/nikiroo/jvcard/launcher/Main.java | head -n1 | cut -d'"' -f2`.jar - -jvcard.jar: bin/bin - @echo 'Main-Class: be.nikiroo.jvcard.launcher.Main' > bin/manifest - @echo >> bin/manifest - @echo Creating jar file jvcard-`grep "APPLICATION_VERSION" src/be/nikiroo/jvcard/launcher/Main.java | head -n1 | cut -d'"' -f2`.jar... - jar cfm jvcard-`grep "APPLICATION_VERSION" src/be/nikiroo/jvcard/launcher/Main.java | head -n1 | cut -d'"' -f2`.jar bin/manifest -C bin/ be -C bin/ com -C bin/ default-theme.properties -C bin/ multilang - @rm bin/manifest - @echo Copying to jvcard.jar... - @cp jvcard-`grep "APPLICATION_VERSION" src/be/nikiroo/jvcard/launcher/Main.java | head -n1 | cut -d'"' -f2`.jar jvcard.jar - -bin/5: bin/lanterna bin/files - @cp -r src/* bin/ - @echo Compiling in Java 1.5 mode "('make bin/5')"... - javac -cp bin/ -encoding UTF-8 -Xlint -Xlint:-options -source 5 -target 5 @bin/files -d bin/ - @rm -f bin/[0-9] - @touch bin/5 - @touch bin/bin - -bin/6: bin/lanterna bin/files - @cp -r src/* bin/ - @echo Compiling in Java 1.6 mode "('make bin/6')"... - javac -cp bin/ -encoding UTF-8 -Xlint -Xlint:-options -source 6 -target 6 @bin/files -d bin/ - @rm -f bin/[0-9] - @touch bin/6 - @touch bin/bin - -bin/7: bin/lanterna bin/files - @cp -r src/* bin/ - @echo Compiling in Java 1.7 mode "('make bin/7')"... - javac -cp bin/ -encoding UTF-8 -Xlint -Xlint:-options -source 7 -target 7 @bin/files -d bin/ - @rm -f bin/[0-9] - @touch bin/7 - @touch bin/bin - -bin/8: bin/lanterna bin/files - @cp -r src/* bin/ - @echo Compiling in Java 1.8 mode "('make bin/8')"... - javac -cp bin/ -encoding UTF-8 -Xlint -Xlint:-options -source 8 -target 8 @bin/files -d bin/ - @rm -f bin/[0-9] - @touch bin/8 - @touch bin/bin - -bin/files: src/be/nikiroo/jvcard/*/* src/be/nikiroo/jvcard/* - @mkdir -p bin/ - @find src/be/ -name '*.java' > bin/files - -bin/lanterna: src/resources/* src/com/googlecode/lanterna/* src/com/googlecode/lanterna/*/* src/com/googlecode/lanterna/*/*/* - @mkdir -p bin/ - @find src/com/ -name '*.java' > bin/lanterna - cp -r src/resources/* bin/ - javac -encoding UTF-8 -source 5 @bin/lanterna -d bin/ || rm bin/lanterna - @test -e bin/lanterna - diff --git a/Makefile.base b/Makefile.base new file mode 100644 index 0000000..3143778 --- /dev/null +++ b/Makefile.base @@ -0,0 +1,168 @@ +# 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 +#MORE = path to supplementary needed resources not linked from MAIN +#NAME = name of project (used for jar output file) +#PREFIX = usually /usr/local (where to install the program) +#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/ +JAVA = java +JAVA_FLAGS += -cp ./bin/ +JAR = jar +RJAR = java +RJAR_FLAGS += -jar + +# Usual options: +# make : to build the jar file +# make libs : to update the libraries into src/ +# make build : to update the binaries (not the jar) +# make test : to update the test binaries +# make build jar : to update the binaries and jar file +# make clean : to clean the directory of intermediate files +# make mrpropre : to clean the directory of all outputs +# make run : to run the program from the binaries +# make run-test : to run the test program from the binaries +# make jrun : to run the program from the jar file +# make install : to install the application into $PREFIX + +# Note: build is actually slower than rebuild in most cases except when +# small changes only are detected ; so we use rebuild by default + +all: build jar + +.PHONY: all clean mrproper mrpropre build run jrun jar resources test-resources install libs love + +bin: + @mkdir -p bin + +jar: $(NAME).jar + +build: resources + @echo Compiling program... + @echo " src/$(MAIN)" + @$(JAVAC) $(JAVAC_FLAGS) "src/$(MAIN).java" + @[ "$(MORE)" = "" ] || for sup in $(MORE); do \ + echo " src/$$sup" ;\ + $(JAVAC) $(JAVAC_FLAGS) "src/$$sup.java" ; \ + done + +test: test-resources + @[ -e bin/$(MAIN).class ] || echo You need to build the sources + @[ -e bin/$(MAIN).class ] + @echo Compiling test program... + @[ "$(TEST)" != "" ] || echo No test sources defined. + @[ "$(TEST)" = "" ] || for sup in $(TEST); do \ + echo " src/$$sup" ;\ + $(JAVAC) $(JAVAC_FLAGS) "src/$$sup.java" ; \ + done + +clean: + rm -rf bin/ + @echo Removing sources taken from libs... + @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 + +mrpropre: clean + rm -f $(NAME).jar + rm -f $(NAME)-sources.jar + [ ! -e VERSION ] || rm -f "$(NAME)-`cat VERSION`.jar" + [ ! -e VERSION ] || rm -f "$(NAME)-`cat VERSION`-sources.jar" + +love: + @echo " ...not war." + +resources: libs + @echo Copying resources into bin/... + @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" ; \ + cp "$$ln" "../bin/$$ln" ; \ + fi ; \ + done + +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 ../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 + +$(NAME).jar: resources + @[ -e bin/$(MAIN).class ] || echo You need to build the sources + @[ -e bin/$(MAIN).class ] + @echo Making JAR file... + @echo > bin/manifest + @[ "$(SJAR_FLAGS)" = "" ] || echo Creating $(NAME)-sources.jar... + @[ "$(SJAR_FLAGS)" = "" ] || $(JAR) cfm $(NAME)-sources.jar bin/manifest $(SJAR_FLAGS) + @[ "$(SJAR_FLAGS)" = "" ] || [ ! -e VERSION ] || echo Copying to "$(NAME)-`cat VERSION`-sources.jar"... + @[ "$(SJAR_FLAGS)" = "" ] || [ ! -e VERSION ] || cp $(NAME)-sources.jar "$(NAME)-`cat VERSION`-sources.jar" + @echo "Main-Class: `echo "$(MAIN)" | sed 's:/:.:g'`" > bin/manifest + @echo >> bin/manifest + $(JAR) cfm $(NAME).jar bin/manifest $(JAR_FLAGS) + @[ ! -e VERSION ] || echo Copying to "$(NAME)-`cat VERSION`.jar"... + @[ ! -e VERSION ] || cp $(NAME).jar "$(NAME)-`cat VERSION`.jar" + +run: + @[ -e bin/$(MAIN).class ] || echo You need to build the sources + @[ -e bin/$(MAIN).class ] + @echo Running "$(NAME)"... + $(JAVA) $(JAVA_FLAGS) $(MAIN) + +jrun: + @[ -e $(NAME).jar ] || echo You need to build the jar + @[ -e $(NAME).jar ] + @echo Running "$(NAME).jar"... + $(RJAR) $(RJAR_FLAGS) $(NAME).jar + +run-test: + @[ "$(TEST)" = "" -o -e "bin/$(TEST).class" ] || echo You need to build the test sources + @[ "$(TEST)" = "" -o -e "bin/$(TEST).class" ] + @echo Running tests for "$(NAME)"... + @[ "$(TEST)" != "" ] || echo No test sources defined. + [ "$(TEST)" = "" ] || ( clear ; $(JAVA) $(JAVA_FLAGS) $(TEST) $(TEST_PARAMS) ) + +install: + @[ -e $(NAME).jar ] || echo You need to build the jar + @[ -e $(NAME).jar ] + 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)" + chmod a+rx "$(PREFIX)/bin/$(NAME)" + diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..336c367 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +1.1.0-dev diff --git a/configure.sh b/configure.sh new file mode 100755 index 0000000..23d713a --- /dev/null +++ b/configure.sh @@ -0,0 +1,80 @@ +#!/bin/sh + +# default: +PREFIX=/usr/local +PROGS="java javac jar make sed" + +TUI=be/nikiroo/jvcard/tui/TuiLauncher +JTUI="-C bin/ com -C bin/ resources" + +NET="be/nikiroo/jvcard/remote/Server be/nikiroo/jvcard/remote/Sync" +JNET= + +valid=true +while [ "$*" != "" ]; do + key=`echo "$1" | cut -f1 -d=` + val=`echo "$1" | cut -f2 -d=` + case "$key" in + --) + ;; + --help) # This help message + echo The following arguments can be used: + cat "$0" | grep '^\s*--' | grep '#' | while read ln; do + cmd=`echo "$ln" | cut -f1 -d')'` + msg=`echo "$ln" | cut -f2 -d'#'` + echo " $cmd$msg" + done + ;; + --prefix) #=PATH Change the prefix to the given path + PREFIX="$val" + ;; + --net) #=no Disable server and sync support + [ "$val" = no -o "$val" = false ] && NET= && JNET= + ;; + --tui) #=no Disable TUI support (Lanterna) + [ "$val" = no -o "$val" = false ] && TUI= && JTUI= + ;; + *) + echo "Unsupported parameter: '$1'" >&2 + echo >&2 + sh "$0" --help >&2 + valid=false + ;; + esac + shift +done + +[ $valid = false ] && exit 1 + +MESS="A required program cannot be found:" +for prog in $PROGS; do + out="`whereis -b "$prog" 2>/dev/null`" + if [ "$out" = "$prog:" ]; then + echo "$MESS $prog" >&2 + valid=false + fi +done + +[ $valid = false ] && exit 2 + +if [ "`whereis tput`" = "tput:" ]; then + ok='"[ ok ]"'; + ko='"[ !! ]"'; + cols=80; +else + ok='"`tput bold`[`tput setf 2` OK `tput init``tput bold`]`tput init`"'; + ko='"`tput bold`[`tput setf 4` !! `tput init``tput bold`]`tput init`"'; + cols='"`tput cols`"'; +fi; + +echo "MAIN = be/nikiroo/jvcard/launcher/Main" > Makefile +echo "MORE = $NET $TUI" >> Makefile +echo "TEST = " >> Makefile +echo "TEST_PARAMS = $cols $ok $ko" >> Makefile +echo "NAME = jvcard" >> Makefile +echo "PREFIX = $PREFIX" >> Makefile +echo "JAR_FLAGS += $JNET $JTUI -C bin/ be -C bin/ VERSION" >> Makefile +#echo "SJAR_FLAGS += -C src/ com -C src/ be -C ./ LICENSE -C ./ README.md -C ./ VERSION" >> Makefile + +cat Makefile.base >> Makefile + -- 2.27.0