summaryrefslogtreecommitdiff
path: root/sysinfo.sh
blob: ab7149f97eedbe078fea31e03d133348ea60603f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/sh

# the arguments of this script are the compiler name and flags

# try to solve a chicken-and-egg problem on SunOS
# ucb's test program does not handle -L like the other test programs
# let's try to find another implementation
if test -x /bin/test; then
    TEST=/bin/test;
else
    if test -x /usr/bin/test; then
        TEST=/usr/bin/test;
    else
        # cross your fingers that it's not like ucb test
        TEST=test;
    fi
fi

compiler=`echo $* | sed -e 's/-static//g' -e 's/-Bstatic//g'`
if $TEST `basename $1` = "gcc" && ($compiler -v) >/dev/null 2>&1 ; then
# Cygwin writes more than one line with "version" in it
    gccversion=`$compiler -v 2>&1 | sed -e "/version/!d" | tail -n 1`
else
    gccversion="$1"
fi

libcversion=`/lib/libc.so.6 | head -n 1`
if ($* hello.c -o hello) >/dev/null 2>&1; then
  ldd_output=`(ldd hello) 2>&1`
  libcversion=`echo $ldd_output | sed -e 's/.*static.*/static/' \
				      -e 's/.*not a dynamic.*/static/'`
  if $TEST "$libcversion" = "static" ; then
    if ($compiler hello.c -o hello) >/dev/null 2>&1; then
      if (ldd hello) >/dev/null 2>/dev/null; then
        libcversion=`(ldd hello) 2>&1`
        libcversion=`echo $libcversion | sed -e '/libc/!d'\
			-e 's/^[ 	]*//' \
			-e 's/.*=>[ 	][ 	]*\([^ 	]*\).*/\1/'`
	# remember the current directory
      	current=`pwd`
      	while $TEST -L "$libcversion" && ! $TEST "$libcversion" = "" ; do
      	  libcitself=`basename $libcversion`
      	  libpath=`echo $libcversion | sed -e "s/$libcitself$//"`
      	  if $TEST -d "$libpath" ; then
      	    cd $libpath
      	  fi
      	  if ls $libcitself >/dev/null 2>/dev/null ; then
      	    libcversion=`ls -l $libcitself | \
			   sed -e 's/.*->[ 	][ 	]*\(.*\)$/\1/'`
      	  else
      	    # something must have gone wrong, let's bail out
      	    libcversion=""
      	  fi
      	done
      	# return to the current directory
      	cd $current
      fi
    fi
  else
    libcversion=""
  fi
fi

rm -f sysinfo.crm sysinfo.c hello

# this bombs out on Ultrix which expect "cut -d"

compsystem=`uname -a | cut -b 1-78`
compdate=`date|cut -b1-55`

# let's hope that ctrl-c is not part of any string here
# this also will barf later if " is in any of the strings

sed -e "s%CCVERSION%$gccversion" -e "s%LIBCVERSION%$libcversion"\
    -e "s%SYSTEM%$compsystem" -e "s%DATE%$compdate"\
    sysinfo.c.template > sysinfo.c