Skip to content

Commit

Permalink
Clean configure.sh and add --user-install option
Browse files Browse the repository at this point in the history
  • Loading branch information
loathingKernel committed Feb 28, 2024
1 parent f0d6750 commit 5dd681c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 21 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var
build
dist
__pycache__
.ref
23 changes: 19 additions & 4 deletions Makefile.in
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -69,6 +74,7 @@ $(OBJDIR)/.build-reaper: | $(OBJDIR)
ninja -C $(OBJDIR)/reaper -v
touch $(@)

.PHONY: reaper
reaper: $(OBJDIR)/.build-reaper

reaper-install: reaper
Expand All @@ -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
46 changes: 30 additions & 16 deletions configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

set -eu

SRCDIR="$(dirname "$0")"

# Output helpers
COLOR_ERR=""
COLOR_STAT=""
Expand Down Expand Up @@ -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"
Expand All @@ -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."
Expand All @@ -87,13 +80,17 @@ function configure() {
#

arg_prefix=""
arg_user_install=""
arg_help=""
invalid_args=""
function parse_args() {
local arg;
local val;
local val_used;
local val_passed;
if [[ $# -eq 0 ]]; then
return 1
fi
while [[ $# -gt 0 ]]; do
arg="$1"
val=''
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 5dd681c

Please sign in to comment.