summaryrefslogtreecommitdiffstats
path: root/glselect.function
blob: d0758500437107acc8993f9162ba0bd0edde2ba8 (plain) (blame)
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
#---
## glselect - select default libGL provider
## rewritten from smgl-gl_select
##
## this is run in FINAL and will always set the provider
## based on the final spell cast that calls this.
## If one wants to have this settable runtime then
## there's the smgl-gl_select tool to do so
##
#---

function glselect(){
  # get all available GL providers
  local gl_libs="$(ls -1 --color=none ${TRACK_ROOT}/usr/lib/*/libGL.so \
                   | awk -F"/" '{print $4}' 2> /dev/null )"
  # where to store the filelists
  local gl_filelist_dir="$GRIMOIRE/.glselect"
  local orig_file new_file
  local gl_lib=$1
  if ! grep -q "$gl_lib" <<< "$gl_libs"
  then
    message "Error $gl_lib is not a valid GL Library"
    exit 1
  fi
  message "Selecting $gl_lib as the default system GL library"
  if [[ -L ${INSTALL_ROOT}/usr/lib/libGL.so ]] ||
     [[ ! -e ${INSTALL_ROOT}/usr/lib/libGL.so ]]
  then
    message "Cleaning all previous GL providers..."
    for orig_file in $(grep "/ati" $gl_filelist_dir/ati-filelist)
    do
      new_file=${orig_file/\/ati}
      rm -f $new_file
      echo -n "."
    done
    echo -n "."
    orig_file=""
    for orig_file in $(grep "/mesa" $gl_filelist_dir/mesa-filelist)
    do
      new_file=${orig_file/\/mesa}
      rm -f $new_file
      echo -n "."
    done
    echo -n "."
    orig_file=""
    for orig_file in $(grep "/nvidia" $gl_filelist_dir/nvidia-filelist)
    do
      new_file=${orig_file/\/nvidia}
      rm -f $new_file
      echo -n "."
    done
    orig_file=""
    echo ""
    message "Done."
    message "Setting up new GL provider $gl_lib..."
    case "$1" in
       ati)
            for orig_file in $(grep "/mesa" $gl_filelist_dir/ati-filelist)
            do
              new_file=${orig_file/\/mesa}
              ln -sf ${INSTALL_ROOT}${orig_file} \
                     ${INSTALL_ROOT}${new_file} 2>/dev/null
              echo -n "."
            done
            orig_file=""
            for orig_file in $(grep "/ati" $gl_filelist_dir/ati-filelist)
            do
              new_file=${orig_file/\/ati}
              ln -sf ${INSTALL_ROOT}${orig_file} \
                     ${INSTALL_ROOT}${new_file} 2>/dev/null
              echo -n "."
            done
            ;;
      mesa) 
            for orig_file in $(cat $gl_filelist_dir/mesa-filelist)
            do
              new_file=${orig_file/\/mesa}
              ln -sf ${INSTALL_ROOT}${orig_file} \
                     ${INSTALL_ROOT}${new_file} 2>/dev/null
              echo -n "."
            done
            ;;
    nvidia) 
            for orig_file in $(grep "/mesa" $gl_filelist_dir/nvidia-filelist)
            do
              new_file=${orig_file/\/mesa}
              ln -sf ${INSTALL_ROOT}${orig_file} \
                     ${INSTALL_ROOT}${new_file} 2>/dev/null
              echo -n "."
            done
            orig_file=""
            for orig_file in $(grep "/nvidia" $gl_filelist_dir/nvidia-filelist)
            do
              new_file=${orig_file/\/nvidia}
              ln -sf ${INSTALL_ROOT}${orig_file} \
                     ${INSTALL_ROOT}${new_file} 2>/dev/null
              echo -n "."
            done
            ;;
         *) message "Unknown secondary files so I only linked the libGL.so"
            for orig_file in $(cat $gl_filelist_dir/mesa-filelist)
            do
              new_file=${orig_file/\/mesa}
              ln -sf ${INSTALL_ROOT}${orig_file} \
                     ${INSTALL_ROOT}${new_file} 2>/dev/null
              echo -n "."
            done
            ln -fs ${INSTALL_ROOT}/usr/lib/$gl_lib/libGL.so* \
                   ${INSTALL_ROOT}/usr/lib/ 2>/dev/null
            ;;
      esac
    echo -e "\nDone."
    message "You can manage the libGL providers at runtime by using"
    message "either smgl-gl_select or manually by symlinking the files"
    message "from their respective directories i.e.:"
    message "/usr/lib/[nvidia|ati|mesa]/libGL.so"
    message "/usr/xorg/modules/extensions/[nvidia,ati,mesa]/lib{glx,dri}.so"
    message "/usr/include/GL/[nvidia|mesa]/gl{x,xext,ext}.h"
    message ""
    message "To:"
    message "/usr/lib/libGL.so"
    message "/usr/xorg/modules/extensions/lib{glx,dri}.so"
    message "/usr/include/GL/gl{x,xext,ext}.h"
    message ""
    return 0
  else
    message "Error ${INSTALL_ROOT}/usr/lib/libGL.so is not a symlink"
    message "unable to proceed!!!"
    message "Please recast:"
    message "mesalib, xorg-server and whatever GL driver you use."
    message ""
    message "If this continues to happen please file a bug."
    message ""
    return 1
  fi
}