Usenet comp.unix.tru64 (2000-2013)
 help / color / mirror / Atom feed
From: Dave <foo@coo.com>
Subject: Count someone test this script which determines compiler please?
Date: Sat, 03 Oct 2009 21:24:01 +0100	[thread overview]
Message-ID: <38faa65577e2dff08685b44f53d39a63.comp-unix-tru64@archive.invalid> (raw)
Message-ID: <4ac7b2e2@212.67.96.135> (raw)

I have two scripts, one of which is supposed to determine if the 
environment variable CC points to a IBM, Sun, GNU, HP ... etc C compiler.

The other does the same for the C++ compiler, if CXX is defined.

I've tested these with Sun's compiler and gcc on Solaris, but I don't 
have any machines running HP-UX, AIX or tru64 easily available. Could 
someone try setting the variables CC and CXX to various compilers, and 
let me know what these two scripts report.

I've put a bit of a gap between then. I'm not sure how well newsgroups 
handle attachments, so I'm not using that.

First the C one:

drkirkby@swan:[~] $ cat testcc
#!/usr/bin/sh
# Determine the type of C compiler, which can later
# be used to determine the flags the compiler
# will want. Do this by defining pre-processing a bit
# of C++ code, and checking what are defined.

# The Sun and GNU compilers have been tested.

# The HP and GNU compilers have not been tested, but
# use information gained from the documentation.

# HP-UX C and C++ compiler.
# http://docs.hp.com/en/7730/newhelp0610/preprocess.htm

# IBM Compiler Reference - XL C/C++ for AIX, V10.1
# http://www-01.ibm.com/support/docview.wss?uid=swg27012860&aid=1

# Using HP C++ for Tru64 UNIX and Linux Alpha
# http://h30097.www3.hp.com/cplus/ugu_impl.html#implem_chap


# First, make sure the enviroment variable CC is defined.

if [ -z "$CC" ]; then
    echo "Sorry, you should define the enivronment variable CC"
    exit 1
fi

# Create a test file. It does not need to be a complete
# C++ file, as it is only pre-processed. So there is no
# need for a 'main'

TESTFILE=/tmp/test.$$.c

# The flags for the GNU compilers do not change with
# operating system, so there is no need to worry too
# much about what system this is on.

echo "#ifdef __GNUC__"                   > $TESTFILE
echo "it_is_the_GNU_compiler"            >> $TESTFILE
echo "#endif"                            >> $TESTFILE

echo "#ifdef __SUNPRO_C"                 >> $TESTFILE
echo "it_is_the_Sun_compiler"            >> $TESTFILE
echo "#endif"                            >> $TESTFILE

# Not found any offical documention to suggest __DECC
# would be defined, but __DECCC is defined for C++,
# and a Google on __DECC shows many hits.
echo "#ifdef __digital__"                >> $TESTFILE
echo "#ifdef __DECC"                     >> $TESTFILE
echo "it_is_the_HP_Tru64_compiler"       >> $TESTFILE
echo "#endif"                            >> $TESTFILE
echo "#endif"                            >> $TESTFILE

echo "#ifdef __linux__"                  >> $TESTFILE
echo "#ifdef __DECCC"                   >> $TESTFILE
echo "it_is_the_HP_Alpha_Linux_compiler" >> $TESTFILE
echo "#endif"                            >> $TESTFILE
echo "#endif"                            >> $TESTFILE

echo "#ifdef __HP_aCC"                   >> $TESTFILE
echo "it_is_the_HP_HPUX_compiler"        >> $TESTFILE
echo "#endif"                            >> $TESTFILE

echo "#ifdef __xlC__"                    >> $TESTFILE
echo "it_is_the_IBM_AIX_compiler"        >> $TESTFILE
echo "#endif"                            >> $TESTFILE

${CC} -E $TESTFILE | grep it_is_the_GNU_compiler  >/dev/null 2>&1
if [ $? = 0 ]; then
    echo GNU
    rm $TESTFILE
    exit 0
fi

${CC} -E $TESTFILE | grep it_is_the_Sun_compiler  >/dev/null 2>&1
if [ $? = 0 ]; then
    echo Sun_on_Solaris
    rm $TESTFILE
    exit 0
fi

# HP make compilers for linux, HP-UX and tru64, which complicates matters.

${CC} -E $TESTFILE | grep it_is_the_HP_Tru64_compiler >/dev/null 2>&1
if [ $? = 0 ]; then
    echo HP_on_Tru64
    rm $TESTFILE
    exit 0
fi

${CC} -E $TESTFILE | grep it_is_the_HP_Alpha_Linux_compiler >/dev/null 2>&1
if [ $? = 0 ]; then
    echo HP_on_Alpha_Linux
    rm $TESTFILE
    exit 0
fi

${CC} -E $TESTFILE | grep it_is_the_HP_HPUX_compiler >/dev/null 2>&1
if [ $? = 0 ]; then
    echo HP_on_HPUX
    rm $TESTFILE
    exit 0
fi

