Subversion Repositories f9daq

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
146 f9daq 1
#!/bin/bash
2
 
3
function colorecho
4
{
5
  echo -e$2 "\033[33m$1\033[39m"
6
}
7
 
8
function errorecho
9
{
10
  echo -e "\031[33m$1\033[39m"
11
}
12
 
13
function helptext()
14
{
15
  colorecho "#------------------------------"
16
  colorecho "# Configure instructions: -----"
17
  colorecho "#------------------------------"
18
  colorecho ""
19
  colorecho "./configure [option] [type] [install directories] [ostype]"
20
  colorecho ""
21
  colorecho "[option] = Option for configure:"
22
  colorecho "  help		Display configure instructions."
23
  colorecho "  nomake	Only prepare system dependent files (base directory and online/offline mode)."
24
  colorecho "  all		Prepare system dependent files and make used libraries."
25
  colorecho "  clean		Clean the installation directory. Does not clean the results directory."
26
  colorecho "  compress	Compress the source code in a tar-ball."
27
  colorecho ""
28
  colorecho "[type] = Configure for use in online or offline mode (only needed in nomake and all):"
29
  colorecho "  I	Online mode."
30
  colorecho "  O	Offline mode (no connection to CAMAC, motor, voltage supply and scope)."
31
  colorecho "  S	Offline mode with scope connection (no connection to CAMAC, motor and voltage supply)."
32
  colorecho ""
33
  colorecho "[install directories] = Directories where ROOT and NET-SNMP are installed (when running with superuser, this is important, otherwise optional):"
34
  colorecho "  --root-install=/root/install/directory"
35
  colorecho "  --snmp-install=/snmp/install/directory"
36
  colorecho ""
37
  colorecho "[ostype] = Specific setting for 64bit or 32bit version of OS (optional):"
38
  colorecho "  --ostype=i686		32bit OS type"
39
  colorecho "  --ostype=x86_64	64bit OS type"
40
  colorecho ""
41
  colorecho "Example:"
42
  colorecho "  ./configure all I --root-install=/home/user/root --snmp-install=/home/user/snmp"
43
  colorecho ""
44
  colorecho "#------------------------------"
45
}
46
 
47
# Check for arguments
48
if [ "$1" == "" ]; then
49
  errorecho "Error! No arguments supplied."
50
  echo ""
51
  helptext
52
  exit 1
53
else
54
  # When using help, only display help and then exit
55
  if  [ "$1" == "help" ]; then
56
    helptext
57
    exit 0
58
  fi
59
 
60
  # Print help and exit if we give a wrong first argument
61
  if  [ "$1" != "nomake" ] && [ "$1" != "all" ] && [ "$1" != "clean" ] && [ "$1" != "compress" ]; then
62
    errorecho "Error! Wrong configuration option selected (first argument)."
63
    echo ""
64
    helptext
65
    exit 1
66
  fi
67
 
68
  startdir=$PWD
69
 
70
  # Check for ROOT and NET-SNMP install directories and for OS type
71
  snmpsearch="--snmp-install="
72
  rootsearch="--root-install="
73
  ossearch="--ostype="
74
  snmpdirectory=-1
75
  rootdirectory=-1
76
  osmanual=-1
77
  for var in $@
78
  do
79
    case $var in
80
      "$snmpsearch"*)
81
        snmpdirectory=${var#$snmpsearch}
82
        echo "NET-SNMP directory: $snmpdirectory";;
83
      "$rootsearch"*)
84
        rootdirectory=${var#$rootsearch}
85
        echo "ROOT directory: $rootdirectory";;
86
      "$ossearch"*)
87
        osmanual=${var#$ossearch};;
88
      *) ;;
89
    esac 
90
  done   
91
 
92
  # If not supplied, check automatically for OS type
93
  if [ $osmanual == -1 ]; then
94
    ostype=`uname -p`
95
    if [  "$ostype" != "x86_64" ] && [ "$ostype" != "i686" ]; then
96
      ostype=`uname -i`
97
      if  [ "$ostype" != "x86_64" ] && [ "$ostype" != "i686" ]; then
98
         ostype=`uname -m`
99
      fi 
100
    fi
101
  else
102
    ostype=$osmanual
103
  fi
104
 
105
  # Check for installation directory of ROOT - if variables not currently set, remind user to set them before running make
106
  if [ "$1" != "clean" ] && [ "$1" != "compress" ]; then
107
    if [ $rootdirectory != -1 ]; then
108
      printenv ROOTSYS > /dev/null
109
      if [ $? != 0 ]; then
110
        colorecho "ROOT environment variables not set. Please run \"source $rootdirectory/bin/thisroot.sh\", before using make."
