Subversion Repositories f9daq

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
145 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 n ot 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/MIKRO ]; then
120
      cd $startdir/MIKRO
121
      rm -f $startdir/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/camac_gui_windowed ]; then
131
      mkdir $startdir/camac_gui_windowed
132
      mkdir $startdir/camac_gui_windowed/results
133
      echo "Copying source files to temporary directory $startdir/camac_gui_windowed..."
134
      cp -r configure daq.h daqscope.h GuiLinkDef.h libxxusb.cpp root_include.h README start.cxx windowed_test.C windowed_test.h wusbcc.h wusbxx_dll.c wusbxx_dll.h mpod/ MIKRO/ vxi11_x86_64/ vxi11_i686/ input/ fieldpoint/ ./camac_gui_windowed/
135
      cd $startdir/camac_gui_windowed
136
      echo "Cleaning the base directory in $startdir/camac_gui_windowed..."
137
      rm -f *.bakc
138
      cd $startdir/camac_gui_windowed/input
139
      echo "Cleaning the input directory in $startdir/camac_gui_windowed/input..."
140
      rm -f *.bak
141
      cd $startdir/camac_gui_windowed/vxi11_x86_64
142
      echo "Cleaning the 64 bit VXI11 directory in $startdir/camac_gui_windowed/vxi11_x86_64..."
143
      rm -f *.bak
144
      make clean
145
      cd $startdir/camac_gui_windowed/vxi11_i686
146
      echo "Cleaning the 32 bit VXI11 directory in $startdir/camac_gui_windowed/vxi11_i686..."
147
      rm -f *.bak
148
      make clean
149
      cd $startdir
150
      echo "Creating a tar-ball camac_gui_windowed.tar.gz..."
151
      tar czf $startdir/camac_gui_windowed.tar.gz ./camac_gui_windowed
152
      echo "Removing the temporary directory $startdir/camac_gui_windowed..."
153
      rm -r $startdir/camac_gui_windowed
154
      exit 0
155
    else
156
      errorecho "Error! Directory ./camac_gui_windowed already exists."
157
      exit 1
158
    fi
159
  fi
160
 
161
  # Configure the workstation information and directory of program (0 if we find something and 1 otherwise)
162
  basedir=$(echo $startdir | sed 's/\//\\\//g')
163
 
164
  if [ "$1" == "nomake" ] || [ "$1" == "all" ]; then
165
    if [ "$2" == "O" ] || [ "$2" == "I" ] || [ "$2" == "S" ]; then
166
      # Setting up the current working computer
167
      grep -q "#define WORKSTAT 'N'" $startdir/input/workstation.h.in
168
      if [ $? == 0 ]; then
169
        sed "s/define WORKSTAT 'N'/define WORKSTAT '$2'/" $startdir/input/workstation.h.in > $startdir/input/workstation.h.mid
170
      fi
171
      grep -q "#define rootdir \"path-to-installation\"" $startdir/input/workstation.h.in
172
      if [ $? == 0 ]; then
173
        sed "s/path-to-installation/$basedir/g" $startdir/input/workstation.h.mid > $startdir/input/workstation.h.mid2
174
        rm $startdir/input/workstation.h.mid
175
      fi
176
      # Check if we are connected to IJS network
177
      etnet=$(ifconfig | grep "178.172.43.")
178
      if [ "$etnet" == "" ]; then
179
	sed "s/define IJSNET 1/define IJSNET 0/" $startdir/input/workstation.h.mid2 > $startdir/workstation.h
180
	rm $startdir/input/workstation.h.mid2
181
      else
182
	cp $startdir/input/workstation.h.mid2 $startdir/workstation.h
183
	rm $startdir/input/workstation.h.mid2
184
      fi
185
      # Setting up the OS type specific files
186
      grep -q "#include \"vxi11_user.h\"" $startdir/input/daqscope.C.in
187
      if [ $? == 0 ]; then
188
	sed "s/vxi11_user.h/.\/vxi11_$ostype\/vxi11_user.h/g" $startdir/input/daqscope.C.in > $startdir/daqscope.C
189
      fi
190
      grep -q "SHLIB = \$(LIBFILE) libvxi11.a" $startdir/input/Makefile.in
