1#!/bin/bash
2# Copyright (C) 2011 GAMS Development and others
3# All Rights Reserved.
4# This file is distributed under the Eclipse Public License.
5#
6# Author: Michael Bussieck, Stefan Vigerske
7
8gamspath="$1"
9
10if test -z "$gamspath" ; then
11  echo "Need to get path of GAMS system as first argument."
12  exit 1
13fi
14
15# TODO adapt for DOS ?
16#gmscmp=${gamspath}/gmscmpNT.txt
17gmscmp="${gamspath}/gmscmpun.txt"
18
19#libname="libGamsCoin.dll";
20lib=`pwd`"/lib/libgamsscip.so";
21
22gmscmporig="${gmscmp}.orig"
23gmscmpbak="${gmscmp}.bak"
24
25if ! test -r "$gmscmp" ;
26then
27   echo "File $gmscmp not found or not readable, cannot edit."
28   exit 1
29fi
30
31if ! test -e "$lib"
32then
33   echo "Solver library $lib not found, cannot install."
34   exit 1
35fi
36
37echo "Adding or updating entry for SCIPDEV into $gmscmp (pointing to $lib)."
38
39# keep backup of original gmscmpun.txt file
40if ! test -r "$gmscmporig"
41then
42   cp "$gmscmp" "$gmscmporig"
43fi
44
45# keep backup of current gmscmpun.txt file
46cp -f "$gmscmp" "$gmscmpbak"
47
48awk -v lib="$lib" '
49BEGIN {
50   fileType      = 111;
51   dictType      = 0;
52   licCodes      = "0001020304";
53   defaultOkFlag = 1;
54   hiddenFlag    = 0;
55   # TODO adapt for DOS
56   #scriptCmd  = "gmsgennt.cmd";
57   #execCmd    = "gmsgennx.exe";
58   scriptCmd = "gmsgenus.run";
59   execCmd   = "gmsgenux.out";
60
61   written["SCIPDEV"] = 0;
62   libid["SCIPDEV"] = "scp";
63   dicttype["SCIPDEV"] = 5;
64   modeltypes["SCIPDEV"] = "RMIP MIP QCP RMIQCP NLP DNLP RMINLP CNS MIQCP MINLP";
65
66   startBlock = 0;
67}
68
69function writeConfig(solverID) {
70   print solverID, fileType, dicttype[solverID], licCodes, defaultOkFlag, hiddenFlag, "2", modeltypes[solverID];
71   print scriptCmd;
72   print execCmd;
73   print lib, libid[solverID], "1";
74   written[solverID] = 1;
75}
76
77(/^\*/ || /^ *$/) { print $0 }
78
79/^DEFAULTS/ {
80   for( solverID in written )
81      if( !written[solverID] )
82      {
83         writeConfig(solverID)
84         print "";
85      }
86   print;
87   next;
88}
89
90!(/^*/ || /^ *$/) {
91   if( startBlock < 0 )
92   {
93      startBlock++;
94      next;
95   }
96   if( $1 in written && !written[$1] )
97   {
98      writeConfig($1)
99      startBlock = -($7+1);
100      next;
101   }
102   print;
103}
104' $gmscmpbak > $gmscmp
105
106
107#echo "Installing $lib in $gamspath"
108
109#if test -e "${gamspath}/$libname" ;
110#then
111#   rm -f "${gamspath}/$libname"
112#fi
113#cp "${libdir}/$libname" "${gamspath}/$libname"
114#ln -s "${libdir}/$libname" "${gamspath}/$libname"
115
116# hide libstdc++ and some other GCC libraries if system files are more recent than what GAMS ships
117if [ -e "${gamspath}/libstdc++.so.6" ] ; then
118  # get highest GLIBCXX dependency from libstdc++.so.6 in GAMS
119  gamsver=`strings ${gamspath}/libstdc++.so.6 | grep "^GLIBCXX_[0-9]" | sort -V | tail -1`
120  # check which libstdc++ is used by libgamsscip.so
121  userlibstdcxx=`ldd lib/libgamsscip.so | grep libstdc++ | awk '{print $3}'`
122  if [ -n "$userlibstdcxx" ] ; then
123    # get highest GLIBCXX dependency from libstdc++.so.6 that is used by SCIP
124    userver=`strings ${userlibstdcxx} | grep "^GLIBCXX_[0-9]" | sort -V | tail -1`
125  fi
126  if [ -n "${gamsver}" ] && [ -n "${userver}" ] ; then
127    # if things worked so far, compare the version numbers (by checking what sort -V lists last)
128    gamsver=${gamsver/GLIBCXX_/}
129    userver=${userver/GLIBCXX_/}
130    echo "libstdc++ versions GAMS: $gamsver   ${userlibstdcxx}: $userver"
131    if [ `printf "$gamsver\n$userver" | sort -V | tail -1` != "$gamsver" ] ; then
132      # hide GCC libraries in GAMS system directory
133      echo "GAMS libstdc++ is older than dependency of libgamsscip.so."
134      for f in libgcc_s.so.1 libstdc++.so.6 libgfortran.so.3 libquadmath.so.0 ; do
135        if [ -e "${gamspath}/$f" ] ; then
136          echo "Moving ${gamspath}/$f to ${gamspath}/${f}.hide"
137          mv "${gamspath}/$f" "${gamspath}/${f}.hide"
138        fi
139      done
140    else
141      echo "GAMS libstdc++ is at least as recent as dependency of libgamsscip.so, so no action needed."
142    fi
143
144  else
145    echo "Could not check GLIBCXX version of libstdc++.so.6 in GAMS directory and SCIP library dependency."
146    echo "If running GAMS/SCIPDEV fails due some missing GLIBCXX version, try removing libstdc++.so.6 from the GAMS system directory."
147  fi
148
149fi
150