diff --git a/.github/build b/.github/build new file mode 100755 index 0000000..d35cc1d --- /dev/null +++ b/.github/build @@ -0,0 +1,110 @@ +#!/usr/bin/env bash +set -e + +if [[ ! -d tools ]] ; then + printf "This script needs to be run from the root of the repo, like ./tools/travis-setup\n" + exit 1 +fi + +mkdir -p tools/downloads +mkdir -p tools/cross/bin +mkdir -p dist + +export PATH="$(pwd)/tools/cross/bin:$PATH" + +targets=( +'x86_64-linux-musl' +'i486-linux-musl' +'aarch64-linux-musl' +'arm-linux-musleabi' +'arm-linux-musleabihf' +'powerpc64le-linux-musl' +) + +declare -A target_short +target_short[x86_64-linux-musl]="amd64" +target_short[i486-linux-musl]="x86" +target_short[aarch64-linux-musl]="aarch64" +target_short[arm-linux-musleabi]="arm" +target_short[arm-linux-musleabihf]="armhf" +target_short[powerpc64le-linux-musl]="ppc64le" + +declare -A versions +versions[justc-forstdin]=$(grep version package/info | cut -d'=' -f2) + +skaware_release=v2.0.7 +musl_make_release=v15 +gccver=7.3.0 + +musl_cross_make="https://github.com/just-containers/musl-cross-make/releases/download/$musl_make_release" +skaware="https://github.com/just-containers/skaware/releases/download/$skaware_release" + +manifesturl="$skaware/manifest.txt" +rm -f "tools/downloads/manifest.txt" +curl -s -R -L -o "tools/downloads/manifest.txt" "$manifesturl" + +while read -r line ; do + key=$(printf "${line}" | cut -d"=" -f1) + value=$(printf "${line}" | cut -d"=" -f2) + if [[ -n "${key}" && -n "${value}" ]] ; then + versions[$key]="$value" + fi +done < tools/downloads/manifest.txt + + +for target in "${targets[@]}" ; do + gccurl="$musl_cross_make/gcc-${gccver}-${target}.tar.xz" + gccfile=$(basename $gccurl) + if [[ ! -f "tools/downloads/$gccfile" ]] ; then + printf "Downloading tools/downloads/$gccfile\n" + curl -s -R -L -o "tools/downloads/$gccfile" "$gccurl" + fi + skawareurl="$skaware/skalibs-${versions[skalibs]}-linux-${target_short[$target]}-dev.tar.gz" + skafile=$(basename $skawareurl) + if [[ ! -f "tools/downloads/$skafile" ]] ; then + printf "Downloading tools/downloads/$skafile\n" + curl -s -R -L -o "tools/downloads/$skafile" "$skawareurl" + fi + + execlineurl="$skaware/execline-${versions[execline]}-linux-${target_short[$target]}-dev.tar.gz" + execlinefile=$(basename $execlineurl) + if [[ ! -f "tools/downloads/$execlinefile" ]] ; then + printf "Downloading tools/downloads/$execlinefile\n" + curl -s -R -L -o "tools/downloads/$execlinefile" "$execlineurl" + fi + + tar xf "tools/downloads/$gccfile" -C tools/cross + tar xf "tools/downloads/$skafile" -C tools/cross/${target} --strip-components=1 + tar xf "tools/downloads/$execlinefile" -C tools/cross/${target} --strip-components=1 + + mkdir -p dist/${target} + + CFLAGS="-g0 -Os" \ + ./configure \ + --target=$target \ + --prefix=/usr \ + --with-include=$(pwd)/tools/cross/${target}/include \ + --with-lib=$(pwd)/tools/cross/${target}/lib \ + --with-sysdeps=$(pwd)/tools/cross/${target}/lib/skalibs/sysdeps \ + --enable-static-libc + make + ${target}-strip justc-forstdin + make DESTDIR=dist/${target} install + make clean + rm -rf dist/${target}/usr/include + + printf "Making tarball for $target\n" + tar cvzf dist/justc-forstdin-${versions[justc-forstdin]}-linux-${target_short[$target]}.tar.gz \ + -C dist/${target} \ + --owner 0 \ + --group 0 \ + usr +done + +printf 'Built using `skalibs-%s`\n' "${versions[skalibs]}" > dist/release.md + +printf 'Compiling source tarball\n' + +make tgz +cp /tmp/justc-forstdin-${versions[justc-forstdin]}.tar.gz dist/ + diff --git a/.github/release b/.github/release new file mode 100755 index 0000000..94a9645 --- /dev/null +++ b/.github/release @@ -0,0 +1,62 @@ +#!/usr/bin/env bash +set -e + +# don't loop if files don't exist +shopt -s nullglob + +mkdir -p tools/downloads +mkdir -p tools/cross/bin + +if [[ ! -f "tools/downloads/linux-amd64-github-release.bz2" ]] ; then + printf "Downloading tools/downloads/linux-amd64-github-release.bz2\n" + curl -s -R -L -o "tools/downloads/linux-amd64-github-release.bz2" \ + "https://github.com/github-release/github-release/releases/download/v0.8.1/linux-amd64-github-release.bz2" +fi + +bunzip2 "tools/downloads/linux-amd64-github-release.bz2" +mv "tools/downloads/linux-amd64-github-release" "tools/cross/bin/github-release" +chmod +x "tools/cross/bin/github-release" + +export PATH="$(pwd)/tools/cross/bin:$PATH" + +if [[ ! -d dist ]] ; then + printf "This needs to be run from the root of the repo\n" + exit 1 +fi + +# exit if TRAVIS_TAG is empty, no need to release anything +if [ -z "${TRAVIS_TAG}" ]; then + exit 0 +fi + +export "PATH=$(pwd)/tools/cross/bin:$PATH" + +# get user and repo names +USERNAME=$(echo ${TRAVIS_REPO_SLUG} | cut -d"/" -f1) +REPONAME=$(echo ${TRAVIS_REPO_SLUG} | cut -d"/" -f2) + +# release +github-release release \ + --user "${USERNAME}" \ + --repo "${REPONAME}" \ + --tag "${TRAVIS_TAG##*/}" \ + --name "${TRAVIS_TAG##*/}" \ + --description "$(cat $(pwd)/dist/release.md)" || true + +# binaries +for i in "$(pwd)/dist/"*.tar.gz; do + name=$(basename ${i}) + gpg -u 0x3B2FD161 --output "${i}.sig" --detach-sig "${i}" + github-release upload \ + --user "${USERNAME}" \ + --repo "${REPONAME}" \ + --tag "${TRAVIS_TAG##*/}" \ + --name "${name}" \ + --file "${i}" + github-release upload \ + --user "${USERNAME}" \ + --repo "${REPONAME}" \ + --tag "${TRAVIS_TAG##*/}" \ + --name "${name}.sig" \ + --file "${i}.sig" +done diff --git a/.github/workflows/all.yml b/.github/workflows/all.yml new file mode 100644 index 0000000..2aa30f3 --- /dev/null +++ b/.github/workflows/all.yml @@ -0,0 +1,57 @@ +on: [push, pull_request] + +jobs: + build: + name: Build + runs-on: ubuntu-latest + steps: + - name: checkout code + uses: actions/checkout@v2 + + - name: build + run: .github/build + + - name: upload artifacts + uses: actions/upload-artifact@v2 + with: + name: dist + path: | + dist/*.tar.gz + dist/*.md + + release: + name: Release + runs-on: ubuntu-latest + needs: build + if: startsWith(github.ref, 'refs/tags/v') + steps: + - name: checkout code + uses: actions/checkout@v2 + + - name: download artifacts + uses: actions/download-artifact@v2 + with: + name: dist + path: dist + + - name: decrypt signing keys + env: + OPENSSL_KEY: ${{ secrets.OPENSSL_KEY }} + OPENSSL_IV: ${{ secrets.OPENSSL_IV }} + run: openssl aes-256-cbc -K $OPENSSL_KEY -iv $OPENSSL_IV -in tools/keys.tar.xz.enc -out tools/keys.tar.xz -d + + - name: extract signing keys + run: tar xf tools/keys.tar.xz -C tools + + - name: import public key + run: gpg --import tools/keys/public.key + + - name: import private key + run: gpg --allow-secret-key-import --import tools/keys/private.key + + - name: create and upload release + run: .github/release + env: + TRAVIS_REPO_SLUG: just-containers/justc-forstdin + TRAVIS_TAG: ${{ github.ref }} + GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..51d59fb --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +/config.mak +/justc-forstdin +*.o +/src/include/justc-forstdin/config.h +/tools/downloads +/tools/cross +/dist diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..ba62ea8 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,16 @@ +Internet Systems Consortium license +=================================== + +Copyright (c) `2021`, `Laurent Bercot `, `John Regan ` + +Permission to use, copy, modify, and/or 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..8c86a1b --- /dev/null +++ b/Makefile @@ -0,0 +1,151 @@ +# +# This Makefile requires GNU make. +# +# Do not make changes here. +# Use the included .mak files. +# + +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) +REALCC = $(CROSS_COMPILE)$(CC) +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) $(EXTRA_TARGETS) + +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=.travis* --exclude=dist --exclude=tools/cross --exclude=tools/downloads --exclude=tools/travis* --exclude=tools/keys* --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 -R .note.GNU-stack $(STATIC_LIBS) +endif +ifneq ($(strip $(ALL_BINS)$(SHARED_LIBS)),) + exec $(STRIP) -R .note -R .comment -R .note.GNU-stack $(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)/%) +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/%) + +$(DESTDIR)$(sproot)/command/%: $(DESTDIR)$(home)/command/% + exec $(INSTALL) -D -l ..$(subst $(sproot),,$(exthome))/command/$( +# +# 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. + + +. package/info + +usage () { +cat </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 /dev/null "$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 /dev/null "$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 -D_BSD_SOURCE -iquote src/include-local -Isrc/include" +CPPFLAGS_POST="$CPPFLAGS" +CPPFLAGS= +CFLAGS_AUTO="-pipe -Wall -Wextra" +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' +sysdeps='$prefix/lib/skalibs/sysdeps' +manualsysdeps=false +shared=false +static=true +allpic=detect +slashpackage=false +abspath=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#*=} ;; + --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-*|--disable-*|--with-*|--without-*|--*dir=*) ;; + --host=*|--target=*) target=${arg#*=} ;; + --build=*) build=${arg#*=} ;; + -* ) echo "$0: unknown option $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 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" + tmpe="./tmp-configure-$$-$PPID-$i.tmp" + 2>|/dev/null > "$tmpc" && break + 2>|/dev/null > "$tmpe" && break + test "$i" -gt 50 && fail "$0: cannot create temporary files" +done +set +C +trap 'rm -f "$tmpc" "$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=${sproot}/package/prog/skalibs/sysdeps + fi + extbinprefix=${exthome}/command + dynlibdir=${home}/library.so + bindir=${home}/command + libdir=${home}/library + libexecdir=$bindir + includedir=${home}/include + while read dep ; do + addincpath="$addincpath -I${sproot}${dep}/include" + vpaths="$vpaths ${sproot}${dep}/library" + addlibspath="$addlibspath -L${sproot}${dep}/library" + vpathd="$vpathd ${sproot}${dep}/library.so" + addlibdpath="$addlibdpath -L${sproot}${dep}/library.so" + 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 ${cross}${CC} +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 /dev/null "$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 test $allpic = detect ; then + echo "Checking whether we need to build everything as PIC..." + if $CC_AUTO $CPPFLAGS_AUTO $CPPFLAGS $CPPFLAGS_POST $CFLAGS_AUTO $CFLAGS $CFLAGS_POST -dM -E - < /dev/null | grep -qF __PIE__ ; then + allpic=true + echo " ... yes" + else + allpic=false + echo " ... no" + fi +fi +if $allpic ; then + tryflag CFLAGS_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 CFLAGS_AUTO -Wa,--noexecstack +tryflag CFLAGS -fno-stack-protector +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 $allstatic ; then + LDFLAGS_NOSHARED="${LDFLAGS_NOSHARED}${addlibspath}" + tryldflag LDFLAGS_NOSHARED -Wl,--gc-sections +else + LDFLAGS_NOSHARED="${LDFLAGS_NOSHARED}${addlibdpath}" +fi + +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 + +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##${cross}} +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 + +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 <&3 3>&- +echo " ... done." diff --git a/package/deps-build b/package/deps-build new file mode 100644 index 0000000..a966904 --- /dev/null +++ b/package/deps-build @@ -0,0 +1,2 @@ +/package/prog/skalibs +/package/admin/execline diff --git a/package/deps.mak b/package/deps.mak new file mode 100644 index 0000000..77f6e8c --- /dev/null +++ b/package/deps.mak @@ -0,0 +1,8 @@ +# +# This file has been generated by tools/gen-deps.sh +# + +src/justc-forstdin/justc-forstdin.o src/justc-forstdin/justc-forstdin.lo: src/justc-forstdin/justc-forstdin.c + +justc-forstdin: EXTRA_LIBS := +justc-forstdin: src/justc-forstdin/justc-forstdin.o -lexecline -lskarnet diff --git a/package/info b/package/info new file mode 100644 index 0000000..8d6fd21 --- /dev/null +++ b/package/info @@ -0,0 +1,4 @@ +package=justc-forstdin +version=1.0.0 +category=admin +package_macro_name=JUSTC_FORSTDIN diff --git a/package/modes b/package/modes new file mode 100644 index 0000000..658a5d8 --- /dev/null +++ b/package/modes @@ -0,0 +1 @@ +justc-forstdin 0755 diff --git a/package/targets.mak b/package/targets.mak new file mode 100644 index 0000000..b3235de --- /dev/null +++ b/package/targets.mak @@ -0,0 +1,4 @@ +BIN_TARGETS := justc-forstdin +LIBEXEC_TARGETS := + + diff --git a/src/justc-forstdin/deps-exe/justc-forstdin b/src/justc-forstdin/deps-exe/justc-forstdin new file mode 100644 index 0000000..8c3ba3b --- /dev/null +++ b/src/justc-forstdin/deps-exe/justc-forstdin @@ -0,0 +1,2 @@ +-lexecline +-lskarnet diff --git a/src/justc-forstdin/justc-forstdin.c b/src/justc-forstdin/justc-forstdin.c new file mode 100644 index 0000000..c228840 --- /dev/null +++ b/src/justc-forstdin/justc-forstdin.c @@ -0,0 +1,159 @@ +/* ISC license. */ + +/* copied and modified from upstream forstdin: + * no checking for EOF (just return 0 on an empty file) + * use skagetlnsep_loose to ensure final line (possibly missing null) is called + */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#define USAGE "forstdin [ -E | -e ] [ -p | -o okcode,okcode,... | -x breakcode,breakcode,... ] [ -N | -n ] [ -C | -c ] [ -0 | -d delim ] var command..." +#define dieusage() strerr_dieusage(100, USAGE) + +static genalloc pids = GENALLOC_ZERO ; /* pid_t */ + +static int isok (unsigned short *tab, unsigned int n, int code) +{ + unsigned int i = 0 ; + for (; i < n ; i++) if ((unsigned short)code == tab[i]) break ; + return i < n ; +} + +static void parallel_sigchld_handler (int sig) +{ + pid_t *tab = genalloc_s(pid_t, &pids) ; + size_t len = genalloc_len(pid_t, &pids) ; + int wstat ; + for (;;) + { + ssize_t r = wait_pids_nohang(tab, len, &wstat) ; + if (r <= 0) break ; + tab[r-1] = tab[--len] ; + } + genalloc_setlen(pid_t, &pids, len) ; + (void)sig ; +} + +int main (int argc, char const **argv) +{ + stralloc value = STRALLOC_ZERO ; + char const *delim = "\n" ; + size_t delimlen = 1 ; + size_t nbc = 0 ; + unsigned short okcodes[256] ; + int crunch = 0, chomp = 1, not = 1, doimport = 0 ; + PROG = "forstdin" ; + { + subgetopt l = SUBGETOPT_ZERO ; + for (;;) + { + int opt = subgetopt_r(argc, argv, "pNnCc0d:o:x:Ee", &l) ; + if (opt == -1) break ; + switch (opt) + { + case 'p' : + { + if (!genalloc_ready(pid_t, &pids, 1)) + strerr_diefu1sys(111, "genalloc_ready") ; + break ; + } + case 'N' : chomp = 0 ; break ; + case 'n' : chomp = 1 ; break ; + case 'C' : crunch = 1 ; break ; + case 'c' : crunch = 0 ; break ; + case '0' : delim = "" ; delimlen = 1 ; break ; + case 'd' : delim = l.arg ; delimlen = strlen(delim) ; break ; + case 'o' : + not = 0 ; + if (!ushort_scanlist(okcodes, 256, l.arg, &nbc)) dieusage() ; + break ; + case 'x' : + not = 1 ; + if (!ushort_scanlist(okcodes, 256, l.arg, &nbc)) dieusage() ; + break ; + case 'E' : doimport = 1 ; break ; + case 'e' : doimport = 0 ; break ; + default : dieusage() ; + } + } + argc -= l.ind ; argv += l.ind ; + } + if (argc < 2) dieusage() ; + if (!argv[0][0] || strchr(argv[0], '=')) strerr_dief1x(100, "invalid variable name") ; + + if (pids.s) + { + if (!sig_catch(SIGCHLD, ¶llel_sigchld_handler)) + strerr_diefu1sys(111, "install SIGCHLD handler") ; + } + for (;;) + { + pid_t pid ; + value.len = 0 ; + if (delimlen) + { + int r = skagetlnsep_loose(buffer_0, &value, delim, delimlen) ; + if (!r) break ; + else if (r < 0) + { + if (errno != EPIPE) strerr_diefu1sys(111, "skagetlnsep") ; + if (chomp) break ; + } + if (crunch && value.len == 1) continue ; + if (chomp) value.len-- ; + } + else + { + size_t unread = 0 ; + if (netstring_get(buffer_0, &value, &unread) <= 0) + { + if (netstring_okeof(buffer_0, unread)) break ; + else strerr_diefu1sys(111, "netstring_get") ; + } + } + if (!stralloc_0(&value)) strerr_diefu1sys(111, "stralloc_0") ; + if (pids.s) sig_block(SIGCHLD) ; + pid = el_modif_and_spawn(argv + 1, argv[0], value.s, doimport) ; + if (!pid) strerr_diefu2sys(111, "spawn ", argv[1]) ; + if (pids.s) + { + if (!genalloc_append(pid_t, &pids, &pid)) + strerr_diefu1sys(111, "genalloc_append") ; + sig_unblock(SIGCHLD) ; + } + else + { + int wstat ; + if (wait_pid(pid, &wstat) < 0) + strerr_diefu2sys(111, "wait for ", argv[1]) ; + if (not == isok(okcodes, nbc, wait_estatus(wstat))) + return wait_estatus(wstat) ; + } + } + if (pids.s) + { + sigset_t empty ; + sigemptyset(&empty) ; + sig_block(SIGCHLD) ; + for (;;) + { + if (!pids.len) break ; + sigsuspend(&empty) ; + } + } + return 0 ; +} diff --git a/tools/gen-deps.sh b/tools/gen-deps.sh new file mode 100755 index 0000000..6383ac2 --- /dev/null +++ b/tools/gen-deps.sh @@ -0,0 +1,93 @@ +#!/bin/sh -e + +. package/info + +echo '#' +echo '# This file has been generated by tools/gen-deps.sh' +echo '#' +echo + +for dir in src/include/${package} src/* ; do + for file in $(ls -1 $dir | grep -- \\.h$) ; do + { + grep -F -- "#include <${package}/" < ${dir}/$file | cut -d'<' -f2 | cut -d'>' -f1 ; + grep -- '#include ".*\.h"' < ${dir}/$file | cut -d'"' -f2 + } | sort -u | { + deps= + while read dep ; do + if echo $dep | grep -q "^${package}/" ; then + deps="$deps src/include/$dep" + elif test -f "${dir}/$dep" ; then + deps="$deps ${dir}/$dep" + else + deps="$deps src/include-local/$dep" + fi + done + if test -n "$deps" ; then + echo "${dir}/${file}:${deps}" + fi + } + done +done + +for dir in src/* ; do + for file in $(ls -1 $dir | grep -- \\.c$) ; do + { + grep -F -- "#include <${package}/" < ${dir}/$file | cut -d'<' -f2 | cut -d'>' -f1 ; + grep -- '#include ".*\.h"' < ${dir}/$file | cut -d'"' -f2 + } | sort -u | { + deps=" ${dir}/$file" + while read dep ; do + if echo $dep | grep -q "^${package}/" ; then + deps="$deps src/include/$dep" + elif test -f "${dir}/$dep" ; then + deps="$deps ${dir}/$dep" + else + deps="$deps src/include-local/$dep" + fi + done + o=$(echo $file | sed s/\\.c$/.o/) + lo=$(echo $file | sed s/\\.c$/.lo/) + echo "${dir}/${o} ${dir}/${lo}:${deps}" + } + done +done +echo + +for dir in $(ls -1 src | grep -v ^include) ; do + for file in $(ls -1 src/$dir/deps-lib) ; do + deps= + libs= + while read dep ; do + if echo $dep | grep -q -e ^-l -e '^\${.*_LIB}' ; then + libs="$libs $dep" + else + deps="$deps src/$dir/$dep" + fi + done < src/$dir/deps-lib/$file + echo 'ifeq ($(strip $(STATIC_LIBS_ARE_PIC)),)' + echo "lib${file}.a.xyzzy:$deps" + echo else + echo "lib${file}.a.xyzzy:$(echo "$deps" | sed 's/\.o/.lo/g')" + echo endif + echo "lib${file}.so.xyzzy: EXTRA_LIBS :=$libs" + echo "lib${file}.so.xyzzy:$(echo "$deps" | sed 's/\.o/.lo/g')" + done + + for file in $(ls -1 src/$dir/deps-exe) ; do + deps= + libs= + while read dep ; do + if echo $dep | grep -q -- \\.o$ ; then + dep="src/$dir/$dep" + fi + if echo $dep | grep -q -- '^\${.*_LIB}' ; then + libs="$libs $dep" + else + deps="$deps $dep" + fi + done < src/$dir/deps-exe/$file + echo "$file: EXTRA_LIBS :=$libs" + echo "$file: src/$dir/$file.o$deps" + done +done diff --git a/tools/install.sh b/tools/install.sh new file mode 100755 index 0000000..89f9428 --- /dev/null +++ b/tools/install.sh @@ -0,0 +1,64 @@ +#!/bin/sh + +usage() { + echo "usage: $0 [-D] [-l] [-m mode] src dst" 1>&2 + exit 1 +} + +mkdirp=false +symlink=false +mode=0755 + +while getopts Dlm: name ; do + case "$name" in + D) mkdirp=true ;; + l) symlink=true ;; + m) mode=$OPTARG ;; + ?) usage ;; + esac +done +shift $(($OPTIND - 1)) + +test "$#" -eq 2 || usage +src=$1 +dst=$2 +tmp="$dst.tmp.$$" + +case "$dst" in + */) echo "$0: $dst ends in /" 1>&2 ; exit 1 ;; +esac + +set -C +set -e + +if $mkdirp ; then + umask 022 + case "$2" in + */*) mkdir -p "${dst%/*}" ;; + esac +fi + +trap 'rm -f "$tmp"' EXIT INT QUIT TERM HUP + +umask 077 + +if $symlink ; then + ln -s "$src" "$tmp" +else + cat < "$1" > "$tmp" + chmod "$mode" "$tmp" +fi + +mv -f "$tmp" "$dst" +if test -d "$dst" ; then + rm -f "$dst/$(basename $tmp)" + if $symlink ; then + mkdir "$tmp" + ln -s "$src" "$tmp/$(basename $dst)" + mv -f "$tmp/$(basename $dst)" "${dst%/*}" + rmdir "$tmp" + else + echo "$0: $dst is a directory" 1>&2 + exit 1 + fi +fi diff --git a/tools/keys.tar.xz.enc b/tools/keys.tar.xz.enc new file mode 100644 index 0000000..0c8481b Binary files /dev/null and b/tools/keys.tar.xz.enc differ