/ani/mrses

To get this branch, use:
bzr branch http://suren.me/webbzr/ani/mrses
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/bin/sh
# --------------------------------------------------------------
# (C) Copyright 2001,2007,
# International Business Machines Corporation,
#
# All Rights Reserved.
# --------------------------------------------------------------

#------------------------------------------------------------------------
#  cellsdk_select_compiler
#
#  This script selects the compiler in make.env
#
#------------------------------------------------------------------------

#
# Miscellaneous variables
#
if [ -f ${CELL_TOP}/buildutils/make.env ] ; then
	CELL_BUILD_DIR=$CELL_TOP
else
	CELL_BUILD_DIR=/opt/cell/sdk
fi
CELL_MAKE_ENV=${CELL_BUILD_DIR}/buildutils/make.env
CELL_MAKE_FOOTER=${CELL_BUILD_DIR}/buildutils/make.footer

#--------------------------------------------------------------------------
# Switches to the gcc compiler
#
# return: none
function switch_to_gcc()
{
  # abort if gcc is not installed
  which `PROGRAM_ppu=foo PPU_COMPILER=gcc make --no-print-directory CCACHE="" -f ${CELL_MAKE_FOOTER} listenv_c 2>/dev/null` >/dev/null 2>&1
  if [ $? -ne 0 ] ; then
        echo "gcc is not installed - can't change default to gcc."
  elif [ "`grep "^ .*_COMPILER.*:= gcc" ${CELL_MAKE_ENV}`" == "" ] ; then
	sed -i -e 's/^    PPU32_COMPILER	:= xlc/#   PPU32_COMPILER	:= xlc/' \
	       -e 's/^#   PPU32_COMPILER	:= gcc/    PPU32_COMPILER	:= gcc/' \
	       -e 's/^    PPU64_COMPILER	:= xlc/#   PPU64_COMPILER	:= xlc/' \
	       -e 's/^#   PPU64_COMPILER	:= gcc/    PPU64_COMPILER	:= gcc/' \
	       -e 's/^    SPU_COMPILER	:= xlc/#   SPU_COMPILER	:= xlc/' \
	       -e 's/^#   SPU_COMPILER	:= gcc/    SPU_COMPILER	:= gcc/' \
	    ${CELL_MAKE_ENV} && echo "Default compiler changed to GNU gcc."
  else
      echo "Default compiler is already set to GNU gcc."
  fi
}

#--------------------------------------------------------------------------
# Switches to the gfortran
#
function switch_to_gfortran()
{
  # abort if gfortran is not installed
  which `PROGRAM_ppu=foo FTN_PPU32_COMPILER=gfortran FTN_PPU64_COMPILER=gfortran make --no-print-directory -f ${CELL_MAKE_FOOTER} listenv_f 2>/dev/null` >/dev/null 2>&1
  if [ $? -ne 0 ] ; then
        echo "gfortran is not installed - can't change default to gfortran."
  elif [ "`grep "^ .*_COMPILER.*:= gfortran" ${CELL_MAKE_ENV}`" == "" ] ; then
	sed -i -e 's/^    FTN_PPU32_COMPILER	:= xlf/#   FTN_PPU32_COMPILER	:= xlf/' \
	       -e 's/^#   FTN_PPU32_COMPILER	:= gfortran/    FTN_PPU32_COMPILER	:= gfortran/' \
	       -e 's/^    FTN_PPU64_COMPILER	:= xlf/#   FTN_PPU64_COMPILER	:= xlf/' \
	       -e 's/^#   FTN_PPU64_COMPILER	:= gfortran/    FTN_PPU64_COMPILER	:= gfortran/' \
	       -e 's/^    FTN_SPU_COMPILER	:= xlf/#   FTN_SPU_COMPILER	:= xlf/' \
	       -e 's/^#   FTN_SPU_COMPILER	:= gfortran/    FTN_SPU_COMPILER	:= gfortran/' \
	    ${CELL_MAKE_ENV} && echo "Default compiler changed to GNU gfortran."
  else
      echo "Default compiler is already set to GNU gfortran."
  fi
}