191
      if [ $? == 0 ]; then
192
	if [ "$2" == "I" ]; then
193
	  sed "s/SHLIB = \$(LIBFILE) libvxi11.a/SHLIB = \$(LIBFILE) libvxi11.a -lusb/g" $startdir/input/Makefile.in > $startdir/Makefile.mid
194
	fi
195
      fi
196
      grep -q "CAMLIB = \$(LIBFILE)" $startdir/input/Makefile.in
197
      if [ $? == 0 ]; then
198
	if [ "$2" == "I" ]; then
199
	  sed "s/CAMLIB = \$(LIBFILE)/CAMLIB = \$(LIBFILE) -lusb/g" $startdir/Makefile.mid > $startdir/Makefile.mid2
200
	  rm $startdir/Makefile.mid
201
        elif [ "$2" == "O" ] || [ "$2" == "S" ]; then
202
	  cp $startdir/input/Makefile.in $startdir/Makefile.mid2
203
        fi
204
      fi
205
      sed "s/OSTYPE=none/OSTYPE=$ostype/g" $startdir/Makefile.mid2 > $startdir/Makefile
206
      rm $startdir/Makefile.mid2
207
 
208
      if [ "$2" == "O" ] || [ "$2" == "S" ]; then
209
        cp $startdir/input/daqusb.C.offline $startdir/daqusb.C
210
	cp $startdir/input/libxxusb.h.offline $startdir/libxxusb.h
211
	cp $startdir/input/usb.h.offline $startdir/usb.h
212
      elif [ "$2" == "I" ]; then
213
        cp $startdir/input/daqusb.C.online $startdir/daqusb.C
214
	cp $startdir/input/libxxusb.h.online $startdir/libxxusb.h
215
      fi
216
 
217
      echo "#!/bin/bash" > $startdir/start.sh
218
      echo "dir=\`dirname \$0\`" >> $startdir/start.sh
219
      echo "" >> $startdir/start.sh
220
      echo "snmpdirectory=$snmpdirectory" >> $startdir/start.sh
221
      echo "rootdirectory=$rootdirectory" >> $startdir/start.sh
222
      echo "" >> $startdir/start.sh
223
      cat $startdir/input/start.sh.in >> $startdir/start.sh
224
      chmod a+x $startdir/start.sh
225
    fi
226
  fi
227
 
228
  # In case we just want to set the workstation information, exit here
229
  if [ "$1" == "nomake" ]; then
230
    exit 0
231
  fi
232
 
233
  # 64 bit configuration rules
234
  if [ $ostype == "x86_64" ]; then
235
    vxidir=$startdir/vxi11_$ostype
236
    if [ -d $vxidir ]; then
237
      cd $vxidir
238
      if [ "$1" == "clean" ]; then
239
        make clean
240
	cd $startdir
241
	make clean
242
	rm -f Makefile
243
      else
244
        if [ "$2" == "O" ] || [ "$2" == "I" ] || [ "$2" == "S" ]; then
245
          make
246
	else
247
          errorecho "Error! No configuration type selected (second argument)."
248
	  echo ""
249
	  helptext
250
	  exit 1
251
	fi
252
      fi
253
      cd $startdir
254
    else
255
      errorecho "No 64 bit VXI11 source folder."
256
      exit 1
257
    fi
258
  # 32 bit configuration rules
259
  elif [ $ostype == "i686" ]; then
260
    vxidir=$startdir/vxi11_$ostype
261
    if [ -d $vxidir ]; then
262
      cd $vxidir
263
      if [ "$1" == "clean" ]; then
264
        make clean
265
	cd $startdir
266
	make clean
267
	rm -f Makefile
268
      else
269
        if [ "$2" == "O" ] || [ "$2" == "I" ] || [ "$2" == "S" ]; then
270
          make
271
	else
272
          errorecho "Error! No installation type selected (second argument)."
273
	  echo ""
274
	  helptext
275
	  exit 1
276
	fi
277
      fi
278
      cd $startdir
279
    else
280
      errorecho "No 32 bit VXI11 source folder."
281
      exit 1
282
    fi
283
  else
284
    errorecho "No OS type information found."
285
    exit 1
286
  fi
287
fi
288
 
289
exit 0