Merge mozilla-central and tracemonkey. (a=blockers)
[mozilla-central.git] / config / glibcversion.sh
blobf8c220e5e67ba8d8ca8370937c51486658f1ac6e
1 #!/bin/sh
3 # ***** BEGIN LICENSE BLOCK *****
4 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 # The contents of this file are subject to the Mozilla Public License Version
7 # 1.1 (the "License"); you may not use this file except in compliance with
8 # the License. You may obtain a copy of the License at
9 # http://www.mozilla.org/MPL/
11 # Software distributed under the License is distributed on an "AS IS" basis,
12 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 # for the specific language governing rights and limitations under the
14 # License.
16 # The Original Code is mozilla.org code.
18 # The Initial Developer of the Original Code is
19 # Netscape Communications Corporation.
20 # Portions created by the Initial Developer are Copyright (C) 1998
21 # the Initial Developer. All Rights Reserved.
23 # Contributor(s):
25 # Alternatively, the contents of this file may be used under the terms of
26 # either of the GNU General Public License Version 2 or later (the "GPL"),
27 # or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 # in which case the provisions of the GPL or the LGPL are applicable instead
29 # of those above. If you wish to allow use of your version of this file only
30 # under the terms of either the GPL or the LGPL, and not to allow others to
31 # use your version of this file under the terms of the MPL, indicate your
32 # decision by deleting the provisions above and replace them with the notice
33 # and other provisions required by the GPL or the LGPL. If you do not delete
34 # the provisions above, a recipient may use your version of this file under
35 # the terms of any one of the MPL, the GPL or the LGPL.
37 # ***** END LICENSE BLOCK *****
39 ##############################################################################
41 ## Name: glibcversion.sh - Print __GLIBC__ version if gnu libc 2 is
42 ## found.
44 ## Description: This script is needed by the mozilla build system. It needs
45 ## to determine whether the current platform (mostly the
46 ## various linux "platforms") are based on the gnu libc2. This
47 ## information is later used in mozilla to determine whether
48 ## gnu libc 2 specific "features" need to be handled, such
49 ## as broken locales.
51 ## Author: Ramiro Estrugo <ramiro@netscape.com>
53 ##############################################################################
56 ## Command Line Flags Supported:
58 ## -g | --is-glibc2: Print True/False if detected __GLIBC__.
60 ## -v | --print-version: Print value of __GLIBC__ if found, or none.
62 ## -o | --set-object-name: Set object name for current system.
63 ## -cc | --set-compiler: Set compiler for building test program.
68 ## Constants
70 GLIBC_PROG_PREFIX=./get_glibc_info
73 ## Defaults
75 GLIBC_PRINT_IS_GLIBC2=False
77 GLIBC_PRINT_VERSION=False
79 GLIBC_OBJECT_NAME=`uname`-`uname -r`
80 GLIBC_CC=cc
82 function glibc_usage()
84 echo
85 echo "Usage: `basename $0` [options]"
86 echo
87 echo " -g, --is-glibc2: Print True/False if detected __GLIBC__."
88 echo
89 echo " -v, --print-version: Print value of __GLIBC__ if found, or none."
90 echo
91 echo " -o, --set-object-name: Set object name for current system."
92 echo " -cc, --set-compiler: Set compiler for building test program."
93 echo
94 echo " -h, --help: Print this blurb."
95 echo
96 echo "The default is '-v' if no options are given."
97 echo
101 ## Parse the command line
103 while [ "$*" ]; do
104 case $1 in
105 -h | --help)
106 shift
107 glibc_usage
108 exit 0
111 -g | --is-glibc2)
112 shift
113 GLIBC_PRINT_IS_GLIBC2=True
116 -v | --print-version)
117 shift
118 GLIBC_PRINT_VERSION=True
121 -o | --set-object-name)
122 shift
123 GLIBC_OBJECT_NAME="$1"
124 shift
127 -cc | --set-compiler)
128 shift
129 GLIBC_CC="$1"
130 shift
134 echo "`basename $0`: invalid option '$1'"
135 shift
136 glibc_usage
137 exit 0
139 esac
140 done
143 ## Motif info program name
145 GLIBC_PROG="$GLIBC_PROG_PREFIX"_"$GLIBC_OBJECT_NAME"
146 GLIBC_SRC="$GLIBC_PROG_PREFIX"_"$GLIBC_OBJECT_NAME.c"
149 ## Cleanup the dummy test source/program
151 function glibc_cleanup()
153 true
155 # rm -f $GLIBC_PROG
156 # rm -f $GLIBC_SRC
160 glibc_cleanup
162 if [ ! -f $GLIBC_SRC ]
163 then
164 cat << EOF > $GLIBC_SRC
165 #include <stdio.h>
167 int main(int argc,char ** argv)
169 #ifdef __GLIBC__
170 fprintf(stdout,"%d\n",__GLIBC__);
171 #else
172 fprintf(stdout,"none\n");
173 #endif
175 return 0;
180 if [ ! -f $GLIBC_SRC ]
181 then
182 echo
183 echo "Could not create test program source $GLIBC_SRC."
184 echo
186 glibc_cleanup
188 exit
192 ## Compile the dummy test program if needed
194 if [ ! -x $GLIBC_PROG ]
195 then
196 $GLIBC_CC -o $GLIBC_PROG $GLIBC_SRC
199 if [ ! -x $GLIBC_PROG ]
200 then
201 echo
202 echo "Could not create test program $GLIBC_PROG."
203 echo
205 glibc_cleanup
207 exit
211 ## Execute the dummy test program
213 GLIBC_PROG_OUTPUT=`$GLIBC_PROG`
216 ## -g | --is-glibc2
218 if [ "$GLIBC_PRINT_IS_GLIBC2" = "True" ]
219 then
220 if [ "$GLIBC_PROG_OUTPUT" = "2" ]
221 then
222 echo True
223 else
224 echo False
227 glibc_cleanup
229 exit 0
232 echo $GLIBC_PROG_OUTPUT
234 glibc_cleanup