File: irafarch.sh

package info (click to toggle)
iraf 2.17-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 95,288 kB
  • sloc: ansic: 228,894; fortran: 75,606; lisp: 18,369; xml: 8,401; sh: 6,111; yacc: 5,648; lex: 596; makefile: 575; asm: 153; csh: 95; sed: 4
file content (160 lines) | stat: -rwxr-xr-x 3,593 bytes parent folder | download
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/bin/sh 
#
#  IRAFARCH -- Determine or set the current platform architecture parameters.
#
#  Usage:       irafarch
#		irafarch -set [<arch>] [opts]
#               irafarch [ -hsi | -nbits | -endian ]
#
#	-mach		print the iraf architecture name [default]
#	-hsi		print the HSI arch
#	-nbits		print number of bits in an int (32 or 64)
#	-endian		print endianness of platform (big or little)
#
#	-actual		print actual architecture name regardless of IRAFARCH
#	-set <arch>	manually reset the iraf environment architecture
#
# ----------------------------------------------------------------------------


##############################################################################
# START OF MACHDEP DEFINITIONS.
##############################################################################

debug=0

# Get the Utility aliases.
# Initialize the $iraf and environment.
if [ -z "$iraf" ]; then
  bindir=$(dirname "$0")                # get iraf root directory 
  iraf=${bindir%/*}/../
fi
. "${iraf}/unix/hlib/util.sh"


#----------------------------------
# Determine platform architecture.
#----------------------------------

if [ -e /usr/bin/uname ]; then
    uname_cmd=/usr/bin/uname
elif [ -e /bin/uname ]; then
    uname_cmd=/bin/uname
else
    WARNING  "No 'uname' command found to determine architecture."
    exit 1
fi

export MNAME=$($uname_cmd | tr '[:upper:]' '[:lower:]')

# Allow an IRAFARCH definition in the environment to override.

if [ $# -gt 0 ]; then
    if [ "$1" = "-actual" ]; then
        unset IRAFARCH
	shift
    elif [ "$1" = "-current" ]; then
        export IRAFARCH=$(ls -lad "$iraf/bin" | \
			awk '{ printf ("%s\n", $11) }' | \
			sed -e 's/bin.//g')
	shift
    elif [ "$1" = "-set" ]; then
	export IRAFARCH=$2
    fi
fi


# Set some common defaults for most platforms

if [ $debug = 1 ]; then				# DEBUG PRINT
    if [ -n "$IRAFARCH" ]; then
        ECHO " IRAFARCH=$IRAFARCH"
    fi
    ECHO "    MNAME=$MNAME"
fi


# Determine parameters for each architecture.
if [ -n "$IRAFARCH" ]; then
    mach="$IRAFARCH"
    if [ "$mach" = "macintel" ] || [ "$mach" = "macos64" ] || [ "$mach" = "freebsd64" ] || [ "$mach" = "linux64" ]; then
	nbits=64
    else
	nbits=32
    fi
else
    nbits=$(getconf LONG_BIT)
    case "$MNAME" in
     "darwin")		# Mac OS X
	 if [ "$nbits" = 64 ] ; then
	     if [ "$(uname -m)" = "x86_64" ] ; then
	         mach="macintel"
             else
                 mach="macos64"
	     fi
	 else
             mach="macosx"
         fi
         ;;

     "linux")
	 if [ "$nbits" = 64 ] ; then
             mach="linux64"
	 else
	     mach="linux"
         fi
         ;;

     "*freebsd")
	 if [ "$nbits" = 64 ] ; then
             mach="freebsd64"
         else
             mach="freebsd"
         fi
         ;;
     "gnu"|"hurd") # GNU HURD
         mach="hurd"
         ;;

    *)
	ECHO  "Unable to determine platform architecture for ($MNAME)."
	exit 1
	;;
    esac
fi
if [ "$(printf 'I' | od -to2 | awk 'FNR==1{ print substr($2,6,1)}')" = "0" ] ; then
    endian="big"
else
    endian="little"
fi

##############################################################################
# END OF MACHDEP DEFINITIONS.
##############################################################################

# Handle any command-line options.
if [ $# = 0 ]; then
    ECHO $mach
else
    case "$1" in
    "-mach"|"-hsi")
	ECHO "$mach"
	;;
    "-nbits")
	ECHO "$nbits"
	;;
    "-endian")
	ECHO "$endian"
	;;
    "-set")
	if [ -n "$2" ]; then
	    export IRAFARCH=$2
	fi
	export MNAME=$IRAFARCH
	;;
    *)
	ECHO 'Invalid option '"$1"
	;;
    esac
fi