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