view ibmscripts/ldcc @ 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
# ldcc - wrap the IBM compiler to look sort of like a unix compiler
# (for linking programs)
# usage: ldcc [opts] objectfiles -o output
# options:
#     -v	verbose
#

QUIET=1

while [ x"$1" != x ]; do
    case "$1" in
	-o) OUTPUT="$2"; shift;;
	-o*) OUTPUT=`echo "$1" | sed 's/^-o//'`;;
	-v) QUIET=0;;
	-*)
	    echo "$0: unknown option $1" 1>&2
	    exit 1
	;;
	*.dll) FILES="$FILES `echo $1 | sed 's/\.dll$/.lib/'`";;
	*) FILES="$FILES $1";;
    esac
shift
done

LIB='I:\\ibmcppw\\lib;I:\\ibmcppw\\sdk\\lib'
export LIB

case x"$OUTPUT" in
    x*.exe) ;;
    x) echo "$0: Usage: $0 [options] files -o output" 1>&2; exit 1;;
    *) echo "$0: output file must be an EXE" 1>&2; exti 1;;
esac

MAPFILE=`echo "$OUTPUT" | sed 's/\.exe$/.map/'`
LOGFILE=`echo "$OUTPUT" | sed 's/\.exe$/.log/'`

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

# note: this must be ilink354, not the latest patchlevel, as the latest
# one apparently doesn't work right in wine.

# In the older makefiles, ag.exe is linked with /B"PM:PM", and agcl.exe
# isn't. According to documentation I just found on the web (1/1/06) this
# means "PMTYPE" and sets the type of application with respect to the OS/2
# Presentation Manager. Apparently PM means it *is* a Presentation Manager
# application. You can also set it to "VIO" or "NOVIO" for whether it's
# visually compatible (or something like that) with the Presentation Manager.
# I strongly suspect that under Windows this has no effect and it's a 
# leftover from when we were using the OS/2 version of this compiler.
# So I'm leaving it out.

# 4/1/06 I'm putting /B"PM:PM" in, unconditionally, for now, just in case.

# /Gm is like -thread.
# /Q+ suppresses the copyright notice.

if [ $QUIET = 0 ]; then
    echo wine 'I:\\ibmcppw\\bin\\icc.exe' /Gm '/B"PM:PM"' /Q+ \
	/Fm$MAPFILE /Fe$OUTPUT $FILES '|' tee "$LOGFILE"
fi

(
    wine 'I:\\ibmcppw\\bin\\icc.exe' /Gm '/B"PM:PM"' /Q+ \
	/Fm$MAPFILE /Fe$OUTPUT $FILES
    echo "@@@Exit $?"
) 2>&1 | tr -d '\r' | tee "$LOGFILE" | (
    if [ $QUIET = 1 ]; then
      #
      # The compiler prints its copyright banner every time you run
      # it, and there's apparently no way to fully suppress this.
      # (That is, I think the /Q+ flag above silences some messages
      # but not all of them.) 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. (Or Microsoft's,
      # either.)
      #
      # Note that the strings with the first character missing are not
      # an accident. That actually happens.
      #
      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
	/^[B][M](.) Linker for Windows(.), %0$/d
	/^ersion 02.01.r2a_WTC354e *$/d
	/^[o]pyright (.) [I][B][M] [C]orporation 1988, 1998\.$/d
	/^[C]opyright (.) [M]icrosoft [C]orp\. 1988, 1989\.$/d
	/^[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"