aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore4
-rw-r--r--COPYING13
-rw-r--r--Makefile26
-rw-r--r--README.md4
-rwxr-xr-xconfigure7
-rw-r--r--mk/Makefile8
-rw-r--r--mk/bsd.sz.make.mk26
-rw-r--r--mk/bsd.sz.script.mk101
-rw-r--r--mk/gnu.sz.skaware.mk144
-rw-r--r--package/info3
-rw-r--r--package/targets.mk4
-rw-r--r--src/sz-configure-script93
-rw-r--r--src/sz-configure-skaware504
-rw-r--r--src/sz-install35
-rw-r--r--src/sz-policy-filter24
15 files changed, 996 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..ace3b6e
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
+.idea
+.policy
+build
+*.tar.gz
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..ab60150
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,13 @@
+Copyright (c) 2022 D. Olsson <hi@senzilla.io>
+
+Permission to use, copy, modify, and distribute this software for any
+purpose with or without fee is hereby granted, provided that the above
+copyright notice and this permission notice appear in all copies.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..3e00405
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,26 @@
+# SPDX-License-Identifier: ISC
+
+.include ".policy"
+.include "package/targets.mk"
+
+# XXX: Override our own build system since we're not installed yet.
+
+${DESTDIR}${PACKAGE_BASE}: ${DESTDIR}${PACKAGE_PREFIX}
+ backtick -E src basename ${PACKAGE_PREFIX} '' ln -s \$$src $@
+
+.for b in ${BIN_TARGETS}
+${DESTDIR}${PREFIX}/command/${b}: ${DESTDIR}${PACKAGE_BINDIR}/${b}
+ foreground mkdir -p ${@D} '' ln -s ..${PACKAGE_BASE:${PREFIX}=}/command/${b} $@
+
+build/bin/${b}: src/${b}
+ foreground mkdir -p ${@D} '' redirfd -r 0 src/${b} redirfd -w 1 $@ foreground awk 'NR==1 { sub("\/*@SHEBANGDIR@", "${SHEBANGDIR}") } 1' '' chmod 0755 $@
+.endfor
+
+# XXX: We want execline's export in the shell
+global-links: ${DESTDIR}${PREFIX}/command/execline-export
+${DESTDIR}${PREFIX}/command/execline-export:
+ execline-umask 077 ln -s export ${@}
+
+# XXX: The remaining rules will work.
+.include <sz.script.mk>
+INSTALL= install
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..b469fb3
--- /dev/null
+++ b/README.md
@@ -0,0 +1,4 @@
+sz-build
+========
+
+A simple command that applies file system and package policy to a file.
diff --git a/configure b/configure
new file mode 100755
index 0000000..313ef23
--- /dev/null
+++ b/configure
@@ -0,0 +1,7 @@
+#!/bin/sh
+# SPDX-License-Identifier: ISC
+
+tmp=$(mktemp)
+trap "rm -f $tmp" EXIT
+install -m 0755 src/sz-configure-script $tmp
+$tmp $@
diff --git a/mk/Makefile b/mk/Makefile
new file mode 100644
index 0000000..e95c965
--- /dev/null
+++ b/mk/Makefile
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: ISC
+
+BSDMK= sz.make.mk sz.script.mk
+GNUMK= sz.skaware.mk
+
+.include "${.CURDIR}/bsd.sz.make.mk"
+
+INSTALL= install
diff --git a/mk/bsd.sz.make.mk b/mk/bsd.sz.make.mk
new file mode 100644
index 0000000..29aa78c
--- /dev/null
+++ b/mk/bsd.sz.make.mk
@@ -0,0 +1,26 @@
+# SPDX-License-Identifier: ISC
+
+.MAIN: install
+
+INSTALL= sz-install
+BSDDIR= ${DESTDIR}/usr/share/mk
+GNUDIR= ${DESTDIR}/usr/local/include
+
+.PHONY: install
+install: install-bsd install-gnu
+
+.PHONY: install-bsd
+install-bsd: ${BSDMK:%=${BSDDIR}/%}
+
+.PHONY: install-gnu
+install-gnu: ${GNUMK:%=${GNUDIR}/%}
+
+.for f in ${BSDMK}
+${BSDDIR}/${f}: bsd.${f}
+ ${INSTALL} -Dm 0644 bsd.${f} $@
+.endfor
+
+.for f in ${GNUMK}
+${GNUDIR}/${f}: gnu.${f}
+ ${INSTALL} -Dm 0644 gnu.${f} $@
+.endfor
diff --git a/mk/bsd.sz.script.mk b/mk/bsd.sz.script.mk
new file mode 100644
index 0000000..b111012
--- /dev/null
+++ b/mk/bsd.sz.script.mk
@@ -0,0 +1,101 @@
+# SPDX-License-Identifier: ISC
+
+.MAIN: all
+
+.include ".policy"
+.include "package/targets.mk"
+
+.if exists(package/deps.mk)
+.include "package/deps.mk"
+.endif
+
+BUILD= build
+BIN_BUILD?= ${BIN_TARGETS:%=${BUILD}/bin/%}
+LIBEXEC_BUILD?= ${LIBEXEC_TARGETS:%=${BUILD}/libexec/%}
+SHARE_BUILD?= ${SHARE_TARGETS:%=${BUILD}/share/%}
+MAN_BUILD?= ${MAN_TARGETS:%=${BUILD}/man/%}
+
+INSTALL= sz-install
+
+.PHONY: all
+all: .policy ${BIN_BUILD} ${LIBEXEC_BUILD} ${SHARE_BUILD} ${MAN_BUILD}
+
+.PHONY: clean
+clean:
+ rm -rf ${BUILD}
+
+.PHONY: install
+install: install-bin install-libexec install-share
+
+.PHONY: install-bin
+install-bin: ${BIN_TARGETS:%=${DESTDIR}${PACKAGE_BINDIR}/%}
+
+.PHONY: install-libexec
+install-libexec: ${LIBEXEC_TARGETS:%=${DESTDIR}${PACKAGE_LIBEXECDIR}/%}
+
+.PHONY: install-share
+install-share: ${SHARE_TARGETS:%=${DESTDIR}${PACKAGE_SHAREDIR}/%}
+
+.PHONY: global-links
+global-links: ${DESTDIR}${PACKAGE_BASE} ${BIN_TARGETS:%=${DESTDIR}${PREFIX}/command/%}
+
+${DESTDIR}${PACKAGE_BASE}: ${DESTDIR}${PACKAGE_PREFIX}
+ ${INSTALL} -l ${PACKAGE_NAME}-${PACKAGE_VERSION} $@
+
+.if defined(SHARE_TARGETS)
+global-links: ${DESTDIR}${SHAREDIR}/${PACKAGE_NAME}
+
+# TODO: Don't hard code depth of the link.
+${DESTDIR}${SHAREDIR}/${PACKAGE_NAME}:
+ ${INSTALL} -l ../..${PACKAGE_BASE}/share $@
+.endif
+
+.for b in ${BIN_BUILD}
+${DESTDIR}${PREFIX}/command/${b:T}: ${DESTDIR}${PACKAGE_BINDIR}/${b:T}
+ ${INSTALL} -l ..${PACKAGE_BASE:${PREFIX}=}/command/${b:T} $@
+
+${DESTDIR}${PACKAGE_BINDIR}/${b:T}: ${b}
+ ${INSTALL} -Dm 0555 $> $@
+
+${b}: src/${b:T}
+ ${INSTALL} -Dm 0555 $> $@
+.endfor
+
+.for l in ${LIBEXEC_BUILD}
+${DESTDIR}${PACKAGE_LIBEXECDIR}/${l:T}: ${l}
+ ${INSTALL} -Dm 0555 $> $@
+
+${l}: src/${l:T}
+ ${INSTALL} -Dm 0555 $> $@
+.endfor
+
+.for s in ${SHARE_BUILD}
+${DESTDIR}${PACKAGE_SHAREDIR}/${s:${BUILD}/share/%=%}: ${s}
+ ${INSTALL} -Dm 0444 $> $@
+
+# XXX: Build full depth target.
+${s}: ${s:${BUILD}/%=%}
+ ${INSTALL} -Dm 0444 $> $@
+.endfor
+
+.if defined(MAN_TARGETS)
+.PHONY: install-man
+install: install-man
+
+. for m in ${MAN_BUILD}
+_MAN_TARGET= ${DESTDIR}${PACKAGE_MANDIR}/${m:T}
+_LINK_TARGET= ${DESTDIR}${MANDIR}/man${m:E}/${m:T}
+install-man: ${_MAN_TARGET}
+global-links: ${_LINK_TARGET}
+
+# TODO: Don't hard code depth of the link.
+${_LINK_TARGET}: ${_MAN_TARGET}
+ ln -s ../../../..${PACKAGE_BASE}/man/${m:T} $@
+
+${_MAN_TARGET}: ${m}
+ ${INSTALL} -Dm 0444 $> $@
+
+${m}: man/${m:T}
+ ${INSTALL} -Dm 0444 $> $@
+. endfor
+.endif
diff --git a/mk/gnu.sz.skaware.mk b/mk/gnu.sz.skaware.mk
new file mode 100644
index 0000000..d3452ff
--- /dev/null
+++ b/mk/gnu.sz.skaware.mk
@@ -0,0 +1,144 @@
+# SPDX-License-Identifier: ISC
+
+it: all
+
+make_need := 3.81
+ifeq "" "$(strip $(filter $(make_need), $(firstword $(sort $(make_need) $(MAKE_VERSION)))))"
+fail := $(error Your make ($(MAKE_VERSION)) is too old. You need $(make_need) or newer)
+endif
+
+CC = $(error Please use ./configure first)
+
+STATIC_LIBS :=
+SHARED_LIBS :=
+INTERNAL_LIBS :=
+EXTRA_TARGETS :=
+LIB_DEFS :=
+
+define library_definition
+LIB$(firstword $(subst =, ,$(1))) := lib$(lastword $(subst =, ,$(1))).$(if $(DO_ALLSTATIC),a,so).xyzzy
+ifdef DO_SHARED
+SHARED_LIBS += lib$(lastword $(subst =, ,$(1))).so.xyzzy
+endif
+ifdef DO_STATIC
+STATIC_LIBS += lib$(lastword $(subst =, ,$(1))).a.xyzzy
+endif
+endef
+
+-include config.mak
+include package/targets.mak
+
+$(foreach var,$(LIB_DEFS),$(eval $(call library_definition,$(var))))
+
+include package/deps.mak
+
+version_m := $(basename $(version))
+version_M := $(basename $(version_m))
+version_l := $(basename $(version_M))
+CPPFLAGS_ALL := $(CPPFLAGS_AUTO) $(CPPFLAGS)
+CFLAGS_ALL := $(CFLAGS_AUTO) $(CFLAGS)
+ifeq ($(strip $(STATIC_LIBS_ARE_PIC)),)
+CFLAGS_SHARED := -fPIC
+else
+CFLAGS_SHARED :=
+endif
+LDFLAGS_ALL := $(LDFLAGS_AUTO) $(LDFLAGS)
+AR := $(CROSS_COMPILE)ar
+RANLIB := $(CROSS_COMPILE)ranlib
+STRIP := $(CROSS_COMPILE)strip
+INSTALL := ./tools/install.sh
+
+ALL_BINS := $(LIBEXEC_TARGETS) $(BIN_TARGETS)
+ALL_LIBS := $(SHARED_LIBS) $(STATIC_LIBS) $(INTERNAL_LIBS)
+ALL_INCLUDES := $(wildcard src/include/$(package)/*.h)
+
+all: $(ALL_LIBS) $(ALL_BINS) $(ALL_INCLUDES)
+
+clean:
+ @exec rm -f $(ALL_LIBS) $(ALL_BINS) $(wildcard src/*/*.o src/*/*.lo)
+
+distclean: clean
+ @exec rm -f config.mak src/include/$(package)/config.h
+
+tgz: distclean
+ @. package/info && \
+ rm -rf /tmp/$$package-$$version && \
+ cp -a . /tmp/$$package-$$version && \
+ cd /tmp && \
+ tar -zpcv --owner=0 --group=0 --numeric-owner --exclude=.git* -f /tmp/$$package-$$version.tar.gz $$package-$$version && \
+ exec rm -rf /tmp/$$package-$$version
+
+strip: $(ALL_LIBS) $(ALL_BINS)
+ifneq ($(strip $(STATIC_LIBS)),)
+ exec $(STRIP) -x -R .note -R .comment $(STATIC_LIBS)
+endif
+ifneq ($(strip $(ALL_BINS)$(SHARED_LIBS)),)
+ exec $(STRIP) -R .note -R .comment $(ALL_BINS) $(SHARED_LIBS)
+endif
+
+install: install-dynlib install-libexec install-bin install-lib install-include
+install-dynlib: $(SHARED_LIBS:lib%.so.xyzzy=$(DESTDIR)$(dynlibdir)/lib%.so)
+install-libexec: $(LIBEXEC_TARGETS:%=$(DESTDIR)$(libexecdir)/%)
+install-bin: $(BIN_TARGETS:%=$(DESTDIR)$(bindir)/%) $(EXTRA_TARGETS:%=$(DESTDIR)$(bindir)/%)
+install-lib: $(STATIC_LIBS:lib%.a.xyzzy=$(DESTDIR)$(libdir)/lib%.a)
+install-include: $(ALL_INCLUDES:src/include/$(package)/%.h=$(DESTDIR)$(includedir)/$(package)/%.h)
+install-data: $(ALL_DATA:src/etc/%=$(DESTDIR)$(datadir)/%)
+
+ifneq ($(exthome),)
+
+$(DESTDIR)$(exthome): $(DESTDIR)$(home)
+ exec $(INSTALL) -l $(notdir $(home)) $(DESTDIR)$(exthome)
+
+update: $(DESTDIR)$(exthome)
+
+global-links: $(DESTDIR)$(exthome) $(SHARED_LIBS:lib%.so.xyzzy=$(DESTDIR)$(sproot)/library.so/lib%.so.$(version_M)) $(BIN_TARGETS:%=$(DESTDIR)$(sproot)/command/%) $(EXTRA_TARGETS:%=$(DESTDIR)$(sproot)/command/%)
+
+$(DESTDIR)$(sproot)/command/%: $(DESTDIR)$(home)/command/%
+ exec $(INSTALL) -D -l ..$(subst $(sproot),,$(exthome))/command/$(<F) $@
+
+$(DESTDIR)$(sproot)/library.so/lib%.so.$(version_M): $(DESTDIR)$(dynlibdir)/lib%.so.$(version_M)
+ exec $(INSTALL) -D -l ..$(subst $(sproot),,$(exthome))/library.so/$(<F) $@
+
+.PHONY: update global-links
+
+endif
+
+$(DESTDIR)$(datadir)/%: src/etc/%
+ exec $(INSTALL) -D -m 644 $< $@
+
+$(DESTDIR)$(dynlibdir)/lib%.so $(DESTDIR)$(dynlibdir)/lib%.so.$(version_M): lib%.so.xyzzy
+ $(INSTALL) -D -m 755 $< $@.$(version) && \
+ $(INSTALL) -l $(@F).$(version) $@.$(version_M) && \
+ exec $(INSTALL) -l $(@F).$(version_M) $@
+
+$(DESTDIR)$(libexecdir)/% $(DESTDIR)$(bindir)/%: % package/modes
+ exec $(INSTALL) -D -m 600 $< $@
+ grep -- ^$(@F) < package/modes | { read name mode owner && \
+ if [ x$$owner != x ] ; then chown -- $$owner $@ ; fi && \
+ chmod $$mode $@ ; }
+
+$(DESTDIR)$(libdir)/lib%.a: lib%.a.xyzzy
+ exec $(INSTALL) -D -m 644 $< $@
+
+$(DESTDIR)$(includedir)/$(package)/%.h: src/include/$(package)/%.h
+ exec $(INSTALL) -D -m 644 $< $@
+
+%.o: %.c
+ exec $(CC) $(CPPFLAGS_ALL) $(CFLAGS_ALL) -c -o $@ $<
+
+%.lo: %.c
+ exec $(CC) $(CPPFLAGS_ALL) $(CFLAGS_ALL) $(CFLAGS_SHARED) -c -o $@ $<
+
+$(ALL_BINS):
+ exec $(CC) -o $@ $(CFLAGS_ALL) $(LDFLAGS_ALL) $(LDFLAGS_NOSHARED) $^ $(EXTRA_LIBS) $(LDLIBS)
+
+lib%.a.xyzzy:
+ exec $(AR) rc $@ $^
+ exec $(RANLIB) $@
+
+lib%.so.xyzzy:
+ exec $(CC) -o $@ $(CFLAGS_ALL) $(CFLAGS_SHARED) $(LDFLAGS_ALL) $(LDFLAGS_SHARED) -Wl,-soname,$(patsubst lib%.so.xyzzy,lib%.so.$(version_M),$@) $^ $(EXTRA_LIBS) $(LDLIBS)
+
+.PHONY: it all clean distclean tgz strip install install-dynlib install-bin install-lib install-include install-data
+
+.DELETE_ON_ERROR:
diff --git a/package/info b/package/info
new file mode 100644
index 0000000..8c0ee5e
--- /dev/null
+++ b/package/info
@@ -0,0 +1,3 @@
+package=sz-build
+version=0.0.1
+category=devel
diff --git a/package/targets.mk b/package/targets.mk
new file mode 100644
index 0000000..77a0d56
--- /dev/null
+++ b/package/targets.mk
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: ISC
+
+BIN_TARGETS= sz-configure-script sz-configure-skaware sz-install \
+ sz-policy-filter
diff --git a/src/sz-configure-script b/src/sz-configure-script
new file mode 100644
index 0000000..69fe377
--- /dev/null
+++ b/src/sz-configure-script
@@ -0,0 +1,93 @@
+#/bin/sh
+# SPDX-License-Identifier: ISC
+
+. package/info
+
+usage() {
+echo "Usage: $0 [OPTION...]
+
+Options:
+
+--help this help message
+--prefix=PREFIX install prefix [/]
+--bindir=DIR user executables [PREFIX/bin]
+--sbindir=DIR system executables [PREFIX/sbin]
+--libexecdir=DIR package executables [PREFIX/libexec]
+--sharedir=DIR shared data files [/usr/share]
+--mandir=DIR manual pages [SHAREDIR/man]
+--shebangdir=DIR absolute path for #! invocations [BINDIR]
+--enable-slashpackage enable the /package policy [disabled]"
+exit 0
+}
+
+prefix=
+bindir=$prefix/bin
+sbindir=$prefix/sbin
+libexecdir=$prefix/libexec
+sharedir=/usr/share
+mandir=$sharedir/man
+shebangdir=$bindir
+slashpackage=false
+package_base=$prefix
+package_prefix=$prefix
+package_bindir=$bindir
+package_sbindir=$sbindir
+package_libexecdir=$libexecdir
+package_sharedir=$sharedir/$package
+package_mandir=$mandir
+
+cmdline="$0 $@"
+
+for arg; do
+ case "$arg" in
+ --help) usage;;
+ --prefix=*) prefix=${arg#*=};;
+ --bindir=*) bindir=${arg#*=};;
+ --sbindir=*) sbindir=${arg#*=};;
+ --libexecdir=*) libexecdir=${arg#*=};;
+ --sharedir=*) sharedir=${arg#*=};;
+ --mandir=*) mandir=${arg#*=};;
+ --shebangdir=*) shebangdir=${arg#*=};;
+ --enable-slashpackage) slashpackage=true;;
+ *) echo "$0: unknown option $arg";;
+ esac
+done
+
+if $slashpackage; then
+ bindir=$prefix/command
+ sbindir=$bindir
+ libexecdir=$bindir
+ shebangdir=/command
+ package_base=$prefix/package/$category/$package
+ package_prefix=${package_base}-${version}
+ package_bindir=$package_prefix/command
+ package_sbindir=$package_bindir
+ package_libexecdir=$package_bindir
+ package_sharedir=$package_prefix/share
+ package_mandir=$package_prefix/man
+fi
+
+echo "Creating .policy ..."
+cat > .policy <<EOF
+# This file was generated with: $cmdline
+
+PREFIX=$prefix
+BINDIR=$bindir
+SBINDIR=$sbindir
+LIBEXECDIR=$libexecdir
+SHAREDIR=$sharedir
+MANDIR=$mandir
+SHEBANGDIR=$shebangdir
+
+PACKAGE_NAME=$package
+PACKAGE_VERSION=$version
+PACKAGE_BASE=$package_base
+PACKAGE_PREFIX=$package_prefix
+PACKAGE_BINDIR=$package_bindir
+PACKAGE_SBINDIR=$package_sbindir
+PACKAGE_LIBEXECDIR=$package_libexecdir
+PACKAGE_SHAREDIR=$package_sharedir
+PACKAGE_MANDIR=$package_mandir
+EOF
+
+echo "... done."
diff --git a/src/sz-configure-skaware b/src/sz-configure-skaware
new file mode 100644
index 0000000..52c398a
--- /dev/null
+++ b/src/sz-configure-skaware
@@ -0,0 +1,504 @@
+#!/bin/sh
+# SPDX-License-Identifier: ISC
+
+. package/info
+
+usage () {
+cat <<EOF
+Usage: $0 [OPTION]... [TARGET]
+
+Defaults for the options are specified in brackets.
+
+System types:
+ --target=TARGET configure to run on target TARGET [detected]
+ --host=TARGET same as --target
+
+Installation directories:
+ --prefix=PREFIX main installation prefix [/]
+ --exec-prefix=EPREFIX installation prefix for executable files [PREFIX]
+
+Fine tuning of the installation directories:
+ --dynlibdir=DIR shared library files [PREFIX/lib]
+ --bindir=BINDIR user executables [EPREFIX/bin]
+ --libexecdir=DIR package-scoped executables [EPREFIX/libexec]
+ --libdir=DIR static library files [PREFIX/lib/$package]
+ --includedir=DIR C header files [PREFIX/include]
+ --shebangdir=DIR absolute path for #! invocations [BINDIR]
+
+ If no --prefix option is given, by default libdir (but not dynlibdir) will be
+ /usr/lib/$package, and includedir will be /usr/include.
+
+Dependencies:
+ --with-sysdeps=DIR use sysdeps in DIR [PREFIX/lib/skalibs/sysdeps]
+ --with-include=DIR add DIR to the list of searched directories for headers
+ --with-lib=DIR add DIR to the list of searched directories for static libraries
+ --with-dynlib=DIR add DIR to the list of searched directories for shared libraries
+
+ If no --prefix option is given, by default sysdeps will be fetched from
+ /usr/lib/skalibs/sysdeps.
+
+Optional features:
+ --enable-shared build shared libraries [disabled]
+ --disable-static do not build static libraries [enabled]
+ --disable-allstatic do not prefer linking against static libraries [enabled]
+ --enable-static-libc make entirely static binaries [disabled]
+ --disable-all-pic do not build executables and static libs as PIC [enabled]
+ --enable-slashpackage[=ROOT] assume /package installation at ROOT [disabled]
+ --enable-absolute-paths do not rely on PATH to access this package's binaries,
+ hardcode absolute BINDIR/foobar paths instead [disabled]
+ --enable-nsss use the nsss library for user information [disabled]
+ --enable-pedantic-posix use pedantically POSIX-compatible binaries [disabled]
+
+EOF
+exit 0
+}
+
+# Helper functions
+
+# If your system does not have printf, you can comment this, but it is
+# generally not a good idea to use echo.
+# See http://etalabs.net/sh_tricks.html
+echo () {
+ IFS=" "
+ printf %s\\n "$*"
+}
+
+quote () {
+ tr '\n' ' ' <<EOF | grep '^[-[:alnum:]_=,./:]* $' >/dev/null 2>&1 && { echo "$1" ; return 0 ; }
+$1
+EOF
+ echo "$1" | sed -e "s/'/'\\\\''/g" -e "1s/^/'/" -e "\$s/\$/'/" -e "s#^'\([-[:alnum:]_,./:]*\)=\(.*\)\$#\1='\2#" -e "s|\*/|* /|g"
+}
+
+fail () {
+ echo "$*"
+ exit 1
+}
+
+fnmatch () {
+ eval "case \"\$2\" in $1) return 0 ;; *) return 1 ;; esac"
+}
+
+cmdexists () {
+ type "$1" >/dev/null 2>&1
+}
+
+trycc () {
+ test -z "$CC_AUTO" && cmdexists "$1" && CC_AUTO="$*"
+}
+
+stripdir () {
+ while eval "fnmatch '*/' \"\${$1}\"" ; do
+ eval "$1=\${$1%/}"
+ done
+}
+
+tryflag () {
+ echo "Checking whether compiler accepts $2 ..."
+ echo "typedef int x;" > "$tmpc"
+ if $CC_AUTO $CPPFLAGS_AUTO $CPPFLAGS $CPPFLAGS_POST $CFLAGS_AUTO $CFLAGS $CFLAGS_POST "$2" -c -o "$tmpo" "$tmpc" >/dev/null 2>&1 ; then
+ echo " ... yes"
+ eval "$1=\"\${$1} \$2\""
+ eval "$1=\${$1# }"
+ return 0
+ else
+ echo " ... no"
+ return 1
+ fi
+}
+
+tryldflag () {
+ echo "Checking whether linker accepts $2 ..."
+ echo "typedef int x;" > "$tmpc"
+ if $CC_AUTO $CFLAGS_AUTO $CFLAGS $CFLAGS_POST $LDFLAGS_AUTO $LDFLAGS $LDFLAGS_POST -nostdlib "$2" -o "$tmpe" "$tmpc" >/dev/null 2>&1 ; then
+ echo " ... yes"
+ eval "$1=\"\${$1} \$2\""
+ eval "$1=\${$1# }"
+ return 0
+ else
+ echo " ... no"
+ return 1
+ fi
+}
+
+
+# Actual script
+
+CC_AUTO=
+CPPFLAGS_AUTO="-D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 -iquote src/include-local -Isrc/include"
+CPPFLAGS_POST="$CPPFLAGS"
+CPPFLAGS=
+CFLAGS_AUTO="-pipe -Wall"
+CFLAGS_POST="$CFLAGS"
+CFLAGS=-O2
+LDFLAGS_AUTO=
+LDFLAGS_POST="$LDFLAGS"
+LDFLAGS=
+LDFLAGS_NOSHARED=
+LDFLAGS_SHARED=-shared
+prefix=
+exec_prefix='$prefix'
+dynlibdir='$prefix/lib'
+libexecdir='$exec_prefix/libexec'
+bindir='$exec_prefix/bin'
+libdir='$prefix/lib/$package'
+includedir='$prefix/include'
+shebangdir='$bindir'
+shebangisdefault=true
+sysdeps='$prefix/lib/skalibs/sysdeps'
+manualsysdeps=false
+shared=false
+static=true
+allpic=true
+slashpackage=false
+abspath=false
+usensss=false
+pposix=false
+sproot=
+home=
+exthome=
+allstatic=true
+evenmorestatic=false
+addincpath=''
+addlibspath=''
+addlibdpath=''
+vpaths=''
+vpathd=''
+build=
+
+for arg ; do
+ case "$arg" in
+ --help) usage ;;
+ --prefix=*) prefix=${arg#*=} ;;
+ --exec-prefix=*) exec_prefix=${arg#*=} ;;
+ --dynlibdir=*) dynlibdir=${arg#*=} ;;
+ --libexecdir=*) libexecdir=${arg#*=} ;;
+ --bindir=*) bindir=${arg#*=} ;;
+ --libdir=*) libdir=${arg#*=} ;;
+ --includedir=*) includedir=${arg#*=} ;;
+ --shebangdir=*) shebangisdefault=false ; shebangdir=${arg#*=} ;;
+ --with-sysdeps=*) sysdeps=${arg#*=} manualsysdeps=true ;;
+ --with-include=*) var=${arg#*=} ; stripdir var ; addincpath="$addincpath -I$var" ;;
+ --with-lib=*) var=${arg#*=} ; stripdir var ; addlibspath="$addlibspath -L$var" ; vpaths="$vpaths $var" ;;
+ --with-dynlib=*) var=${arg#*=} ; stripdir var ; addlibdpath="$addlibdpath -L$var" ; vpathd="$vpathd $var" ;;
+ --enable-shared|--enable-shared=yes) shared=true ;;
+ --disable-shared|--enable-shared=no) shared=false ;;
+ --enable-static|--enable-static=yes) static=true ;;
+ --disable-static|--enable-static=no) static=false ;;
+ --enable-allstatic|--enable-allstatic=yes) allstatic=true ;;
+ --disable-allstatic|--enable-allstatic=no) allstatic=false ; evenmorestatic=false ;;
+ --enable-static-libc|--enable-static-libc=yes) allstatic=true ; evenmorestatic=true ;;
+ --disable-static-libc|--enable-static-libc=no) evenmorestatic=false ;;
+ --enable-all-pic|--enable-all-pic=yes) allpic=true ;;
+ --disable-all-pic|--enable-all-pic=no) allpic=false ;;
+ --enable-slashpackage=*) sproot=${arg#*=} ; slashpackage=true ; ;;
+ --enable-slashpackage) sproot= ; slashpackage=true ;;
+ --disable-slashpackage) sproot= ; slashpackage=false ;;
+ --enable-absolute-paths|--enable-absolute-paths=yes) abspath=true ;;
+ --disable-absolute-paths|--enable-absolute-paths=no) abspath=false ;;
+ --enable-nsss|--enable-nsss=yes) usensss=true ;;
+ --disable-nsss|--enable-nsss=no) usensss=false ;;
+ --enable-pedantic-posix|--enable-pedantic-posix=yes) pposix=true ;;
+ --disable-pedantic-posix|--enable-pedantic-posix=no) pposix=false ;;
+ --enable-*|--disable-*|--with-*|--without-*|--*dir=*) ;;
+ --enable-*|--disable-*|--with-*|--without-*|--*dir=*) ;;
+ --host=*|--target=*) target=${arg#*=} ;;
+ --build=*) build=${arg#*=} ;;
+ -* ) echo "$0: unknown option $arg" ;;
+ *=*) eval "$arg" ;;
+ *) target=$arg ;;
+ esac
+done
+
+# Add /usr in the default default case
+if test -z "$prefix" ; then
+ if test "$libdir" = '$prefix/lib/$package' ; then
+ libdir=/usr/lib/$package
+ fi
+ if test "$includedir" = '$prefix/include' ; then
+ includedir=/usr/include
+ fi
+ if test "$sysdeps" = '$prefix/lib/skalibs/sysdeps' ; then
+ sysdeps=/usr/lib/skalibs/sysdeps
+ fi
+fi
+
+# Expand installation directories
+stripdir prefix
+for i in exec_prefix dynlibdir libexecdir bindir libdir includedir shebangdir sysdeps sproot ; do
+ eval tmp=\${$i}
+ eval $i=$tmp
+ stripdir $i
+done
+
+# Get usable temp filenames
+i=0
+set -C
+while : ; do
+ i=$(($i+1))
+ tmpc="./tmp-configure-$$-$PPID-$i.c"
+ tmpo="./tmp-configure-$$-$PPID-$i.o"
+ tmpe="./tmp-configure-$$-$PPID-$i.tmp"
+ 2>|/dev/null > "$tmpc" && break
+ 2>|/dev/null > "$tmpo" && break
+ 2>|/dev/null > "$tmpe" && break
+ test "$i" -gt 50 && fail "$0: cannot create temporary files"
+done
+set +C
+trap 'rm -f "$tmpc" "$tmpo" "$tmpe"' EXIT ABRT INT QUIT TERM HUP
+
+# Set slashpackage values
+if $slashpackage ; then
+ home=${sproot}/package/${category}/${package}-${version}
+ exthome=${sproot}/package/${category}/${package}
+ if $manualsysdeps ; then
+ :
+ else
+ sysdeps=${DESTDIR}${sproot}/package/prog/skalibs/sysdeps
+ fi
+ extbinprefix=${exthome}/command
+ dynlibdir=${home}/library.so
+ bindir=${home}/command
+ libdir=${home}/library
+ libexecdir=$bindir
+ includedir=${home}/include
+ if $shebangisdefault ; then
+ shebangdir=${extbinprefix}
+ fi
+ while read dep condvar ; do
+ if test -n "$condvar" ; then
+ eval "cond=$condvar"
+ else
+ cond=true
+ fi
+ if $cond ; then
+ addincpath="$addincpath -I${DESTDIR}${sproot}${dep}/include"
+ vpaths="$vpaths ${DESTDIR}${sproot}${dep}/library"
+ addlibspath="$addlibspath -L${DESTDIR}${sproot}${dep}/library"
+ vpathd="$vpathd ${DESTDIR}${sproot}${dep}/library.so"
+ addlibdpath="$addlibdpath -L${DESTDIR}${sproot}${dep}/library.so"
+ fi
+ done < package/deps-build
+fi
+
+# Find a C compiler to use
+if test -n "$target" && test x${build} != x${target} ; then
+ cross=${target}-
+else
+ cross=
+fi
+echo "Checking for C compiler..."
+trycc ${CC}
+if test -n "$CC_AUTO" ; then
+ b=`basename "$CC"`
+ adjust_cross=false
+ if test "$b" != "$CC" ; then
+ adjust_cross=true
+ echo "$0: warning: compiler $CC is declared with its own path. If it's not accessible via PATH, you will need to pass AR, RANLIB and STRIP make variables to the make invocation." 1>&2
+ fi
+ if test -n "$cross" ; then
+ if test "$b" = "${b##$cross}" ; then
+ echo "$0: warning: compiler $CC is declared as a cross-compiler for target $target but does not start with prefix ${cross}" 1>&2
+ elif $adjust_cross ; then
+ cross=`dirname "$CC"`/"$cross"
+ fi
+ fi
+fi
+trycc ${cross}gcc
+trycc ${cross}clang
+trycc ${cross}cc
+test -n "$CC_AUTO" || { echo "$0: cannot find a C compiler" ; exit 1 ; }
+echo " ... $CC_AUTO"
+echo "Checking whether C compiler works... "
+echo "typedef int x;" > "$tmpc"
+if $CC_AUTO $CPPFLAGS_AUTO $CPPFLAGS $CPPFLAGS_POST $CFLAGS_AUTO $CFLAGS $CFLAGS_POST -c -o "$tmpo" "$tmpc" 2>"$tmpe" ; then
+ echo " ... yes"
+else
+ echo " ... no. Compiler output follows:"
+ cat < "$tmpe"
+ exit 1
+fi
+
+echo "Checking target system type..."
+if test -z "$target" ; then
+ if test -n "$build" ; then
+ target=$build ;
+ else
+ target=$($CC_AUTO -dumpmachine 2>/dev/null) || target=unknown
+ fi
+fi
+echo " ... $target"
+if test ! -d $sysdeps || test ! -f $sysdeps/target ; then
+ echo "$0: error: $sysdeps is not a valid sysdeps directory"
+ exit 1
+fi
+if [ "x$target" != "x$(cat $sysdeps/target)" ] ; then
+ echo "$0: error: target $target does not match the contents of $sysdeps/target"
+ exit 1
+fi
+
+if $allpic ; then
+ tryflag CPPFLAGS_AUTO -fPIC
+fi
+spawn_lib=$(cat $sysdeps/spawn.lib)
+socket_lib=$(cat $sysdeps/socket.lib)
+sysclock_lib=$(cat $sysdeps/sysclock.lib)
+timer_lib=$(cat $sysdeps/timer.lib)
+util_lib=$(cat $sysdeps/util.lib)
+
+tryflag CFLAGS_AUTO -std=c99
+tryflag CFLAGS -fomit-frame-pointer
+tryflag CFLAGS_AUTO -fno-exceptions
+tryflag CFLAGS_AUTO -fno-unwind-tables
+tryflag CFLAGS_AUTO -fno-asynchronous-unwind-tables
+tryflag CPPFLAGS_AUTO -Werror=implicit-function-declaration
+tryflag CPPFLAGS_AUTO -Werror=implicit-int
+tryflag CPPFLAGS_AUTO -Werror=pointer-sign
+tryflag CPPFLAGS_AUTO -Werror=pointer-arith
+tryflag CFLAGS_AUTO -ffunction-sections
+tryflag CFLAGS_AUTO -fdata-sections
+
+tryldflag LDFLAGS_AUTO -Wl,--sort-section=alignment
+tryldflag LDFLAGS_AUTO -Wl,--sort-common
+
+CPPFLAGS_AUTO="${CPPFLAGS_AUTO}${addincpath}"
+
+if $evenmorestatic ; then
+ LDFLAGS_NOSHARED=-static
+fi
+
+if $shared ; then
+ tryldflag LDFLAGS -Wl,--hash-style=both
+fi
+
+LDFLAGS_SHARED="${LDFLAGS_SHARED}${addlibdpath}"
+
+if test -z "$vpaths" ; then
+ while read dep ; do
+ base=$(basename $dep) ;
+ vpaths="$vpaths /usr/lib/$base"
+ addlibspath="$addlibspath -L/usr/lib/$base"
+ done < package/deps-build
+fi
+
+if $allstatic ; then
+ LDFLAGS_NOSHARED="${LDFLAGS_NOSHARED}${addlibspath}"
+ tryldflag LDFLAGS_NOSHARED -Wl,--gc-sections
+else
+ LDFLAGS_NOSHARED="${LDFLAGS_NOSHARED}${addlibdpath}"
+fi
+
+echo "Creating config.mak..."
+cmdline=$(quote "$0")
+for i ; do cmdline="$cmdline $(quote "$i")" ; done
+exec 3>&1 1>config.mak
+cat << EOF
+# This file was generated by:
+# $cmdline
+# Any changes made here will be lost if configure is re-run.
+
+target := $target
+package := $package
+prefix := $prefix
+exec_prefix := $exec_prefix
+dynlibdir := $dynlibdir
+libexecdir := $libexecdir
+bindir := $bindir
+libdir := $libdir
+includedir := $includedir
+sysdeps := $sysdeps
+slashpackage := $slashpackage
+sproot := $sproot
+version := $version
+home := $home
+exthome := $exthome
+SPAWN_LIB := ${spawn_lib}
+SOCKET_LIB := ${socket_lib}
+SYSCLOCK_LIB := ${sysclock_lib}
+TIMER_LIB := ${timer_lib}
+UTIL_LIB := ${util_lib}
+
+CC := $CC_AUTO
+CPPFLAGS_AUTO := $CPPFLAGS_AUTO
+CPPFLAGS := $CPPFLAGS $CPPFLAGS_POST
+CFLAGS_AUTO := $CFLAGS_AUTO
+CFLAGS := $CFLAGS $CFLAGS_POST
+LDFLAGS_AUTO := $LDFLAGS_AUTO
+LDFLAGS := $LDFLAGS $LDFLAGS_POST
+LDFLAGS_SHARED := $LDFLAGS_SHARED
+LDFLAGS_NOSHARED := $LDFLAGS_NOSHARED
+CROSS_COMPILE := $cross
+
+vpath lib%.a$vpaths
+vpath lib%.so$vpathd
+EOF
+if $allstatic ; then
+ echo ".LIBPATTERNS := lib%.a"
+ echo "DO_ALLSTATIC := 1"
+else
+ echo ".LIBPATTERNS := lib%.so"
+fi
+if $static ; then
+ echo "DO_STATIC := 1"
+else
+ echo "DO_STATIC :="
+fi
+if $shared ; then
+ echo "DO_SHARED := 1"
+else
+ echo "DO_SHARED :="
+fi
+if $allpic ; then
+ echo "STATIC_LIBS_ARE_PIC := 1"
+else
+ echo "STATIC_LIBS_ARE_PIC :="
+fi
+if $usensss ; then
+ echo "LIBNSSS := -lnsss"
+ echo "MAYBEPTHREAD_LIB := -lpthread"
+else
+ echo "LIBNSSS :="
+ echo "MAYBEPTHREAD_LIB :="
+fi
+if $pposix ; then
+ echo "PEDANTIC_POSIX := 1"
+else
+ echo "PEDANTIC_POSIX :="
+fi
+exec 1>&3 3>&-
+echo " ... done."
+
+echo "Creating src/include/${package}/config.h..."
+mkdir -p -m 0755 src/include/${package}
+exec 3>&1 1> src/include/${package}/config.h
+cat <<EOF
+/* ISC license. */
+
+/* Generated by: $cmdline */
+
+#ifndef ${package_macro_name}_CONFIG_H
+#define ${package_macro_name}_CONFIG_H
+
+#define ${package_macro_name}_VERSION "$version"
+EOF
+if $slashpackage ; then
+ echo "#define ${package_macro_name}_BINPREFIX \"$bindir/\""
+ echo "#define ${package_macro_name}_EXTBINPREFIX \"$extbinprefix/\""
+elif $abspath ; then
+ echo "#define ${package_macro_name}_BINPREFIX \"$bindir/\""
+ echo "#define ${package_macro_name}_EXTBINPREFIX \"$bindir/\""
+else
+ echo "#define ${package_macro_name}_BINPREFIX \"\""
+ echo "#define ${package_macro_name}_EXTBINPREFIX \"\""
+fi
+echo "#define ${package_macro_name}_LIBEXECPREFIX \"$libexecdir/\""
+echo "#define ${package_macro_name}_SHEBANGPREFIX \"$shebangdir/\""
+echo
+echo "#undef ${package_macro_name}_PEDANTIC_POSIX"
+if $pposix ; then
+echo "#define ${package_macro_name}_PEDANTIC_POSIX"
+fi
+echo
+echo "#endif"
+exec 1>&3 3>&-
+echo " ... done."
diff --git a/src/sz-install b/src/sz-install
new file mode 100644
index 0000000..403aad0
--- /dev/null
+++ b/src/sz-install
@@ -0,0 +1,35 @@
+#!@SHEBANGDIR@/execlineb
+# SPDX-License-Identifier: ISC
+
+elgetopt Dlm:x:
+multisubstitute {
+ importas -D 0755 mode ELGETOPT_m
+ importas -D .policy policy ELGETOPT_x
+ elgetpositionals
+}
+backtick -E dir { dirname $2 }
+backtick -E tmp { echo ${2}.tmp }
+foreground {
+ if { s6-test -v ELGETOPT_D }
+ umask 022 mkdir -p $dir
+}
+trap { default { rm -rf $tmp } }
+umask 077
+ifthenelse { s6-test -v ELGETOPT_l }
+{
+ ln -s $1 $tmp
+}
+{
+ redirfd -r 0 $1
+ redirfd -w 1 $tmp
+ if {
+ ifelse { s6-test -f $policy }
+ {
+ envfile $policy
+ sz-policy-filter
+ }
+ cat
+ }
+}
+if { chmod $mode $tmp }
+mv $tmp $2
diff --git a/src/sz-policy-filter b/src/sz-policy-filter
new file mode 100644
index 0000000..f1a2559
--- /dev/null
+++ b/src/sz-policy-filter
@@ -0,0 +1,24 @@
+#!@SHEBANGDIR@/awk -f
+# SPDX-License-Identifier: ISC
+# vi: syntax=awk
+
+BEGIN {
+ RS = "@"; ORS = ""
+ P["BINDIR"] = "/bin"
+ P["SBINDIR"] = "/sbin"
+ P["LIBEXECDIR"] = "/libexec"
+ P["SHAREDIR"] = "/usr/share"
+ P["SHEBANGDIR"] = "/bin"
+ P["PACKAGE_BINDIR"] = P["BINDIR"]
+ P["PACKAGE_SBINDIR"] = P["BINDIR"]
+ P["PACKAGE_LIBEXECDIR"] = P["LIBEXECDIR"]
+ P["PACKAGE_SHAREDIR"] = P["SHAREDIR"]
+ for (p in P) if (ENVIRON[p]) P[p] = ENVIRON[p]
+}
+function fmt(s) { printf("%s", s); return 1 }
+NR == 1 { fmt($0) }
+NR > 1 {
+ for (p in P) if ($1 == p && fmt(P[p]) && r = 1) next
+ r ? fmt($0) : fmt(RS $0)
+ r = 0
+}