111
      fi
112
    else
113
      colorecho "Before running make, please make sure ROOT environment variables are set."
114
    fi
115
  fi
116
 
117
  # Compiles the table microcontroller program
118
  if [ "$1" == "all" ]; then
119
    if [ -d $startdir/src/MIKRO ]; then
120
      cd $startdir/src/MIKRO
121
      rm -f $startdir/src/MIKRO/mikro_ctrl
122
      make
123
      cd $startdir
124
    fi
125
  fi
126
 
127
  # When using compress, only create a tar-ball and then exit
128
  if [ "$1" == "compress" ]; then
129
    cd $startdir
130
    if [ ! -d $startdir/sipmscan_trunk ]; then
131
      mkdir $startdir/sipmscan_trunk
132
      mkdir $startdir/sipmscan_trunk/results
133
      mkdir $startdir/sipmscan_trunk/layout
134
      mkdir $startdir/sipmscan_trunk/settings
135
      echo "Copying files to temporary directory $startdir/sipmscan_trunk..."
136
      cp -r configure ./dict ./doc ./include ./input ./src ./sipmscan_trunk/ 
137
      cp -r ./layout/default.layout ./sipmscan_trunk/layout/
138
      echo "default.layout" > ./sipmscan_trunk/layout/selected_layout.txt
139
# TODO - Settings default files
140
      cd $startdir/sipmscan_trunk
141
      echo "Cleaning the base directory in $startdir/sipmscan_trunk..."
142
      rm -f ./*.bak
143
      echo "Cleaning the subdirectories of $startdir/sipmscan_trunk..."
144
      rm -f ./*/*.bak
145
      cd $startdir/sipmscan_trunk/src
