From d2c0bed52d0a293d5541940dedbfe2b5c9afd2c8 Mon Sep 17 00:00:00 2001 From: Andreas Fankhauser (@tux-six) Date: Mon, 30 May 2022 17:18:05 +0200 Subject: Add 'configure'. Add 'make install'. Format some doc. --- .gitignore | 1 + Makefile | 26 ++++++++++++++++-------- README.md | 8 -------- README.txt | 10 ++++++++++ configure | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++ doc/INSTALL.txt | 14 +++++++++++++ src/bulk_ln/bulk_ln.c | 12 +++++------ 7 files changed, 104 insertions(+), 22 deletions(-) delete mode 100644 README.md create mode 100644 README.txt create mode 100755 configure create mode 100644 doc/INSTALL.txt diff --git a/.gitignore b/.gitignore index 796b96d..2247d5f 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /build +/dist diff --git a/Makefile b/Makefile index f3abfb7..86b113f 100644 --- a/Makefile +++ b/Makefile @@ -1,17 +1,21 @@ CC=gcc -LD=ld -AR=ar TAR=tar -BINEXT= +MKDIRS=mkdir -p TOOLS=lxGcc64 +# See "./configure" +PREFIX=/usr/local +EXEC_PREFIX=$(PREFIX) +EXEC_SUFFIX= +BINDIR=$(EXEC_PREFIX)/bin + ifndef PROJECT_VERSION # We just provide a primitive version string so we can see which build # we're using while debugging. For a release we will override the version # by providing it from cli args to 'make' as in: # make clean package PROJECT_VERSION=1.2.3 - PROJECT_VERSION=$(shell date +0.0.0-%Y%m%d.%H%M%S) + PROJECT_VERSION=$(shell date -u +0.0.0-%Y%m%d.%H%M%S) endif CFLAGS= --std=c99 \ @@ -44,14 +48,14 @@ clean: rm -rf build dist .PHONY: link -link: build/bin/bulk-ln$(BINEXT) +link: build/bin/bulk-ln$(EXEC_SUFFIX) build/obj/%.o: src/%.c @echo "\n[INFO ] Compile '$@'" @mkdir -p $(shell dirname build/obj/$*) $(CC) -c -o $@ $< $(CFLAGS) $(INCDIRS) -build/bin/bulk-ln$(BINEXT): \ +build/bin/bulk-ln$(EXEC_SUFFIX): \ build/obj/bulk_ln/bulk_ln.o \ build/obj/bulk_ln/bulk_ln_main.o @echo "\n[INFO ] Link '$@'" @@ -64,14 +68,14 @@ package: link @rm -rf build/dist-* dist @mkdir dist @echo - @bash -c 'if [[ -n `git status --porcelain` ]]; then echo "[ERROR] Worktree not clean as it should be (see: git status)"; exit 1; fi' + @bash -c 'if [[ -n `git status --porcelain` ]]; then echo "[WARN ] Worktree not clean!"; sleep 3; fi' @# Create Executable bundle. @rm -rf build/dist-bin && mkdir -p build/dist-bin @cp -t build/dist-bin \ README* @mkdir build/dist-bin/bin @cp -t build/dist-bin/bin \ - build/bin/*$(BINEXT) + build/bin/*$(EXEC_SUFFIX) @(cd build/dist-bin && find . -type f -not -name MD5SUM -exec md5sum -b {} \;) > build/MD5SUM @mv build/MD5SUM build/dist-bin/. @(cd build/dist-bin && $(TAR) --owner=0 --group=0 -czf ../../dist/BulkLn-$(PROJECT_VERSION)-$(TOOLS).tgz *) @@ -79,3 +83,9 @@ package: link @echo @echo See './dist/' for result. +.PHONY: install +install: + @$(MKDIRS) "$(BINDIR)" + $(TAR) -f "$(shell ls dist/BulkLn-*-$(TOOLS).tgz)" \ + -C "$(BINDIR)" --strip-components=1 -x bin + diff --git a/README.md b/README.md deleted file mode 100644 index 57904bd..0000000 --- a/README.md +++ /dev/null @@ -1,8 +0,0 @@ - -BulkLn -====== - -'ln' like tool to handle large amount of links. - -Usage: bulk-ln --help - diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..91f2c2f --- /dev/null +++ b/README.txt @@ -0,0 +1,10 @@ + +BulkLn +====== + +'ln' like tool to handle large amount of links. + +Usage: bulk-ln --help + +Build: "doc/INSTALL.txt" + diff --git a/configure b/configure new file mode 100755 index 0000000..fea5aeb --- /dev/null +++ b/configure @@ -0,0 +1,55 @@ +#!/usr/bin/env sh +set -e + +# See https://www.gnu.org/prep/standards/html_node/Directory-Variables.html +prefix=/usr/local +exec_prefix='$(PREFIX)' +exec_suffix= +bindir='$(EXEC_PREFIX)/bin' + + +main() { + parseArgs "$@" + mangleMakefile +} + + +printHelp() { + echo '' + echo "Example usage: $0 --prefix /usr/local" + echo '' + echo 'Options:' + echo ' --prefix Default "/usr/local"' + echo ' --exec-prefix Default "$(PREFIX)"' + echo ' --exec-suffix Default ' + echo ' --bindir Default "$(EXEC_PREFIX)/bin"' + echo '' +} + + +parseArgs() { + # See: https://stackoverflow.com/a/14203146/4415884 + while test $# -gt 0 ; do + case $1 in + --help) printHelp; exit 1; ;; + --prefix) prefix="$2" shift; shift; ;; + --exec-prefix) exec_prefix="$2" shift; shift; ;; + --exec-suffix) exec_suffix="$2" shift; shift; ;; + --bindir) bindir="$2" shift; shift; ;; + *) echo "[ERROR] Unexpected argument: $1"; exit 1 ;; + esac + done +} + + +mangleMakefile() { + sed -i 's;^PREFIX=.*$;PREFIX='"$prefix"';' Makefile + sed -i 's;^EXEC_PREFIX=.*$;EXEC_PREFIX='"$exec_prefix"';' Makefile + sed -i 's;^EXEC_SUFFIX=.*$;EXEC_SUFFIX='"$exec_suffix"';' Makefile + sed -i 's;^BINDIR=.*$;BINDIR='"$bindir"';' Makefile +} + + +main "$@" + + diff --git a/doc/INSTALL.txt b/doc/INSTALL.txt new file mode 100644 index 0000000..68ebc59 --- /dev/null +++ b/doc/INSTALL.txt @@ -0,0 +1,14 @@ + +How to build/install +==================== + +Use the well-known procedure: + + ./configure + make + make install + +You can get some help with: + + ./configure --help + diff --git a/src/bulk_ln/bulk_ln.c b/src/bulk_ln/bulk_ln.c index 7c7e98a..6d6b6a3 100644 --- a/src/bulk_ln/bulk_ln.c +++ b/src/bulk_ln/bulk_ln.c @@ -64,9 +64,9 @@ struct BulkLn { void printHelp(){ printf("\n %s%s\n", strrchr(__FILE__, '/') + 1, " @ " STR_QUOT(PROJECT_VERSION) "\n" "\n" - "Utility to create links. Writing a custom implementation of 'ln'\n" - "got necessary as we found no way to instruct 'ln' to create a few thousand\n" - "links in an acceptable amount of time. So we just wrote our own ;)\n" + "Utility to create links. Writing a custom implementation of 'ln' got necessary\n" + "as we found no way to instruct 'ln' to create a few thousand links in an\n" + "acceptable amount of time. So we just wrote our own ;)\n" "\n" "Takes paths (pairwise) from stdin (see --stdin for details) and creates a\n" "hardlink for each pair from the 1st path to the 2nd.\n" @@ -95,9 +95,9 @@ void printHelp(){ "\n" " --dry-run\n" " Will print the actions to stdout instead executing them.\n" - " HINT: The directory count in the summary will be implicitly set to zero,\n" - " as our used counting strategy would deliver wrong results when we not\n" - " actually creating the dirs.\n" + " HINT: The directory count in the summary will be implicitly set to\n" + " zero, as our used counting strategy would deliver wrong results when we\n" + " not actually creating the dirs.\n" "\n" " --force\n" " Same meaning as in original 'ln' command.\n" -- cgit v1.1