configure (3152B)
- #!/bin/sh
- # SPDX-FileCopyrightText: 2023 Haelwenn (lanodan) Monnier <contact+ultrasharp@hacktivis.me>
- # SPDX-License-Identifier: BSD-3-Clause
- set -e
- usage() {
- cat <<'END'
- Usage: [variables] configure [variables]
- Variables:
- PREFIX=DIR
- DATADIR=DIR
- ICONDIR=DIR
- QUOTER=BIN
- XCURSORGEN=BIN
- Variables are set in the following order: Default, Environment, Arguments
- Dependencies: See README.md
- END
- }
- is_ok() {
- status="$?"
- if test $status -eq 0; then
- printf ' OK\n'
- else
- printf ' FAIL\n'
- fi
- return $status
- }
- required() {
- is_ok || exit 1
- }
- # defaults
- PREFIX="${PREFIX:-/usr/local}"
- XCURSORGEN="${XCURSORGEN:-xcursorgen}"
- QUOTER="${QUOTER:-quoter}"
- MAGICK="${MAGICK:-magick}"
- printf 'Checking %s command existance ...' "${QUOTER}"
- command -v "${QUOTER}" >/dev/null ; required
- arg0="$0"
- args="$("${QUOTER}" -- "$@" | sed 's;\$;$$;')"
- # Also allow variables through arguments
- for i; do
- case "$i" in
- -h|--help)
- usage
- exit 1
- ;;
- -*)
- printf "Unknown argument ‘%s’\n" "${i}"
- usage
- exit 1
- ;;
- *=*)
- # shellcheck disable=SC2163
- export "$i"
- shift
- ;;
- *)
- printf "Unknown argument ‘%s’\n" "${i}"
- usage
- exit 1
- ;;
- esac
- done
- # Fallback definitions for dirs, based on $PREFIX
- DATADIR=${DATADIR:-${PREFIX}/share}
- ICONDIR=${ICONDIR:-${DATADIR}/icons}
- ## System checks
- printf 'Checking %s command existance ...' "${XCURSORGEN}"
- command -v "${XCURSORGEN}" >/dev/null ; required
- printf 'Checking %s command existance ...' "${MAGICK}"
- command -v "${MAGICK}" >/dev/null ; required
- CURSORS='
- arrow
- context-menu
- crosshair
- move
- text
- pointer
- help
- row-resize
- col-resize
- e-resize
- w-resize
- n-resize
- s-resize
- nesw-resize
- nwse-resize
- nw-resize
- ne-resize
- sw-resize
- se-resize
- vertical-text
- zoom-in
- zoom-out
- '
- NAME=ultrasharp
- printf 'Writing to build.ninja ...'
- (
- cat <<EOF
- # Autogenerated by $arg0 $args
- THEMEDIR = ${ICONDIR}/${NAME}
- XCURSORGEN = ${XCURSORGEN}
- MAGICK = ${MAGICK}
- rule gen_config
- command = ${arg0} ${args}
- generator = 1
- build build.ninja: gen_config configure
- rule cursorgen
- command = \$XCURSORGEN \$in \$out
- rule install
- command = mkdir -p \$\${DESTDIR}\${THEMEDIR}/ && cp -r cursors \$\${DESTDIR}\${THEMEDIR}/ && cp index.theme \$\${DESTDIR}\${THEMEDIR}/
- rule flop
- command = \$MAGICK \$in -flop \$out
- rule flip
- command = \$MAGICK \$in -flip \$out
- rule 90rot
- command = \$MAGICK \$in -rotate 90 \$out
- build install: install | cursors
- build nesw-resize.png: flip nwse-resize.png
- build e-resize.png: flop w-resize.png
- build n-resize.png: 90rot w-resize.png
- build s-resize.png: flip n-resize.png
- build ne-resize.png: 90rot nw-resize.png
- build se-resize.png: 90rot ne-resize.png
- build sw-resize.png: 90rot se-resize.png
- build wait2.png: 90rot wait.png
- build wait3.png: 90rot wait2.png
- build wait4.png: 90rot wait3.png
- build cursors/wait: cursorgen wait.cfg | wait.png wait2.png wait3.png wait4.png
- EOF
- printf 'build all: phony'
- printf ' cursors/%s' ${CURSORS} wait
- printf '\n\n'
- printf 'default all\n'
- for cur in ${CURSORS}; do
- printf 'build cursors/%s: cursorgen %s.cfg | %s.png\n' $cur $cur $cur
- done
- ) >|build.ninja
- is_ok
- printf '\nDone, you can now run ninja or samu\n'