#!/bin/sh #-*-mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8-*-┐ #───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘ # # OVERVIEW # # GNU Archiver Veneer # # DESCRIPTION # # This script wraps normal archive commands that're transparently # passed-through. It adds value too, by addressing difficulties # that would normally cause a developer to need `make clean`. # # EXAMPLE # # build/archive ar rcsD library.a foo.o ... if [ ! -d o/third_party/gcc ]; then third_party/gcc/unbundle.sh fi export LC_ALL=C RM=${RM:-$(command -v rm) -f} || exit MKDIR=${MKDIR:-$(command -v mkdir) -p} || exit AR=$1 ARFLAGS=$2 OUT=$3 shift 3 # remove directory arguments (having .a targets depend on dirs is what # lets them be invalidated by deleted files) FIRST=1 for x; do if [ $FIRST -eq 1 ]; then set -- FIRST=0 fi if [ -d "$x" ]; then if [ -f "$OUT" ] && [ "$x" -nt "$OUT" ]; then $RM "$OUT" fi continue fi if [ "$x" != "${x%.o}" ]; then set -- "$@" "$x" fi done set -- "$AR" "$ARFLAGS" "$OUT" "$@" printf %s\\n "$*" >"$OUT.cmd" OUTDIR="${OUT%/*}" if [ "$OUTDIR" != "$OUT" ] && [ ! -d "$OUTDIR" ]; then $MKDIR "$OUTDIR" || exit 2 fi printf "$LOGFMT" "${ACTION:-ARCHIVE.a}" "$OUT" >&2 # if [ "$SILENT" = "0" ]; then # # some of these windows nt archives are quite huge # COLUMNS=${COLUMNS:-80} # COLUMNS=$((COLUMNS - 4)) # printf "%s\n" "$*" | # /usr/bin/fold -s -w $COLUMNS | # sed -e '1bb' -e 's/^/ /' -e ':b' -e '$b' -e 's/$/ \\/' >&2 # else # printf "$LOGFMT" "${ACTION:-ARCHIVE.a}" "$OUT" >&2 # fi REASON=failed trap REASON=interrupted INT "$@" >/dev/null && exit if [ "$TERM" = "dumb" ]; then f='%s %s\r\n\r\n' else f='\033[91m%s\033[39m \033[94m%s\033[39m\r\n\r\n' fi printf "$f" "archive $REASON:" "$*" >&2 exit 1