michael@0: #!/bin/sh michael@0: # michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: ############################################################################## michael@0: ## michael@0: ## Name: glibcversion.sh - Print __GLIBC__ version if gnu libc 2 is michael@0: ## found. michael@0: ## michael@0: ## Description: This script is needed by the mozilla build system. It needs michael@0: ## to determine whether the current platform (mostly the michael@0: ## various linux "platforms") are based on the gnu libc2. This michael@0: ## information is later used in mozilla to determine whether michael@0: ## gnu libc 2 specific "features" need to be handled, such michael@0: ## as broken locales. michael@0: ## michael@0: ## Author: Ramiro Estrugo michael@0: ## michael@0: ############################################################################## michael@0: michael@0: ## michael@0: ## Command Line Flags Supported: michael@0: ## michael@0: ## -g | --is-glibc2: Print True/False if detected __GLIBC__. michael@0: ## michael@0: ## -v | --print-version: Print value of __GLIBC__ if found, or none. michael@0: ## michael@0: ## -o | --set-object-name: Set object name for current system. michael@0: ## -cc | --set-compiler: Set compiler for building test program. michael@0: ## michael@0: michael@0: michael@0: ## michael@0: ## Constants michael@0: ## michael@0: GLIBC_PROG_PREFIX=./get_glibc_info michael@0: michael@0: ## michael@0: ## Defaults michael@0: ## michael@0: GLIBC_PRINT_IS_GLIBC2=False michael@0: michael@0: GLIBC_PRINT_VERSION=False michael@0: michael@0: GLIBC_OBJECT_NAME=`uname`-`uname -r` michael@0: GLIBC_CC=cc michael@0: michael@0: function glibc_usage() michael@0: { michael@0: echo michael@0: echo "Usage: `basename $0` [options]" michael@0: echo michael@0: echo " -g, --is-glibc2: Print True/False if detected __GLIBC__." michael@0: echo michael@0: echo " -v, --print-version: Print value of __GLIBC__ if found, or none." michael@0: echo michael@0: echo " -o, --set-object-name: Set object name for current system." michael@0: echo " -cc, --set-compiler: Set compiler for building test program." michael@0: echo michael@0: echo " -h, --help: Print this blurb." michael@0: echo michael@0: echo "The default is '-v' if no options are given." michael@0: echo michael@0: } michael@0: michael@0: ## michael@0: ## Parse the command line michael@0: ## michael@0: while [ "$*" ]; do michael@0: case $1 in michael@0: -h | --help) michael@0: shift michael@0: glibc_usage michael@0: exit 0 michael@0: ;; michael@0: michael@0: -g | --is-glibc2) michael@0: shift michael@0: GLIBC_PRINT_IS_GLIBC2=True michael@0: ;; michael@0: michael@0: -v | --print-version) michael@0: shift michael@0: GLIBC_PRINT_VERSION=True michael@0: ;; michael@0: michael@0: -o | --set-object-name) michael@0: shift michael@0: GLIBC_OBJECT_NAME="$1" michael@0: shift michael@0: ;; michael@0: michael@0: -cc | --set-compiler) michael@0: shift michael@0: GLIBC_CC="$1" michael@0: shift michael@0: ;; michael@0: michael@0: -*) michael@0: echo "`basename $0`: invalid option '$1'" michael@0: shift michael@0: glibc_usage michael@0: exit 0 michael@0: ;; michael@0: esac michael@0: done michael@0: michael@0: ## michael@0: ## Motif info program name michael@0: ## michael@0: GLIBC_PROG="$GLIBC_PROG_PREFIX"_"$GLIBC_OBJECT_NAME" michael@0: GLIBC_SRC="$GLIBC_PROG_PREFIX"_"$GLIBC_OBJECT_NAME.c" michael@0: michael@0: ## michael@0: ## Cleanup the dummy test source/program michael@0: ## michael@0: function glibc_cleanup() michael@0: { michael@0: true michael@0: michael@0: # rm -f $GLIBC_PROG michael@0: # rm -f $GLIBC_SRC michael@0: michael@0: } michael@0: michael@0: glibc_cleanup michael@0: michael@0: if [ ! -f $GLIBC_SRC ] michael@0: then michael@0: cat << EOF > $GLIBC_SRC michael@0: #include michael@0: michael@0: int main(int argc,char ** argv) michael@0: { michael@0: #ifdef __GLIBC__ michael@0: fprintf(stdout,"%d\n",__GLIBC__); michael@0: #else michael@0: fprintf(stdout,"none\n"); michael@0: #endif michael@0: michael@0: return 0; michael@0: } michael@0: EOF michael@0: fi michael@0: michael@0: if [ ! -f $GLIBC_SRC ] michael@0: then michael@0: echo michael@0: echo "Could not create test program source $GLIBC_SRC." michael@0: echo michael@0: michael@0: glibc_cleanup michael@0: michael@0: exit michael@0: fi michael@0: michael@0: ## michael@0: ## Compile the dummy test program if needed michael@0: ## michael@0: if [ ! -x $GLIBC_PROG ] michael@0: then michael@0: $GLIBC_CC -o $GLIBC_PROG $GLIBC_SRC michael@0: fi michael@0: michael@0: if [ ! -x $GLIBC_PROG ] michael@0: then michael@0: echo michael@0: echo "Could not create test program $GLIBC_PROG." michael@0: echo michael@0: michael@0: glibc_cleanup michael@0: michael@0: exit michael@0: fi michael@0: michael@0: ## michael@0: ## Execute the dummy test program michael@0: ## michael@0: GLIBC_PROG_OUTPUT=`$GLIBC_PROG` michael@0: michael@0: ## michael@0: ## -g | --is-glibc2 michael@0: ## michael@0: if [ "$GLIBC_PRINT_IS_GLIBC2" = "True" ] michael@0: then michael@0: if [ "$GLIBC_PROG_OUTPUT" = "2" ] michael@0: then michael@0: echo True michael@0: else michael@0: echo False michael@0: fi michael@0: michael@0: glibc_cleanup michael@0: michael@0: exit 0 michael@0: fi michael@0: michael@0: echo $GLIBC_PROG_OUTPUT michael@0: michael@0: glibc_cleanup