| 1 | #!/bin/bash |
| 2 | ## change path gfortran lib in freefem install |
| 3 | ## usage : change-dylibgfortran oldlibdir newlibdir libnam1 libnam2 list of dylyb file pathname to change ... |
| 4 | ## F. hecht sep. 2023 on MoOS Ventura , Monterey |
| 5 | ## remark the file $oldlibdir/$libnam1 , ... must exist ... |
| 6 | olddir=$1 |
| 7 | shift |
| 8 | newdir=$1 |
| 9 | shift |
| 10 | lib1=$1 |
| 11 | shift |
| 12 | lib2=$1 |
| 13 | shift |
| 14 | lib3=$1 |
| 15 | shift |
| 16 | |
| 17 | if test -f "$olddir/$lib1" -a -f "$olddir/$lib2" -a -f "$olddir/$lib3" \ |
| 18 | -a -f "$newdir/$lib1" -a -f "$newdir/$lib2" -a -f "$newdir/$lib3"; then |
| 19 | for ff in $@; do |
| 20 | ch=0 |
| 21 | for lib in $lib1 $lib2 $lib3; do |
| 22 | old=$olddir/$lib |
| 23 | new=$newdir/$lib |
| 24 | nnl=$(otool -L $ff | grep $lib | awk '{print $1}') |
| 25 | case $nnl in |
| 26 | /*) old=$nnl ;; |
| 27 | esac |
| 28 | # echo "old .. " $old $nnl |
| 29 | # otool -L $ff|awk "/$lib/ "'{print $1}' |
| 30 | nn=$(otool -L $ff | grep $old | wc -l) |
| 31 | # echo "nn=" $nn $nnl $old |
| 32 | otool -L $ff | grep brew |
| 33 | if test $nn -ne 0; then |
| 34 | # echo ..change $old to $new in $ff |
| 35 | ch=1 |
| 36 | echo change $old to $new1 in $ff |
| 37 | install_name_tool -change $old $new $ff |
| 38 | fi |
| 39 | done |
| 40 | if test $ch -eq 1; then |
| 41 | codesign --remove-signature $ff |
| 42 | codesign -s - $ff |
| 43 | fi |
| 44 | done |
| 45 | else |
| 46 | echo "$olddir/$lib1" "$olddir/$lib2" "$olddir/$lib3" do some not exist! |
| 47 | echo "$newdir/$lib1" "$newdir/$lib2" "$newdir/$lib3" do not exist! |
| 48 | fi |