diff --git a/.gitignore b/.gitignore index 7eacf116..117f66df 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ var build -dist __pycache__ .ref diff --git a/Makefile.in b/Makefile.in index 207a222e..2b9e7472 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1,13 +1,16 @@ PROJECT := ulwgl -OBJDIR ?= build -DESTDIR ?= +OBJDIR := build PREFIX ?= /usr BINDIR := $(PREFIX)/bin LIBDIR := $(PREFIX)/lib DATADIR := $(PREFIX)/share +DESTDIR ?= +USERINSTALL ?= xfalse + + .PHONY: all all: reaper ulwgl ulwgl-launcher @@ -17,6 +20,7 @@ $(OBJDIR)/.build-ulwgl: | $(OBJDIR) sed 's|##INSTALL_PATH##|$(DATADIR)/$(PROJECT)|g' ULWGL/ulwgl-run.in > $(OBJDIR)/ulwgl-run touch $(@) +.PHONY: ulwgl ulwgl: $(OBJDIR)/.build-ulwgl ulwgl-bin-install: ulwgl @@ -45,6 +49,7 @@ $(OBJDIR)/.build-ulwgl-launcher: | $(OBJDIR) sed 's|##INSTALL_PATH##|$(DATADIR)/$(PROJECT)|g' ULWGL/ULWGL-Launcher/ulwgl-run.in > $(OBJDIR)/ulwgl-launcher-run touch $(@) +.PHONY: ulwgl-launcher ulwgl-launcher: $(OBJDIR)/.build-ulwgl-launcher ulwgl-launcher-bin-install: ulwgl-launcher @@ -69,6 +74,7 @@ $(OBJDIR)/.build-reaper: | $(OBJDIR) ninja -C $(OBJDIR)/reaper -v touch $(@) +.PHONY: reaper reaper: $(OBJDIR)/.build-reaper reaper-install: reaper @@ -81,13 +87,22 @@ $(OBJDIR): @mkdir -p $(OBJDIR) +.PHONY: clean clean: rm -rf $(OBJDIR) -.PHONY: install-user -install-user: + +.PHONY: user-install +user-install: + $(info :: ---) + $(info :: Installed under user-only location $(DATADIR)/$(PROJECT)) + $(info :: To run you need to make sure "$(BINDIR)" in your PATH) .PHONY: install +ifeq ($(USERINSTALL), xtrue) +install: reaper-install ulwgl-install ulwgl-launcher-install user-install +else install: reaper-install ulwgl-install ulwgl-launcher-install +endif # vim: ft=make \ No newline at end of file diff --git a/configure.sh b/configure.sh index 7b28064b..da51c775 100755 --- a/configure.sh +++ b/configure.sh @@ -2,8 +2,6 @@ set -eu -SRCDIR="$(dirname "$0")" - # Output helpers COLOR_ERR="" COLOR_STAT="" @@ -50,14 +48,6 @@ function escape_for_make() { } function configure() { - local srcdir - srcdir="$(dirname "$0")" - - if [[ "$srcdir" = "." ]]; then - err "Cannot do a top level in-tree build." - die "Create a subdirectory in build/ or outside of the tree and run configure.sh from there." - fi - ## Write out config # Don't die after this point or we'll have rather unhelpfully deleted the Makefile [[ ! -e "$MAKEFILE" ]] || rm "$MAKEFILE" @@ -66,16 +56,19 @@ function configure() { # Config echo "# Generated by: $THIS_COMMAND" echo "" - echo "SRCDIR := $(escape_for_make "$srcdir")" + if [[ -n "$arg_user_install" ]]; then + echo "USERINSTALL := xtrue" + arg_prefix="$HOME/.local" + fi # Prefix was specified, baking it into the Makefile if [[ -n $arg_prefix ]]; then - echo "PREFIX := $(escape_for_make "$arg_prefix")" + echo "PREFIX := $(escape_for_make "$arg_prefix")" fi # Include base echo "" - echo "include \$(SRCDIR)/Makefile.in" + echo "include Makefile.in" } >> "$MAKEFILE" stat "Created $MAKEFILE, now run make to build." @@ -87,6 +80,7 @@ function configure() { # arg_prefix="" +arg_user_install="" arg_help="" invalid_args="" function parse_args() { @@ -94,6 +88,9 @@ function parse_args() { local val; local val_used; local val_passed; + if [[ $# -eq 0 ]]; then + return 1 + fi while [[ $# -gt 0 ]]; do arg="$1" val='' @@ -121,8 +118,22 @@ function parse_args() { if [[ $arg = --help || $arg = --usage ]]; then arg_help=1 elif [[ $arg = --prefix ]]; then + if [[ -n $arg_user_install ]]; then + err "--prefix cannot be used with --user-install" + exit 1 + fi + if [[ $val != $(realpath "$val") ]]; then + err "PREFIX needs to be an absolute path" + exit 1 + fi arg_prefix="$val" val_used=1 + elif [[ $arg = --user-install ]]; then + if [[ -n $arg_prefix ]]; then + err "--user-install cannot be used with --prefix" + exit 1 + fi + arg_user_install="1" else err "Unrecognized option $arg" return 1 @@ -158,13 +169,16 @@ function parse_args() { usage() { "$1" "Usage: $0 { --prefix=path }" - "$1" " Generate a Makefile for building ULWGL. May be run from another directory to create" - "$1" " out-of-tree build directories (e.g. mkdir mybuild && cd mybuild && ../configure.sh)" + "$1" " Generate a Makefile for building ULWGL" "$1" "" "$1" " Options" - "$1" " --help / --usage Show this help text and exit" + "$1" " --help" + "$1" " --usage Show this help text and exit" + "$1" "" "$1" " --prefix=PREFIX Install architecture-independent files in PREFIX" "$1" " [/usr]" + "$1" " --user-install Install under user-only location" + "$1" " [$HOME/.local]" "$1" "" exit 1; }