summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Fankhauser (@tux-six)2022-05-30 17:18:05 +0200
committerAndreas Fankhauser (@tux-six)2022-05-30 17:18:05 +0200
commitd2c0bed52d0a293d5541940dedbfe2b5c9afd2c8 (patch)
treee2fc2af51d27d5b0df7ac8c932bd0588bcd8ce5d
parent3f8ac6551aa0f53fd14b216e97e79939635b8b82 (diff)
downloadbulk-ln-0.0.1.zip
bulk-ln-0.0.1.tar.gz
Add 'configure'. Add 'make install'. Format some doc.v0.0.1
-rw-r--r--.gitignore1
-rw-r--r--Makefile26
-rw-r--r--README.txt (renamed from README.md)2
-rwxr-xr-xconfigure55
-rw-r--r--doc/INSTALL.txt14
-rw-r--r--src/bulk_ln/bulk_ln.c12
6 files changed, 96 insertions, 14 deletions
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.txt
index 57904bd..91f2c2f 100644
--- a/README.md
+++ b/README.txt
@@ -6,3 +6,5 @@ BulkLn
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 <path> Default "/usr/local"'
+ echo ' --exec-prefix <path> Default "$(PREFIX)"'
+ echo ' --exec-suffix <path> Default <empty>'
+ echo ' --bindir <path> 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"