view ibmscripts/cc @ 24:a4899cdfc2d6 default tip

Obfuscate the regexps to strip off the IBM compiler's copyright banners. I don't want bots scanning github to think they're real copyright notices because that could cause real problems.
author David A. Holland
date Mon, 13 Jun 2022 00:40:23 -0400
parents 13d2b8934445
children
line wrap: on
line source

#!/bin/sh
# cc - wrap the IBM compiler to look sort of like a unix compiler
#      (and also to tidy up its output)
# usage: cc [opts] sourcefile
# options:
#     -g	debug
#     -O	optimize
#     -fPIC	generate shared library code
#     -Dsym	define preprocessor symbol SYM
#     -Idir	add include path
#     -c	compile only and don't link (required and assumed)
#     -v	verbose
#
# Note that the behavior of -D is limited by the ability of the shell
# to handle embedded spaces. It's meant to be only used in the style
# "-DFOO".
#

OPT=nil
SHLIB=
ADDINC=
FILE=
DEFS=
QUIET=1

while [ x"$1" != x ]; do
    case "$1" in
	-g) OPT=debug;;
	-O*) OPT=opt;;
	-fPIC) SHLIB=/Ge-;;
	-I*) ADDINC="${ADDINC};`echo "$1" | sed 's/^-I//'`";;
	-D*) DEFS="$DEFS `echo "$1" | sed 's,^-D,/D,'`";;
	-c) ;;
	-v) QUIET=0;;
	-*)
	    echo "$0: unknown option $1" 1>&2
	    exit 1
	;;
	*) FILE="$1";;
    esac
shift
done

if [ x"$FILE" = x ]; then
    echo "$0: usage: $0 [options] sourcefile" 1>&2
    exit 1
fi

INCLUDE='I:\\ibmcppw\\bindings;I:\\ibmcppw\\include;I:\\ibmcppw\\sdk\\winh;I:\\ibmcppw\\sdk\\winh\\winnt;I:\\ibmcppw\\sdk\\winh\\win95;I:\\ibmcppw\\lib;I:\\ibmcppw\\sdk\\lib'
export INCLUDE

case "$ADDINC" in
    \;*) ADDINC=`echo "$ADDINC" | sed 's,^;,/I,'`;;
    *) ;;
esac

#
# Used to use /O /Oc to optimize for size instead of speed
# (doubtless because of the ship-on-a-floppy size limit)
# For now I'm going to leave that off.
#
case "$OPT" in
    nil) OPT=;;
    debug) OPT="/Ti";;
    opt) OPT="/O /Oc /Ti-";;
esac


# try:
#     all+cls+cmp+cnd+cns+cnv+cpy+dcl+eff+enu+ext+gen+gnr+inl+lan
#     obs+ord+par+por+ppc+pro+trd+tru+und+vft
#
# /Wgot?
WARN='/Wini+rea+ret+uni+use'

# /Sc seems like it would be a good idea but doesn't work...

WINEPATH='I:\\ibmcppw\\bin'
export WINEPATH

LOG=`basename $FILE | sed 's/\.[a-z]*$//;s/$/.log/'`

if [ $QUIET = 0 ]; then
    echo wine 'I:\\ibmcppw\\bin\\icc.exe' "$ADDINC" /qmakedep /qtune=pentium \
	/J- /Gl /Gm /Gu+ $DEFS $WARN $OPT $SHLIB \
	/C "$FILE" '|' tee "$LOG"
fi

(
    wine 'I:\\ibmcppw\\bin\\icc.exe' "$ADDINC" /qmakedep /qtune=pentium \
	/J- /Gl /Gm /Gu+ $DEFS $WARN $OPT $SHLIB \
	/C "$FILE"
    echo "@@@Exit $?"
) 2>&1 | tr -d '\r' | tee "$LOG" | (
    if [ $QUIET = 1 ]; then
      #
      # The compiler prints its copyright banner every time you run
      # it, that is, on every file, and there's apparently no way to
      # fully suppress this.  So, since this is extremely annoying and
      # interferes with development, delete the strings from the
      # output. Obfuscate the regexps slightly, because I want them
      # to be precise (no other messages should be suppressed) but I
      # also don't want to be harassed by source-scanning bots or
      # (perhaps) clueless lawyers that think they're actual IBM
      # copyright notices. I wrote this script; it's not IBM's.
      #
      sed '
        /^[I][B][M](.) VisualAge(..) for C++ for Windows(.), Version 3\.5$/d
        /^- [L]icensed [M]aterials - Program-[P]roperty of [I][B][M]$/d
        /^(.) [C]opyright [I][B][M] [C]orp. 1991, 1996 - [A]ll [R]ights [R]eserved.$/d
      '
    else
      cat
    fi
) | awk '
    /^@@@Exit [0-9][0-9]*$/ { exit($2); }

    /^%0$/ { next; }
    /^$/ { next; }
    /%0$/ { sub("%0$", "", $0); printf "%s", $0; needeol=1; next; }
    { print; needeol=0; }
    END { if (needeol) printf "\n"; }

' "q=$QUIET"