1 | #!/bin/sh |
---|
2 | # |
---|
3 | # The contents of this file are subject to the Netscape Public |
---|
4 | # License Version 1.1 (the "License"); you may not use this file |
---|
5 | # except in compliance with the License. You may obtain a copy of |
---|
6 | # the License at http://www.mozilla.org/NPL/ |
---|
7 | # |
---|
8 | # Software distributed under the License is distributed on an "AS |
---|
9 | # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or |
---|
10 | # implied. See the License for the specific language governing |
---|
11 | # rights and limitations under the License. |
---|
12 | # |
---|
13 | # The Original Code is mozilla.org code. |
---|
14 | # |
---|
15 | # The Initial Developer of the Original Code is Netscape |
---|
16 | # Communications Corporation. Portions created by Netscape are |
---|
17 | # Copyright (C) 1998 Netscape Communications Corporation. All |
---|
18 | # Rights Reserved. |
---|
19 | # |
---|
20 | # Contributor(s): |
---|
21 | # |
---|
22 | |
---|
23 | ############################################################################## |
---|
24 | ## |
---|
25 | ## Name: glibcversion.sh - Print __GLIBC__ version if gnu libc 2 is |
---|
26 | ## found. |
---|
27 | ## |
---|
28 | ## Description: This script is needed by the mozilla build system. It needs |
---|
29 | ## to determine whether the current platform (mostly the |
---|
30 | ## various linux "platforms") are based on the gnu libc2. This |
---|
31 | ## information is later used in mozilla to determine whether |
---|
32 | ## gnu libc 2 specific "features" need to be handled, such |
---|
33 | ## as broken locales. |
---|
34 | ## |
---|
35 | ## Author: Ramiro Estrugo <ramiro@netscape.com> |
---|
36 | ## |
---|
37 | ############################################################################## |
---|
38 | |
---|
39 | ## |
---|
40 | ## Command Line Flags Supported: |
---|
41 | ## |
---|
42 | ## -g | --is-glibc2: Print True/False if detected __GLIBC__. |
---|
43 | ## |
---|
44 | ## -v | --print-version: Print value of __GLIBC__ if found, or none. |
---|
45 | ## |
---|
46 | ## -o | --set-object-name: Set object name for current system. |
---|
47 | ## -cc | --set-compiler: Set compiler for building test program. |
---|
48 | ## |
---|
49 | |
---|
50 | |
---|
51 | ## |
---|
52 | ## Constants |
---|
53 | ## |
---|
54 | GLIBC_PROG_PREFIX=./get_glibc_info |
---|
55 | |
---|
56 | ## |
---|
57 | ## Defaults |
---|
58 | ## |
---|
59 | GLIBC_PRINT_IS_GLIBC2=False |
---|
60 | |
---|
61 | GLIBC_PRINT_VERSION=False |
---|
62 | |
---|
63 | GLIBC_OBJECT_NAME=`uname`-`uname -r` |
---|
64 | GLIBC_CC=cc |
---|
65 | |
---|
66 | function glibc_usage() |
---|
67 | { |
---|
68 | echo |
---|
69 | echo "Usage: `basename $0` [options]" |
---|
70 | echo |
---|
71 | echo " -g, --is-glibc2: Print True/False if detected __GLIBC__." |
---|
72 | echo |
---|
73 | echo " -v, --print-version: Print value of __GLIBC__ if found, or none." |
---|
74 | echo |
---|
75 | echo " -o, --set-object-name: Set object name for current system." |
---|
76 | echo " -cc, --set-compiler: Set compiler for building test program." |
---|
77 | echo |
---|
78 | echo " -h, --help: Print this blurb." |
---|
79 | echo |
---|
80 | echo "The default is '-v' if no options are given." |
---|
81 | echo |
---|
82 | } |
---|
83 | |
---|
84 | ## |
---|
85 | ## Parse the command line |
---|
86 | ## |
---|
87 | while [ "$*" ]; do |
---|
88 | case $1 in |
---|
89 | -h | --help) |
---|
90 | shift |
---|
91 | glibc_usage |
---|
92 | exit 0 |
---|
93 | ;; |
---|
94 | |
---|
95 | -g | --is-glibc2) |
---|
96 | shift |
---|
97 | GLIBC_PRINT_IS_GLIBC2=True |
---|
98 | ;; |
---|
99 | |
---|
100 | -v | --print-version) |
---|
101 | shift |
---|
102 | GLIBC_PRINT_VERSION=True |
---|
103 | ;; |
---|
104 | |
---|
105 | -o | --set-object-name) |
---|
106 | shift |
---|
107 | GLIBC_OBJECT_NAME="$1" |
---|
108 | shift |
---|
109 | ;; |
---|
110 | |
---|
111 | -cc | --set-compiler) |
---|
112 | shift |
---|
113 | GLIBC_CC="$1" |
---|
114 | shift |
---|
115 | ;; |
---|
116 | |
---|
117 | -*) |
---|
118 | echo "`basename $0`: invalid option '$1'" |
---|
119 | shift |
---|
120 | glibc_usage |
---|
121 | exit 0 |
---|
122 | ;; |
---|
123 | esac |
---|
124 | done |
---|
125 | |
---|
126 | ## |
---|
127 | ## Motif info program name |
---|
128 | ## |
---|
129 | GLIBC_PROG="$GLIBC_PROG_PREFIX"_"$GLIBC_OBJECT_NAME" |
---|
130 | GLIBC_SRC="$GLIBC_PROG_PREFIX"_"$GLIBC_OBJECT_NAME.c" |
---|
131 | |
---|
132 | ## |
---|
133 | ## Cleanup the dummy test source/program |
---|
134 | ## |
---|
135 | function glibc_cleanup() |
---|
136 | { |
---|
137 | true |
---|
138 | |
---|
139 | # rm -f $GLIBC_PROG |
---|
140 | # rm -f $GLIBC_SRC |
---|
141 | |
---|
142 | } |
---|
143 | |
---|
144 | glibc_cleanup |
---|
145 | |
---|
146 | if [ ! -f $GLIBC_SRC ] |
---|
147 | then |
---|
148 | cat << EOF > $GLIBC_SRC |
---|
149 | #include <stdio.h> |
---|
150 | |
---|
151 | int main(int argc,char ** argv) |
---|
152 | { |
---|
153 | #ifdef __GLIBC__ |
---|
154 | fprintf(stdout,"%d\n",__GLIBC__); |
---|
155 | #else |
---|
156 | fprintf(stdout,"none\n"); |
---|
157 | #endif |
---|
158 | |
---|
159 | return 0; |
---|
160 | } |
---|
161 | EOF |
---|
162 | fi |
---|
163 | |
---|
164 | if [ ! -f $GLIBC_SRC ] |
---|
165 | then |
---|
166 | echo |
---|
167 | echo "Could not create test program source $GLIBC_SRC." |
---|
168 | echo |
---|
169 | |
---|
170 | glibc_cleanup |
---|
171 | |
---|
172 | exit |
---|
173 | fi |
---|
174 | |
---|
175 | ## |
---|
176 | ## Compile the dummy test program if needed |
---|
177 | ## |
---|
178 | if [ ! -x $GLIBC_PROG ] |
---|
179 | then |
---|
180 | $GLIBC_CC -o $GLIBC_PROG $GLIBC_SRC |
---|
181 | fi |
---|
182 | |
---|
183 | if [ ! -x $GLIBC_PROG ] |
---|
184 | then |
---|
185 | echo |
---|
186 | echo "Could not create test program $GLIBC_PROG." |
---|
187 | echo |
---|
188 | |
---|
189 | glibc_cleanup |
---|
190 | |
---|
191 | exit |
---|
192 | fi |
---|
193 | |
---|
194 | ## |
---|
195 | ## Execute the dummy test program |
---|
196 | ## |
---|
197 | GLIBC_PROG_OUTPUT=`$GLIBC_PROG` |
---|
198 | |
---|
199 | ## |
---|
200 | ## -g | --is-glibc2 |
---|
201 | ## |
---|
202 | if [ "$GLIBC_PRINT_IS_GLIBC2" = "True" ] |
---|
203 | then |
---|
204 | if [ "$GLIBC_PROG_OUTPUT" = "2" ] |
---|
205 | then |
---|
206 | echo True |
---|
207 | else |
---|
208 | echo False |
---|
209 | fi |
---|
210 | |
---|
211 | glibc_cleanup |
---|
212 | |
---|
213 | exit 0 |
---|
214 | fi |
---|
215 | |
---|
216 | echo $GLIBC_PROG_OUTPUT |
---|
217 | |
---|
218 | glibc_cleanup |
---|