146
      rm -f ./*/*.bak
147
      cd $startdir/sipmscan_trunk/include/vxi11_x86_64
148
      echo "Cleaning the 64 bit VXI11 directory in $startdir/sipmscan_trunk/include/vxi11_x86_64..."
149
      rm -f ./*.bak
150
      make clean
151
      cd $startdir/sipmscan_trunk/include/vxi11_i686
152
      echo "Cleaning the 32 bit VXI11 directory in $startdir/sipmscan_trunk/include/vxi11_i686..."
153
      rm -f ./*.bak
154
      make clean
155
      cd $startdir
156
      echo "Creating a tar-ball sipmscan_trunk.tar.gz..."
157
      tar czf $startdir/sipmscan_trunk.tar.gz ./sipmscan_trunk
158
      echo "Removing the temporary directory $startdir/sipmscan_trunk..."
159
      rm -fr $startdir/sipmscan_trunk
160
      exit 0
161
    else
162
      errorecho "Error! Directory ./sipmscan_trunk already exists."
163
      exit 1
164
    fi
165
  fi
166
 
167
  # Configure the workstation information and directory of program (0 if we find something and 1 otherwise)
168
  basedir=$(echo $startdir | sed 's/\//\\\//g')
169
 
170
  if [ "$1" == "nomake" ] || [ "$1" == "all" ]; then
171
    if [ "$2" == "O" ] || [ "$2" == "I" ] || [ "$2" == "S" ]; then
172
      # Setting up the current working computer
173
      grep -q "#define WORKSTAT 'N'" $startdir/input/workstation.h.in
174
      if [ $? == 0 ]; then
175
        sed "s/define WORKSTAT 'N'/define WORKSTAT '$2'/" $startdir/input/workstation.h.in > $startdir/input/workstation.h.mid
176
      fi
177
      grep -q "#define rootdir \"path-to-installation\"" $startdir/input/workstation.h.in
178
      if [ $? == 0 ]; then
179
        sed "s/path-to-installation/$basedir/g" $startdir/input/workstation.h.mid > $startdir/input/workstation.h.mid2
180
        rm $startdir/input/workstation.h.mid
181
      fi
182
      # Check if we are connected to IJS network
183
      etnet=$(ifconfig | grep "178.172.43.")
184
      if [ "$etnet" == "" ]; then
185
	sed "s/define IJSNET 1/define IJSNET 0/" $startdir/input/workstation.h.mid2 > $startdir/include/workstation.h
186
	rm $startdir/input/workstation.h.mid2
187
      else
188
	cp $startdir/input/workstation.h.mid2 $startdir/include/workstation.h
189
	rm $startdir/input/workstation.h.mid2
190
      fi
191
      # Setting up the OS type specific files
192
      grep -q "#include \"vxi11_user.h\"" $startdir/input/daqscope.C.in
193
      if [ $? == 0 ]; then
194
	sed "s/vxi11_user.h/..\/include\/vxi11_$ostype\/vxi11_user.h/g" $startdir/input/daqscope.C.in > $startdir/src/daqscope.C
195
      fi
196
      grep -q "SHLIB = \$(LIBFILE) \$(LDIR)\/libvxi11.a" $startdir/input/Makefile.in
197
      if [ $? == 0 ]; then
198
	if [ "$2" == "I" ]; then
199
	  sed "s/SHLIB = \$(LIBFILE) \$(LDIR)\/libvxi11.a/SHLIB = \$(LIBFILE) \$(LDIR)\/libvxi11.a -lusb/g" $startdir/input/Makefile.in > $startdir/Makefile.mid
200
	fi
201
      fi
202
      grep -q "CAMLIB = \$(LIBFILE)" $startdir/input/Makefile.in
203
      if [ $? == 0 ]; then
204
	if [ "$2" == "I" ]; then
205
	  sed "s/CAMLIB = \$(LIBFILE)/CAMLIB = \$(LIBFILE) -lusb/g" $startdir/Makefile.mid > $startdir/Makefile.mid2
206
	  rm $startdir/Makefile.mid
207
        elif [ "$2" == "O" ] || [ "$2" == "S" ]; then
208
	  cp $startdir/input/Makefile.in $startdir/Makefile.mid2
209
        fi
210
      fi
211
      sed "s/OSTYPE=none/OSTYPE=$ostype/g" $startdir/Makefile.mid2 > $startdir/Makefile
212
      rm $startdir/Makefile.mid2
213
 
214
      if [ "$2" == "O" ] || [ "$2" == "S" ]; then
215
        cp $startdir/input/daqusb.C.offline $startdir/src/daqusb.C
216
	cp $startdir/input/libxxusb.h.offline $startdir/include/libxxusb.h
217
	cp $startdir/input/usb.h.offline $startdir/include/usb.h
218
      elif [ "$2" == "I" ]; then
219
        cp $startdir/input/daqusb.C.online $startdir/src/daqusb.C
220
	cp $startdir/input/libxxusb.h.online $startdir/include/libxxusb.h
221
      fi
222
 
223
      echo "#!/bin/bash" > $startdir/start.sh
224
      echo "dir=\`dirname \$0\`" >> $startdir/start.sh
225
      echo "" >> $startdir/start.sh
226
      echo "snmpdirectory=$snmpdirectory" >> $startdir/start.sh
227
      echo "rootdirectory=$rootdirectory" >> $startdir/start.sh
228
      echo "" >> $startdir/start.sh
229
      cat $startdir/input/start.sh.in >> $startdir/start.sh
230
      chmod ug+x $startdir/start.sh
231
    fi
232
  fi
233
 
234
  # In case we just want to set the workstation information, exit here
235
  if [ "$1" == "nomake" ]; then
236
    exit 0
237
  fi
238
 
239
  # 64 bit configuration rules
240
  if [ $ostype == "x86_64" ]; then
241
    vxidir=$startdir/include/vxi11_$ostype
242
    if [ -d $vxidir ]; then
243
      cd $vxidir
244
      if [ "$1" == "clean" ]; then
245
        make clean
246
	cd $startdir
247
	make clean
248
	rm -f Makefile
249
      else
250
        if [ "$2" == "O" ] || [ "$2" == "I" ] || [ "$2" == "S" ]; then
251
          make
252
	else
253
          errorecho "Error! No configuration type selected (second argument)."
254
	  echo ""
255
	  helptext
256
	  exit 1
257
	fi
258
      fi
259
      cd $startdir
260
    else
261
      errorecho "No 64 bit VXI11 source folder."
262
      exit 1
263
    fi
264
  # 32 bit configuration rules
265
  elif [ $ostype == "i686" ]; then
266
    vxidir=$startdir/include/vxi11_$ostype
267
    if [ -d $vxidir ]; then
268
      cd $vxidir
269
      if [ "$1" == "clean" ]; then
270
        make clean
271
	cd $startdir
272
	make clean
273
	rm -f Makefile
274
      else
275
        if [ "$2" == "O" ] || [ "$2" == "I" ] || [ "$2" == "S" ]; then
276
          make
277
	else
278
          errorecho "Error! No installation type selected (second argument)."
279
	  echo ""
280
	  helptext
281
	  exit 1
282
	fi
283
      fi
284
      cd $startdir
285
    else
286
      errorecho "No 32 bit VXI11 source folder."
287
      exit 1
288
    fi
289
  else
290
    errorecho "No OS type information found."
291
    exit 1
292
  fi
293
fi
294
 
295
exit 0