Imported from ../bash-1.14.7.tar.gz.
[platform/upstream/bash.git] / support / cppmagic
1 #!/bin/sh
2 # Return a full cpp specification, complete with system dependent flags.
3 #
4 # Syntax: cppmagic [ program-to-generate-flags [ guessed-cpp ]]
5 #
6 # If only one arg is present it is the name of a program to invoke
7 # which should generate -Dfoo defines.
8 #
9 # If two args are present the second arg is the name of the C
10 # preprocessor to use.
11 #
12 # Invoked with no args, provides a C preprocessor name and
13 # -traditional flag if that is appropriate.
14 #
15 #  ../Makefile calls this file thusly: "cppmagic getcppsyms".
16 #
17 #  Typical output:
18 #
19 #    /lib/cpp -Dunix -Dm68k
20 #
21
22 Cpp=
23
24 if [ "$2" ]; then
25    Cpp=$2
26 else
27    for cpp in /lib/cpp /usr/lib/cpp /usr/ccs/lib/cpp; do
28       if [ -f $cpp ]; then
29          Cpp=$cpp
30       fi
31    done
32    if [ "$Cpp" = "" ]; then
33       Cpp=cpp
34    fi
35 fi
36
37 TRADITIONAL=
38 FLAGS=
39
40 # First flag might be `-traditional' if this is Gnu Cpp.
41 unknown_flag=`$Cpp -traditional /dev/null 2>&1 |
42                 egrep 'known|recognized|valid|bad|legal'`
43 if [ "$unknown_flag" = "" ]; then
44   TRADITIONAL=-traditional
45 fi
46
47 if [ "$1" ]; then
48    FLAGS=`$1`
49 fi
50
51 echo $Cpp $TRADITIONAL $FLAGS