1: mvs.390 cc wrapper for unix message and exit code semantics : 2009-01-30 : 2 3HOSTTYPE=mvs.390 4 5case " $* " in 6*" -dumpmachine "*) echo $HOSTTYPE; exit ;; 7esac 8 9ar=ar 10cc=/bin/c89 11CC=/bin/c++ 12ccflags="-D_ALL_SOURCE -Wc,dll" 13objmax=60 14tmpfiles= 15unbotch= 16 17# -n as *first* arg shows but does not do 18# -Wc,exportall => -Wl,dll 19# -Bdynamic => .c,.o dynamic 20# -Bstatic => .c,.o static 21# *.C => cc=$CC 22# *.cpp => cc=$CC 23# *.cxx => cc=$CC 24# no optimization until the optimizer is fixed: 25# -O dropped (no optimization) 26# -0 dropped (no optimization) 27# -1 -O (default level 1 optimization) 28# -2 -2 (maximal level 2 optimization) 29 30let argc=0 cmp=0 dll=0 libc=0 dynamic=1 dynamic_objc=0 static_objc=0 relc=0 botched=0 31case $1 in 32-n) exec=print 33 shift 34 ;; 35*) exec= 36 ;; 37esac 38export _CC_ACCEPTABLE_RC=1 39export _C89_ACCEPTABLE_RC=$_CC_ACCEPTABLE_RC 40export _CXX_ACCEPTABLE_RC=$_CC_ACCEPTABLE_RC 41case " $* " in 42*.C" "*)let dll=2 43 cc=$CC 44 export _CXXSUFFIX=C 45 ;; 46*.cpp" "*)let dll=2 47 cc=$CC 48 export _CXXSUFFIX=cpp 49 ;; 50*.cxx" "*)let dll=2 51 cc=$CC 52 export _CXXSUFFIX=cxx 53 ;; 54esac 55exe= 56xxx= 57while : 58do case $# in 59 0) break ;; 60 esac 61 arg=$1 62 case $arg in 63 -1) arg=-O 64 ;; 65 -Bdynamic) 66 let dynamic=1 67 ;; 68 -Bstatic) 69 let dynamic=0 70 ;; 71 -c) let cmp=1 72 ;; 73 -D_ALL_SOURCE|-D_ALL_SOURCE=*) 74 arg= 75 ;; 76 -D*[\ \(\)]*) 77 arg=${arg#-D} 78 botch_macro[botched]=${arg%%=*} 79 botch_value[botched]=${arg#*=} 80 let botched=botched+1 81 arg= 82 ;; 83 -o) argv[argc]=$arg 84 let argc=argc+1 85 shift 86 arg=$1 87 exe=$arg 88 rm -f "$exe" 89 ;; 90 -[O0]) arg= 91 ;; 92 -Wc,dll)arg= 93 ;; 94 -Wc,exportall) 95 let dll=1 96 ;; 97 -Wl,dll)arg= 98 let dll=1 99 ;; 100 *.c) if [[ $botched != 0 ]] 101 then src=$arg 102 arg=${arg##*/} 103 unbotch="$unbotch ${arg%.c}.o" 104 arg=__$arg 105 tmpfiles="$tmpfiles $arg" 106 { 107 while [[ $botched != 0 ]] 108 do let botched=botched-1 109 print -r -- "#define ${botch_macro[botched]} ${botch_value[botched]}" 110 done 111 cat $src 112 } > $arg 113 fi 114 ;; 115 *.o) if test 0 != $dynamic 116 then let dynamic_objc=dynamic_objc+1 117 else let static_objc=static_objc+1 118 fi 119 ;; 120 *.x) a=${arg%.x}.a 121 if test -f $a 122 then argv[argc]=$a 123 let argc=argc+1 124 xxx=-Wl,dll 125 case $a in 126 ast.a|*/ast.a) 127 cc="$CC -u_ast_init" 128 ;; 129 esac 130 fi 131 ;; 132 esac 133 case $arg in 134 ?*) argv[argc]=$arg 135 let argc=argc+1 136 ;; 137 esac 138 shift 139done 140 141tmp=/tmp/cc$$.err 142tmpfiles="$tmp $tmpfiles" 143 144# if any dll .o's are in .a then a .x gets generated 145# but the native cc doesn't jcl for the .x 146# -Wl,dll does that, so we nuke the .x and keep the exe 147 148test 0 != $dll && xxx= 149case $xxx in 150?*) case $exe in 151 ?*) a=${exe##*/} 152 a=${a%.*} 153 case $exe in 154 */*) tmpfiles="$tmpfiles ${exe%/*}/${a}.x" ;; 155 *) tmpfiles="$tmpfiles ${a}.x" ;; 156 esac 157 ;; 158 esac 159 ;; 160esac 161if test 0 != $dll 162then if test 0 != $cmp 163 then xxx="-D_SHARE_EXT_VARS $xxx" 164 else xxx="-Wl,dll $xxx" 165 fi 166fi 167set -- $xxx "${argv[@]}" 168 169# can't handle more than objmax .o's 170# -r into intermediates doesn't work, but the cat trick does 171# also, the runtime dll file must be executable but cc -Wl,dll forgets 172 173if test 0 != $dll -a \( $dynamic_objc -ge $objmax -o 0 != $static_objc \) 174then unset argv 175 argc=0 libc=0 dynamic=1 dynamic_objc=0 static_objc=0 endc=0 176 while : 177 do case $# in 178 0) break ;; 179 esac 180 case $1 in 181 -Bdynamic) 182 let dynamic=1 183 ;; 184 -Bstatic) 185 let dynamic=0 186 ;; 187 *.o) if test 0 != $dynamic 188 then dynamic_objv[dynamic_objc]=$1 189 let dynamic_objc=dynamic_objc+1 190 else static_objv[static_objc]=$1 191 let static_objc=static_objc+1 192 fi 193 ;; 194 -l*) libv[libc]=$1 195 let libc=libc+1 196 ;; 197 -o) argv[argc]=$1 198 let argc=argc+1 199 shift 200 argv[argc]=$1 201 let argc=argc+1 202 exe=$1 203 ;; 204 *) argv[argc]=$1 205 let argc=argc+1 206 ;; 207 esac 208 shift 209 done 210 if test 0 != $static_objc 211 then case $exe in 212 ?*) $exec $ar cr ${exe%.*}.a "${static_objv[@]}" ;; 213 esac 214 fi 215 if test 0 != $dynamic_objc 216 then cat=0.0.o 217 tmpfiles="$tmpfiles $cat" 218 cat "${dynamic_objv[@]}" > $cat || exit 219 else cat= 220 fi 221 set -- "${argv[@]}" $cat "${libv[@]}" 222fi 223 224# grep through the warning/error messages to get the true exit code 225# some annoying messages are dropped while we're at it 226 227trap 'rm -f $tmpfiles' 0 1 2 15 228$exec $cc $ccflags "$@" 2> $tmp 229code=$? 230for i in $unbotch 231do test -f __$i && mv __$i $i 232done 233typeset -l lc 234while : 235do if read line 236 then lc=$line 237 case $lc in 238 *'#include file'*'not found'*) 239 code=1 240 ;; 241 *'#pragma ignored'*) 242 continue 243 ;; 244 *'definition side file is not defined'*) 245 continue 246 ;; 247 *'step ended with return code 4'*) 248 code=0 249 continue 250 ;; 251 *'step ended with return code'*) 252 code=1 253 continue 254 ;; 255 *'try again'*) 256 code=1 257 continue 258 ;; 259 *'unknown preprocessing directive'*) 260 code=1 261 case $lc in 262 'warning '*) 263 set -- $line 264 shift 265 line=$* 266 ;; 267 esac 268 ;; 269 *'unresolved writable static references are detected'*) 270 test 0 != $dll && continue 271 ;; 272 esac 273 else case $code:$exe in 274 0:?*) $exec chmod +x $exe ;; 275 esac 276 exit $code 277 fi 278 echo "$line" >&2 279done < $tmp 280