#--------------------------------------------------------------------------
# Switches to the xlc compiler
#
function switch_to_xlc()
{
  # abort if xlc is not installed
  which `PROGRAM_ppu=foo PPU_COMPILER=xlc make --no-print-directory -f ${CELL_MAKE_FOOTER} listenv_c 2>/dev/null` >/dev/null 2>&1
  if [ $? -ne 0 ] ; then
        echo "xlc is not installed - can't change default to xlc."
  elif [ "`grep "^ .*_COMPILER.*:= xlc" ${CELL_MAKE_ENV}`" == "" ] ; then
	sed -i -e 's/^#   PPU32_COMPILER	:= xlc/    PPU32_COMPILER	:= xlc/' \
	       -e 's/^    PPU32_COMPILER	:= gcc/#   PPU32_COMPILER	:= gcc/' \
	       -e 's/^#   PPU64_COMPILER	:= xlc/    PPU64_COMPILER	:= xlc/' \
	       -e 's/^    PPU64_COMPILER	:= gcc/#   PPU64_COMPILER	:= gcc/' \
	       -e 's/^#   SPU_COMPILER	:= xlc/    SPU_COMPILER	:= xlc/' \
	       -e 's/^    SPU_COMPILER	:= gcc/#   SPU_COMPILER	:= gcc/' \
	    ${CELL_MAKE_ENV} && echo "Default compiler changed to IBM xlc."
  else
      echo "Default compiler is already set to IBM xlc."
  fi
}

#--------------------------------------------------------------------------
# Switches to the xlf compiler
#
function switch_to_xlf()
{
  # warn if xlf is not installed
  which `PROGRAM_ppu=foo FTN_PPU32_COMPILER=xlf FTN_PPU64_COMPILER=xlf make --no-print-directory -f ${CELL_MAKE_FOOTER} listenv_f 2>/dev/null` >/dev/null 2>&1
  if [ $? -ne 0 ] ; then
        echo "xlf is not installed - can't change default to xlf."
  elif [ "`grep "^ .*_COMPILER.*:= xlf" ${CELL_MAKE_ENV}`" == "" ] ; then
	sed -i -e 's/^#   FTN_PPU32_COMPILER	:= xlf/    FTN_PPU32_COMPILER	:= xlf/' \
	       -e 's/^    FTN_PPU32_COMPILER	:= gfortran/#   FTN_PPU32_COMPILER	:= gfortran/' \
	       -e 's/^#   FTN_PPU64_COMPILER	:= xlf/    FTN_PPU64_COMPILER	:= xlf/' \
	       -e 's/^    FTN_PPU64_COMPILER	:= gfortran/#   FTN_PPU64_COMPILER	:= gfortran/' \
	       -e 's/^#   FTN_SPU_COMPILER	:= xlf/    FTN_SPU_COMPILER	:= xlf/' \
	       -e 's/^    FTN_SPU_COMPILER	:= gfortran/#   FTN_SPU_COMPILER	:= gfortran/' \
	    ${CELL_MAKE_ENV} && echo "Default compiler changed to IBM xlf."
  else
      echo "Default compiler is already set to IBM xlf."
  fi
}


#--------------------------------------------------------------------------
# Displays the usage statement
#
function usage()
{
  echo "Usage: $SELF <gcc | gfortran | gnu | xlc | xlf | xl> "
  echo ""
  echo "  gcc:      set GNU gcc as default c/c++ compiler in make.footer (default)"
  echo "  gfortran: set GNU gfortran as default fortran compiler in make.footer (default)"
  echo "  gnu:      set both GNU gcc and gfortran as default compilers in make.footer (default)"
  echo "  xlc:      set IBM xlc as default c/c++ compiler in make.footer"
  echo "  xlf:      set IBM xlf as default fortran compiler in make.footer"
  echo "  xl:       set IBM xlc and xlf as default compilers in make.footer"
  echo ""
}


#--------------------------------------------------------------------------
# Continue with main line execution of script


#  Set our name
SELF=`basename $0`

#  Ensure we have at least one argument
if [ $# -lt 1 ] ; then
  usage
  exit 1
fi

#  Pop the first argument as the task
TASK=$1
shift

case $TASK in
  gcc|gfortran|gnu|xlc|xlf|xl)
    if [ ! -w ${CELL_MAKE_ENV} ] ; then
	echo ${CELL_MAKE_ENV} "not writable"
	exit 1
    fi
    ;;

  -?|-h|--help|--usage)
    usage
    exit 0
    ;;

  *)
    echo "$SELF:  unknown option '$TASK'"
    usage
    exit 1
    ;;

esac

case $TASK in
 	gcc)
		switch_to_gcc
		;;
 	gfortran)
		switch_to_gfortran
		;;
 	gnu)
		switch_to_gcc
		switch_to_gfortran
		;;

 	xlc)
		switch_to_xlc
		;;
 	xlf)
		switch_to_xlf
		;;
 	xl)
		switch_to_xlc
		switch_to_xlf
		;;
	*)
		usage
		exit 1
		;;
esac

# end of script