${CC} -E $TESTFILE | grep it_is_the_IBM_AIX_compiler >/dev/null 2>&1
if [ $? = 0 ]; then
    echo IBM_on_AIX
    rm $TESTFILE
    exit 0
fi

# Exit saying 'Unknown' if the type of the compiler could not be found.
echo Unknown
rm $TESTFILE
exit 0





Now the C++ one



drkirkby@swan:[~] $ cat testcxx
#!/usr/bin/sh
# Determine the type of C++ compiler, which can later
# be used to determine the flags the compiler
# will want. Do this by defining pre-processing a bit
# of C++ code, and checking what are defined.

# The Sun and GNU compilers have been tested.

# The HP and GNU compilers have not been tested, but
# use information gained from the documentation.

# HP-UX C and C++ compiler.
# http://docs.hp.com/en/7730/newhelp0610/preprocess.htm

# IBM Compiler Reference - XL C/C++ for AIX, V10.1
# http://www-01.ibm.com/support/docview.wss?uid=swg27012860&aid=1

# Using HP C++ for Tru64 UNIX and Linux Alpha
# http://h30097.www3.hp.com/cplus/ugu_impl.html#implem_chap


# First, make sure the enviroment variable CXX is defined.

if [ -z "$CXX" ]; then
    echo "Sorry, you should define the enivronment variable CXX"
    exit 1
fi

# Create a test file. It does not need to be a complete
# C++ file, as it is only pre-processed. So there is no
# need for a 'main'

TESTFILE=/tmp/test.$$.cpp

# The flags for the GNU compilers do not change with
# operating system, so there is no need to worry too
# much about what system this is on.

echo "#ifdef __GNUC__"                   > $TESTFILE
echo "it_is_the_GNU_compiler"            >> $TESTFILE
echo "#endif"                            >> $TESTFILE

echo "#ifdef __SUNPRO_CC"                >> $TESTFILE
echo "it_is_the_Sun_compiler"            >> $TESTFILE
echo "#endif"                            >> $TESTFILE

echo "#ifdef __digital__"                >> $TESTFILE
echo "#ifdef __DECCXX"                   >> $TESTFILE
echo "it_is_the_HP_Tru64_compiler"       >> $TESTFILE
echo "#endif"                            >> $TESTFILE
echo "#endif"                            >> $TESTFILE

echo "#ifdef __linux__"                  >> $TESTFILE
echo "#ifdef __DECCXX"                   >> $TESTFILE
echo "it_is_the_HP_Alpha_Linux_compiler" >> $TESTFILE
echo "#endif"                            >> $TESTFILE
echo "#endif"                            >> $TESTFILE

echo "#ifdef __HP_aCC"                   >> $TESTFILE
echo "it_is_the_HP_HPUX_compiler"        >> $TESTFILE
echo "#endif"                            >> $TESTFILE

echo "#ifdef __xlC__"                    >> $TESTFILE
echo "it_is_the_IBM_AIX_compiler"        >> $TESTFILE
echo "#endif"                            >> $TESTFILE

${CXX} -E $TESTFILE | grep it_is_the_GNU_compiler  >/dev/null 2>&1
if [ $? = 0 ]; then
    echo GNU
    rm $TESTFILE
    exit 0
fi

${CXX} -E $TESTFILE | grep it_is_the_Sun_compiler  >/dev/null 2>&1
if [ $? = 0 ]; then
    echo Sun_on_Solaris
    rm $TESTFILE
    exit 0
fi

# HP make compilers for linux, HP-UX and tru64, which complicates matters.

${CXX} -E $TESTFILE | grep it_is_the_HP_Tru64_compiler >/dev/null 2>&1
if [ $? = 0 ]; then
    echo HP_on_Tru64
    rm $TESTFILE
    exit 0
fi

${CXX} -E $TESTFILE | grep it_is_the_HP_Alpha_Linux_compiler >/dev/null 2>&1
if [ $? = 0 ]; then
    echo HP_on_Alpha_Linux
    rm $TESTFILE
    exit 0
fi

${CXX} -E $TESTFILE | grep it_is_the_HP_HPUX_compiler >/dev/null 2>&1
if [ $? = 0 ]; then
    echo HP_on_HPUX
    rm $TESTFILE
    exit 0
fi

${CXX} -E $TESTFILE | grep it_is_the_IBM_AIX_compiler >/dev/null 2>&1
if [ $? = 0 ]; then
    echo IBM_on_AIX
    rm $TESTFILE
    exit 0
fi

# Exit saying 'Unknown' if the type of the compiler could not be found.
echo Unknown
rm $TESTFILE
exit 0






-- 
I respectfully request that this message is not archived by companies as
unscrupulous as 'Experts Exchange' . In case you are unaware,
'Experts Exchange'  take questions posted on the web and try to find
idiots stupid enough to pay for the answers, which were posted freely
by others. They are leeches.


             reply	other threads:[~2009-10-03 20:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <4ac7b2e2@212.67.96.135>
2009-10-03 20:24 ` Dave [this message]
2009-10-04  2:55 ` Count someone test this script which determines compiler please? Niel Lambrechts
2009-10-04  5:37   ` Dave
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox