xref: /aoo41x/main/soltools/testhxx/create.pl (revision 7e90fac2)
1*7e90fac2SAndrew Rist#**************************************************************
2*7e90fac2SAndrew Rist#
3*7e90fac2SAndrew Rist#  Licensed to the Apache Software Foundation (ASF) under one
4*7e90fac2SAndrew Rist#  or more contributor license agreements.  See the NOTICE file
5*7e90fac2SAndrew Rist#  distributed with this work for additional information
6*7e90fac2SAndrew Rist#  regarding copyright ownership.  The ASF licenses this file
7*7e90fac2SAndrew Rist#  to you under the Apache License, Version 2.0 (the
8*7e90fac2SAndrew Rist#  "License"); you may not use this file except in compliance
9*7e90fac2SAndrew Rist#  with the License.  You may obtain a copy of the License at
10*7e90fac2SAndrew Rist#
11*7e90fac2SAndrew Rist#    http://www.apache.org/licenses/LICENSE-2.0
12*7e90fac2SAndrew Rist#
13*7e90fac2SAndrew Rist#  Unless required by applicable law or agreed to in writing,
14*7e90fac2SAndrew Rist#  software distributed under the License is distributed on an
15*7e90fac2SAndrew Rist#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*7e90fac2SAndrew Rist#  KIND, either express or implied.  See the License for the
17*7e90fac2SAndrew Rist#  specific language governing permissions and limitations
18*7e90fac2SAndrew Rist#  under the License.
19*7e90fac2SAndrew Rist#
20*7e90fac2SAndrew Rist#**************************************************************
21*7e90fac2SAndrew Rist
22*7e90fac2SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir$solarversion = $ENV{SOLARVERSION};
25cdf0e10cSrcweir$solarversion =~ s![^0-9A-Za-z]!\\$&!g;
26cdf0e10cSrcweir$in = <> || die 'no input';
27cdf0e10cSrcweirchomp $in;
28cdf0e10cSrcweirif ($ENV{OS} eq 'LINUX') {
29cdf0e10cSrcweir    1 while $in =~ s!\s+-I\s*[^/]\S*\s*! !g; # discard relative includes
30cdf0e10cSrcweir    $in =~ s!(\s+-I\s*)$solarversion(\S*)!$1\${SOLARVERSION}$2!og;
31cdf0e10cSrcweir        # macrofy includes to solver
32cdf0e10cSrcweir    $in =~ s!\s+-o\s*\S+! -o /dev/null! || die 'bad input: no -o';
33cdf0e10cSrcweir    $in =~ s!\S+/testhxx.cxx!-x c++ /proc/self/fd/0!
34cdf0e10cSrcweir        || die 'bad input: no source file';
35cdf0e10cSrcweir    print STDOUT '#!/bin/bash', "\n";
36cdf0e10cSrcweir    print STDOUT $in,
37cdf0e10cSrcweir        ' <<<"#include \\"`echo $(if [ ${1%/*} != $1 ];then cd ${1%/*};fi;',
38cdf0e10cSrcweir        '/bin/pwd)/${1##*/}`\\""', "\n";
39cdf0e10cSrcweir} elsif ($ENV{OS} eq 'SOLARIS') {
40cdf0e10cSrcweir    1 while $in =~ s!\s+-I\s*[^/]\S*\s*! !g; # discard relative includes
41cdf0e10cSrcweir    $in =~ s!(\s+-I\s*)$solarversion(\S*)!$1\${SOLARVERSION}$2!og;
42cdf0e10cSrcweir        # macrofy includes to solver
43cdf0e10cSrcweir    $in =~ s!\s+-o\s*\S+! -o /dev/null! || die 'bad input: no -o';
44cdf0e10cSrcweir    $in =~ s!\S+/testhxx.cxx!\${my_tmp}!
45cdf0e10cSrcweir        || die 'bad input: no source file';
46cdf0e10cSrcweir    print STDOUT '#!/bin/sh', "\n";
47cdf0e10cSrcweir    print STDOUT
48cdf0e10cSrcweir        'my_tmp=${TMPDIR:-/tmp}/`/usr/xpg4/bin/id -u`_$$_include.cc', "\n";
49cdf0e10cSrcweir    print STDOUT 'my_pat=`dirname $1`', "\n";
50cdf0e10cSrcweir    print STDOUT 'my_fil=`basename $1`', "\n";
51cdf0e10cSrcweir    print STDOUT 'my_org=${PWD}', "\n";
52cdf0e10cSrcweir    print STDOUT 'cd $my_pat || exit 1', "\n";
53cdf0e10cSrcweir    print STDOUT 'my_pat=`pwd`', "\n";
54cdf0e10cSrcweir    print STDOUT 'cd $my_org || exit 1', "\n";
55cdf0e10cSrcweir    print STDOUT
56cdf0e10cSrcweir        'echo "#include \\"${my_pat}/${my_fil}\\"" > ${my_tmp} || exit 1', "\n";
57cdf0e10cSrcweir    print STDOUT $in, ' > ${my_tmp}.out 2>&1', "\n";
58cdf0e10cSrcweir    print STDOUT 'my_ret=$?', "\n";
59cdf0e10cSrcweir    print STDOUT
60cdf0e10cSrcweir        'if [ ${my_ret} -ne 0 ] ; then echo $1 >&2 ; cat ${my_tmp}.out >&2 ;',
61cdf0e10cSrcweir        ' fi', "\n";
62cdf0e10cSrcweir    print STDOUT 'unlink ${my_tmp} || exit 1', "\n";
63cdf0e10cSrcweir    print STDOUT 'unlink ${my_tmp}.out || exit 1', "\n";
64cdf0e10cSrcweir    print STDOUT 'exit ${my_ret}', "\n";
65cdf0e10cSrcweir} elsif ($ENV{OS} eq 'WNT') {
66cdf0e10cSrcweir  if ($ENV{COM} eq 'GCC') {
67cdf0e10cSrcweir    1 while $in =~ s!\s+-I\s*\.\S*\s*! !g; # discard relative includes
68cdf0e10cSrcweir    $in =~ s!(\s+-I\s*)(?i:$solarversion)(\S*)!$1\${SOLARVERSION}$2!og;
69cdf0e10cSrcweir        # macrofy includes to solver
70cdf0e10cSrcweir    $in =~ s!\s+-o\s*\S+! -o /dev/null! || die 'bad input: no -o';
71cdf0e10cSrcweir    $in =~ s!\S+/testhxx.cxx!\${my_tmp}!
72cdf0e10cSrcweir        || die 'bad input: no source file';
73cdf0e10cSrcweir    print STDOUT '#!/bin/sh', "\n";
74cdf0e10cSrcweir    print STDOUT
75cdf0e10cSrcweir        'my_tmp=${TMPDIR:-/tmp}/`id -u`_$$_include.cc', "\n";
76cdf0e10cSrcweir    print STDOUT 'my_pat=`dirname $1`', "\n";
77cdf0e10cSrcweir    print STDOUT 'my_fil=`basename $1`', "\n";
78cdf0e10cSrcweir    print STDOUT 'my_org=${PWD}', "\n";
79cdf0e10cSrcweir    print STDOUT 'cd $my_pat || exit 1', "\n";
80cdf0e10cSrcweir    print STDOUT 'my_pat=`cygpath -m \`pwd\``', "\n";
81cdf0e10cSrcweir    print STDOUT 'cd $my_org || exit 1', "\n";
82cdf0e10cSrcweir    print STDOUT
83cdf0e10cSrcweir        'echo "#include \\"${my_pat}/${my_fil}\\"" > ${my_tmp} || exit 1', "\n";
84cdf0e10cSrcweir    print STDOUT $in, ' > ${my_tmp}.out 2>&1', "\n";
85cdf0e10cSrcweir    print STDOUT 'my_ret=$?', "\n";
86cdf0e10cSrcweir    print STDOUT
87cdf0e10cSrcweir        'if [ ${my_ret} -ne 0 ] ; then echo $1 >&2 ; cat ${my_tmp}.out >&2 ;',
88cdf0e10cSrcweir        ' fi', "\n";
89cdf0e10cSrcweir    print STDOUT 'unlink ${my_tmp} || exit 1', "\n";
90cdf0e10cSrcweir    print STDOUT 'unlink ${my_tmp}.out || exit 1', "\n";
91cdf0e10cSrcweir    print STDOUT 'exit ${my_ret}', "\n";
92cdf0e10cSrcweir  } else {
93cdf0e10cSrcweir    1 while $in =~ s!\s+-I\s*\.\S*\s*! !g; # discard relative includes
94cdf0e10cSrcweir    $in =~ s!(\s+-I\s*)(?i:$solarversion)(\S*)!$1\${SOLARVERSION}$2!og;
95cdf0e10cSrcweir        # macrofy includes to solver
96cdf0e10cSrcweir    $in =~ s!\s+-Fo\s*\S+! -Fo$[my_tmp}obj! || die 'bad input: no -Fo';
97cdf0e10cSrcweir    $in =~ s!\s+-Zi\s! !;
98cdf0e10cSrcweir    $in =~ s!\s+-Fd\s*\S+!!;
99cdf0e10cSrcweir    print STDOUT '#!/bin/sh', "\n";
100cdf0e10cSrcweir    print STDOUT
101cdf0e10cSrcweir        'my_tmp=${TMPDIR:-/tmp}/`id -u`_$$_include.cc', "\n";
102cdf0e10cSrcweir    print STDOUT 'my_pat=`dirname $1`', "\n";
103cdf0e10cSrcweir    print STDOUT 'my_fil=`basename $1`', "\n";
104cdf0e10cSrcweir    print STDOUT 'my_org=${PWD}', "\n";
105cdf0e10cSrcweir    print STDOUT 'cd $my_pat || exit 1', "\n";
106cdf0e10cSrcweir    print STDOUT 'my_pat=`pwd`', "\n";
107cdf0e10cSrcweir    print STDOUT 'cd $my_org || exit 1', "\n";
108cdf0e10cSrcweir    print STDOUT
109cdf0e10cSrcweir        'echo "#include \\"${my_pat}/${my_fil}\\"" > ${my_tmp} || exit 1', "\n";
110cdf0e10cSrcweir    print STDOUT $in, ' > ${my_tmp}.out 2>&1', "\n";
111cdf0e10cSrcweir    print STDOUT 'my_ret=$?', "\n";
112cdf0e10cSrcweir    print STDOUT
113cdf0e10cSrcweir        'if [ ${my_ret} -ne 0 ] ; then echo $1 >&2 ; cat ${my_tmp}.out >&2 ;',
114cdf0e10cSrcweir        ' fi', "\n";
115cdf0e10cSrcweir    print STDOUT 'unlink ${my_tmp} || exit 1', "\n";
116cdf0e10cSrcweir    print STDOUT 'unlink ${my_tmp}.out || exit 1', "\n";
117cdf0e10cSrcweir    print STDOUT 'exit ${my_ret}', "\n";
118cdf0e10cSrcweir  }
119cdf0e10cSrcweir} else {
120cdf0e10cSrcweir    print STDOUT 'echo \'no testhxx on this platform\'', "\n";
121cdf0e10cSrcweir}
122