From 78c1c6ec780fdfad17107e957e86a8d31719269b Mon Sep 17 00:00:00 2001 From: Sven Nilsen Date: Wed, 25 Jun 2014 15:19:33 +0200 Subject: [PATCH] Upgraded to latest Rust-Empty --- rust-empty.mk | 200 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 163 insertions(+), 37 deletions(-) diff --git a/rust-empty.mk b/rust-empty.mk index d2d05d99..a64e3bd2 100644 --- a/rust-empty.mk +++ b/rust-empty.mk @@ -93,37 +93,38 @@ endif all: $(DEFAULT) help: - $(Q)echo "--- rust-empty (0.5 000)" \ - && echo "make run - Runs executable" \ - && echo "make exe - Builds main executable" \ - && echo "make lib - Both static and dynamic library" \ - && echo "make rlib - Static library" \ - && echo "make dylib - Dynamic library" \ - && echo "make test - Tests library internally and externally" \ - && echo "make test-internal - Tests library internally" \ - && echo "make test-external - Tests library externally" \ - && echo "make bench - Benchmarks library internally and externally" \ - && echo "make bench-internal - Benchmarks library internally" \ - && echo "make bench-external - Benchmarks library externally" \ - && echo "make doc - Builds documentation for library" \ - && echo "make git-ignore - Setup files to be ignored by Git" \ - && echo "make examples - Builds examples" \ - && echo "make cargo-lite-exe - Setup executable package" \ - && echo "make cargo-lite-lib - Setup library package" \ - && echo "make cargo-exe - EXPERIMENTAL: Setup executable package" \ - && echo "make cargo-lib - EXPERIMENTAL: Setup library package" \ - && echo "make rust-ci-lib - Setup Travis CI Rust library" \ - && echo "make rust-ci-exe - Setup Travis CI Rust executable" \ - && echo "make rusti - Setup 'rusti.sh' for interactive Rust" \ - && echo "make watch - Setup 'watch.sh' for compilation on save" \ - && echo "make loc - Count lines of code in src folder" \ - && echo "make nightly-install - Installs Rust nightly built" \ - && echo "make nightly-uninstall - Uninstalls Rust nightly built" \ - && echo "make clean - Deletes binaries and documentation." \ - && echo "make clear-project - WARNING: Deletes project files except 'Makefile'" \ - && echo "make clear-git - WARNING: Deletes Git setup" \ - && echo "make symlink-info - Symlinked libraries dependency info" \ - && echo "make target-dir - Creates directory for current target" + $(Q)echo "--- rust-empty (0.5 006)" + $(Q)echo "make run - Runs executable" + $(Q)echo "make exe - Builds main executable" + $(Q)echo "make lib - Both static and dynamic library" + $(Q)echo "make rlib - Static library" + $(Q)echo "make dylib - Dynamic library" + $(Q)echo "make test - Tests library internally and externally" + $(Q)echo "make test-internal - Tests library internally" + $(Q)echo "make test-external - Tests library externally" + $(Q)echo "make bench - Benchmarks library internally and externally" + $(Q)echo "make bench-internal - Benchmarks library internally" + $(Q)echo "make bench-external - Benchmarks library externally" + $(Q)echo "make doc - Builds documentation for library" + $(Q)echo "make git-ignore - Setup files to be ignored by Git" + $(Q)echo "make examples - Builds examples" + $(Q)echo "make cargo-lite-exe - Setup executable package" + $(Q)echo "make cargo-lite-lib - Setup library package" + $(Q)echo "make cargo-exe - EXPERIMENTAL: Setup executable package" + $(Q)echo "make cargo-lib - EXPERIMENTAL: Setup library package" + $(Q)echo "make rust-ci-lib - Setup Travis CI Rust library" + $(Q)echo "make rust-ci-exe - Setup Travis CI Rust executable" + $(Q)echo "make rusti - Setup 'rusti.sh' for interactive Rust" + $(Q)echo "make watch - Setup 'watch.sh' for compilation on save" + $(Q)echo "make loc - Count lines of code in src folder" + $(Q)echo "make nightly-install - Installs Rust nightly build" + $(Q)echo "make nightly-uninstall - Uninstalls Rust nightly build" + $(Q)echo "make clean - Deletes binaries and documentation." + $(Q)echo "make clear-project - WARNING: Deletes project files except 'Makefile'" + $(Q)echo "make clear-git - WARNING: Deletes Git setup" + $(Q)echo "make symlink-build - Creates a script for building dependencies + $(Q)echo "make symlink-info - Symlinked libraries dependency info" + $(Q)echo "make target-dir - Creates directory for current target" .PHONY: \ bench \ @@ -143,6 +144,7 @@ help: rusti \ rust-ci-lib \ rust-ci-exe \ + symlink-build \ symlink-info \ target-dir \ test \ @@ -209,7 +211,7 @@ cargo-exe: $(EXE_ENTRY_FILE) ( \ name=$${PWD##/*/} ; \ readme=$$((test -e README.md && echo -e "readme = \"README.md\"") || ("")) ; \ - echo -e "[project]\n\nname = \"$$name\"\nversion = \"0.0\"\n$$readme\nauthors = [\"Your Name \"]\ntags = []\n\n[[bin]]\n\nname = \"$$name\"\npath = \"$(EXE_ENTRY_FILE)\"\n" > Cargo.toml \ + echo -e "[package]\n\nname = \"$$name\"\nversion = \"0.0\"\n$$readme\nauthors = [\"Your Name \"]\ntags = []\n\n[[bin]]\n\nname = \"$$name\"\npath = \"$(EXE_ENTRY_FILE)\"\n" > Cargo.toml \ && echo "--- Created 'Cargo.toml' for executable" \ && cat Cargo.toml \ ) @@ -223,7 +225,7 @@ cargo-lib: $(EXE_ENTRY_FILE) ( \ name=$${PWD##/*/} ; \ readme=$$((test -e README.md && echo -e "readme = \"README.md\"") || ("")) ; \ - echo -e "[project]\n\nname = \"$$name\"\nversion = \"0.0\"\n$$readme\nauthors = [\"Your Name \"]\ntags = []\n\n[[lib]]\n\nname = \"$$name\"\npath = \"$(LIB_ENTRY_FILE)\"\n" > Cargo.toml \ + echo -e "[package]\n\nname = \"$$name\"\nversion = \"0.0\"\n$$readme\nauthors = [\"Your Name \"]\ntags = []\n\n[[lib]]\n\nname = \"$$name\"\npath = \"$(LIB_ENTRY_FILE)\"\n" > Cargo.toml \ && echo "--- Created 'Cargo.toml' for executable" \ && cat Cargo.toml \ ) @@ -349,7 +351,7 @@ examples: $(EXAMPLE_FILES) $(EXAMPLE_FILES): lib examples-dir $(Q)$(COMPILER) --target "$(TARGET)" $(COMPILER_FLAGS) $@ -L "target/$(TARGET)/lib" --out-dir examples/ \ - && echo "--- Built examples" + && echo "--- Built '$@' (make $@)" $(EXE_ENTRY_FILE): | src/ $(Q)test -e $(EXE_ENTRY_FILE) \ @@ -479,15 +481,22 @@ define WATCH_SCRIPT # Watch files in infinite loop watch () { + UNAME=$$(uname) if [ -e "$$2" ]; then echo "Watching files in $$2.." - CTIME=$$(date -j -f "%a %b %d %T %Z %Y" "`date`" "+%s") + CTIME=$$(date "+%s") while :; do sleep 1 for f in `find $$2 -type f -name "*.rs"`; do - eval $$(stat -s $$f) + if [[ $$UNAME == "Darwin" ]]; then + st_mtime=$$(stat -f "%m" "$$f") + elif [[ $$UNAME == "FreeBSD" ]]; then + st_mtime=$$(stat -f "%m" "$$f") + else + st_mtime=$$(stat -c "%Y" "$$f") + fi if [ $$st_mtime -gt $$CTIME ]; then - CTIME=$$(date -j -f "%a %b %d %T %Z %Y" "`date`" "+%s") + CTIME=$$(date "+%s") echo "~~~ Rebuilding" $$1 if [ ! $$? -eq 0 ]; then @@ -541,6 +550,123 @@ watch: $(TARGET_LIB_DIR) && echo "--- Type './watch.sh -h' for more options" \ ) +# borrowed from http://stackoverflow.com/q/649246/1256624 +define SYMLINK_BUILD_SCRIPT +#!/bin/bash +# written by bvssvni +# Modify the setting to do conditional compilation. +# For example "--cfg my_feature" +SETTINGS="" +# ================================================ + +MAKE=make +if [ "$$OS" == "Windows_NT" ]; then + MAKE=mingw32-make +fi + +# Checks if an item exists in an array. +# Copied from http://stackoverflow.com/questions/3685970/check-if-an-array-contains-a-value +function contains() { + local n=$$# + local value=$${!n} + for ((i=1;i < $$#;i++)) { + if [ "$${!i}" == "$${value}" ]; then + echo "y" + return 0 + fi + } + echo "n" + return 1 +} + +# This is a counter used to insert dependencies. +# It is global because we need an array of all the +# visited dependencies. +i=0 +function build_deps { + local current=$$(pwd) + for symlib in $$(find target/*/lib -type l) ; do + cd $$current + echo $$symlib + local original_file=$$(readlink $$symlib) + local original_dir=$$(dirname $$original_file) + cd $$original_dir + + # Go to the git root directory. + local current_git_dir=$$(git rev-parse --show-toplevel) + echo "--- Parent $$current" + echo "--- Child $$current_git_dir" + cd $$current_git_dir + + # Skip building if it is already built. + if [ $$(contains "$${git_dir[@]}" $$current_git_dir) == "y" ]; then + echo "--- Visited $$current_git_dir" + continue + fi + + # Remember git directory to not build it twice + git_dir[i]=$$current_git_dir + + # Visit the symlinks and build the dependencies + build_deps + + # First check for a 'build.sh' script with default settings. + # Check for additional 'rust-empty.mk' file. \ + # Compile with the settings flags. \ + # If no other options, build with make. + ( \ + test -e build.sh \ + && ./build.sh \ + ) \ + || \ + ( \ + test -e rust-empty.mk \ + && $$MAKE -f rust-empty.mk clean \ + && $$MAKE -f rust-empty.mk \ + ) \ + || \ + ( \ + echo "--- Building $$current_git_dir" \ + && $$MAKE clean \ + && $$MAKE \ + ) + let i+=1 + done + cd $$current +} + +if [ "$$1" == "deps" ]; then + build_deps +fi + +echo "--- Building $$(pwd)" +( \ + test -e rust-empty.mk \ + && $$MAKE -f rust-empty.mk clean \ + && $$MAKE -f rust-empty.mk COMPILER_FLAGS+="$$SETTINGS" \ +) \ +|| \ +( \ + $$MAKE clean + $$MAKE COMPILER_FLAGS+="$$SETTINGS" +) + +endef +export SYMLINK_BUILD_SCRIPT + +symlink-build: + $(Q)( \ + test -e build.sh \ + && echo "--- The file 'build.sh' already exists" \ + ) \ + || \ + ( \ + echo -e "$$SYMLINK_BUILD_SCRIPT" > build.sh \ + && chmod +x build.sh \ + && echo "--- Created 'build.sh'" \ + && echo "--- Type './build.sh deps' to build everything" \ + ) + loc: $(Q)echo "--- Counting lines of .rs files in 'src' (LOC):" \ && find src/ -type f -name "*.rs" -exec cat {} \; | wc -l