2010-05-18 19:36:55 +00:00
# TODO gentoo removes some tools because there are xorg sources (?)
source $stdenv /setup
2012-10-07 16:03:06 +00:00
set -x
2010-05-18 19:36:55 +00:00
die( ) { echo $@ ; exit 1; }
2012-10-07 16:03:06 +00:00
unzip $src
2016-05-03 08:54:49 +00:00
run_file = fglrx-$build /amd-driver-installer-$build -x86.x86_64.run
2012-10-07 16:03:06 +00:00
sh $run_file --extract .
2010-05-18 19:36:55 +00:00
2016-05-20 11:05:41 +00:00
for patch in $patches ; do
patch -p1 < $patch
done
2014-09-06 04:17:00 +00:00
case " $system " in
x86_64-linux)
arch = x86_64
lib_arch = lib64
DIR_DEPENDING_ON_XORG_VERSION = xpic_64a
; ;
i686-linux)
arch = x86
lib_arch = lib
DIR_DEPENDING_ON_XORG_VERSION = xpic
; ;
*) exit 1; ;
esac
2014-09-20 12:45:21 +00:00
# Handle/Build the kernel module.
2016-01-20 19:51:52 +00:00
2014-09-06 04:17:00 +00:00
if test -z " $libsOnly " ; then
2010-05-18 19:36:55 +00:00
2016-05-03 08:54:49 +00:00
kernelVersion = $( cd ${ kernelDir } /lib/modules && ls)
kernelBuild = $( echo ${ kernelDir } /lib/modules/$kernelVersion /build)
linuxsources = $( echo ${ kernelDir } /lib/modules/$kernelVersion /source)
2010-05-18 19:36:55 +00:00
2014-09-20 12:45:21 +00:00
# note: maybe the .config file should be used to determine this ?
# current kbuild infrastructure allows using CONFIG_* defines
# but ati sources don't use them yet..
# copy paste from make.sh
2016-01-20 19:51:52 +00:00
2014-09-20 12:45:21 +00:00
setSMP( ) {
2010-05-18 19:36:55 +00:00
2014-09-20 12:45:21 +00:00
linuxincludes = $kernelBuild /include
2010-05-18 19:36:55 +00:00
2014-09-20 12:45:21 +00:00
# copied and stripped. source: make.sh:
# 3
# linux/autoconf.h may contain this: #define CONFIG_SMP 1
2010-05-18 19:36:55 +00:00
2014-09-20 12:45:21 +00:00
# Before 2.6.33 autoconf.h is under linux/.
# For 2.6.33 and later autoconf.h is under generated/.
if [ -f $linuxincludes /generated/autoconf.h ] ; then
autoconf_h = $linuxincludes /generated/autoconf.h
else
autoconf_h = $linuxincludes /linux/autoconf.h
fi
src_file = $autoconf_h
2010-05-18 19:36:55 +00:00
2014-09-20 12:45:21 +00:00
[ -e $src_file ] || die " $src_file not found "
2010-10-26 00:35:38 +00:00
2014-09-20 12:45:21 +00:00
if [ ` cat $src_file | grep "#undef" | grep "CONFIG_SMP" -c` = 0 ] ; then
SMP = ` cat $src_file | grep CONFIG_SMP | cut -d' ' -f3`
echo " file $src_file says: SMP= $SMP "
fi
2010-05-18 19:36:55 +00:00
2014-09-20 12:45:21 +00:00
if [ " $SMP " = 0 ] ; then
echo " assuming default: SMP= $SMP "
fi
# act on final result
if [ ! " $SMP " = 0 ] ; then
smp = "-SMP"
def_smp = -D__SMP__
fi
2010-05-18 19:36:55 +00:00
2014-09-20 12:45:21 +00:00
}
2010-05-18 19:36:55 +00:00
2014-09-20 12:45:21 +00:00
setModVersions( ) {
! grep CONFIG_MODVERSIONS = y $kernelBuild /.config ||
def_modversions = "-DMODVERSIONS"
# make.sh contains much more code to determine this whether its enabled
}
2010-05-18 19:36:55 +00:00
2014-09-20 12:45:21 +00:00
# ==============================================================
# resolve if we are building for a kernel with a fix for CVE-2010-3081
# On kernels with the fix, use arch_compat_alloc_user_space instead
# of compat_alloc_user_space since the latter is GPL-only
2010-10-26 00:35:38 +00:00
2014-09-20 12:45:21 +00:00
COMPAT_ALLOC_USER_SPACE = arch_compat_alloc_user_space
2010-10-26 00:35:38 +00:00
2014-09-20 12:45:21 +00:00
for src_file in \
2010-10-26 00:35:38 +00:00
$kernelBuild /arch/x86/include/asm/compat.h \
$linuxsources /arch/x86/include/asm/compat.h \
$kernelBuild /include/asm-x86_64/compat.h \
$linuxsources /include/asm-x86_64/compat.h \
$kernelBuild /include/asm/compat.h;
2014-09-20 12:45:21 +00:00
do
if [ -e $src_file ] ;
then
break
fi
done
if [ ! -e $src_file ] ;
then
echo "Warning: x86 compat.h not found in kernel headers"
echo "neither arch/x86/include/asm/compat.h nor include/asm-x86_64/compat.h"
echo " could be found in $kernelBuild or $linuxsources "
echo ""
else
if [ ` cat $src_file | grep -c arch_compat_alloc_user_space` -gt 0 ]
then
COMPAT_ALLOC_USER_SPACE = arch_compat_alloc_user_space
fi
echo " file $src_file says: COMPAT_ALLOC_USER_SPACE= $COMPAT_ALLOC_USER_SPACE "
2010-10-26 00:35:38 +00:00
fi
2010-05-18 19:36:55 +00:00
2014-09-20 12:45:21 +00:00
# make.sh contains some code figuring out whether to use these or not..
PAGE_ATTR_FIX = 0
setSMP
setModVersions
CC = gcc
MODULE = fglrx
LIBIP_PREFIX = $TMP /arch/$arch /lib/modules/fglrx/build_mod
[ -d $LIBIP_PREFIX ]
GCC_MAJOR = "`gcc --version | grep -o -e " ) ." | head -1 | cut -d " " -f 2`"
2010-05-18 19:36:55 +00:00
2014-09-20 12:45:21 +00:00
{ # build .ko module
cd ./common/lib/modules/fglrx/build_mod/2.6.x
echo .lib${ MODULE } _ip.a.GCC${ GCC_MAJOR } .cmd
echo 'This is a dummy file created to suppress this warning: could not find /lib/modules/fglrx/build_mod/2.6.x/.libfglrx_ip.a.GCC4.cmd for /lib/modules/fglrx/build_mod/2.6.x/libfglrx_ip.a.GCC4' > lib${ MODULE } _ip.a.GCC${ GCC_MAJOR } .cmd
2010-05-18 19:36:55 +00:00
2014-09-20 12:45:21 +00:00
sed -i -e " s@COMPAT_ALLOC_USER_SPACE@ $COMPAT_ALLOC_USER_SPACE @ " ../kcl_ioctl.c
2012-10-07 16:03:06 +00:00
2014-09-20 12:45:21 +00:00
make CC = ${ CC } \
2010-05-18 19:36:55 +00:00
LIBIP_PREFIX = $( echo " $LIBIP_PREFIX " | sed -e 's|^\([^/]\)|../\1|' ) \
2010-10-26 00:35:38 +00:00
MODFLAGS = " -DMODULE -DATI -DFGL -DPAGE_ATTR_FIX= $PAGE_ATTR_FIX -DCOMPAT_ALLOC_USER_SPACE= $COMPAT_ALLOC_USER_SPACE $def_smp $def_modversions " \
2010-05-18 19:36:55 +00:00
KVER = $kernelVersion \
KDIR = $kernelBuild \
PAGE_ATTR_FIX = $PAGE_ATTR_FIX \
-j4
2014-09-20 12:45:21 +00:00
cd $TMP
}
2010-05-18 19:36:55 +00:00
2014-09-06 04:17:00 +00:00
fi
2010-05-18 19:36:55 +00:00
{ # install
2012-01-18 20:16:00 +00:00
mkdir -p $out /lib/xorg
2010-05-18 19:36:55 +00:00
cp -r common/usr/include $out
cp -r common/usr/sbin $out
cp -r common/usr/share $out
2016-01-20 19:51:52 +00:00
mkdir $out /bin/
cp -f common/usr/X11R6/bin/* $out /bin/
2012-10-07 16:03:06 +00:00
# cp -r arch/$arch/lib $out/lib
2010-05-18 19:36:55 +00:00
# what are those files used for?
cp -r common/etc $out
cp -r $DIR_DEPENDING_ON_XORG_VERSION /usr/X11R6/$lib_arch /* $out /lib/xorg
2014-09-06 04:17:00 +00:00
# install kernel module
if test -z " $libsOnly " ; then
2014-09-20 12:45:21 +00:00
t = $out /lib/modules/${ kernelVersion } /kernel/drivers/misc
mkdir -p $t
2010-05-18 19:36:55 +00:00
2014-09-20 12:45:21 +00:00
cp ./common/lib/modules/fglrx/build_mod/2.6.x/fglrx.ko $t
2014-09-06 04:17:00 +00:00
fi
2010-05-18 19:36:55 +00:00
# should this be installed at all?
# its used by the example fglrx_gamma only
# don't use $out/lib/modules/dri because this will cause the kernel module
# aggregator code to see both: kernel version and the dri direcotry. It'll
# fail saying different kernel versions
cp -r $TMP /arch/$arch /usr/X11R6/$lib_arch /modules/dri $out /lib
cp -r $TMP /arch/$arch /usr/X11R6/$lib_arch /modules/dri/* $out /lib
2013-08-22 10:00:23 +00:00
cp -r $TMP /arch/$arch /usr/X11R6/$lib_arch /*.so* $out /lib
2012-10-07 16:03:06 +00:00
cp -r $TMP /arch/$arch /usr/X11R6/$lib_arch /fglrx/fglrx-libGL.so.1.2 $out /lib/fglrx-libGL.so.1.2
2010-05-18 19:36:55 +00:00
cp -r $TMP /arch/$arch /usr/$lib_arch /* $out /lib
ln -s libatiuki.so.1.0 $out /lib/libatiuki.so.1
2012-10-07 16:03:06 +00:00
ln -s fglrx-libGL.so.1.2 $out /lib/libGL.so.1
ln -s fglrx-libGL.so.1.2 $out /lib/libGL.so
2016-01-20 19:51:52 +00:00
# FIXME : This file is missing or has changed versions
#ln -s libfglrx_gamma.so.1.0 $out/lib/libfglrx_gamma.so.1
2012-10-07 16:03:06 +00:00
# make xorg use the ati version
ln -s $out /lib/xorg/modules/extensions/{ fglrx/fglrx-libglx.so,libglx.so}
2014-09-20 12:34:51 +00:00
# Correct some paths that are hardcoded into binary libs.
if [ " $arch " = = "x86_64" ] ; then
for lib in \
2016-01-20 19:51:52 +00:00
xorg/modules/extensions/fglrx/fglrx-libglx.so \
xorg/modules/glesx.so \
dri/fglrx_dri.so \
fglrx_dri.so \
fglrx-libGL.so.1.2
2014-09-20 12:34:51 +00:00
do
oldPaths = "/usr/X11R6/lib/modules/dri"
newPaths = "/run/opengl-driver/lib/dri"
2016-01-20 19:51:52 +00:00
sed -i -e " s| $oldPaths | $newPaths | " $out /lib/$lib
2014-09-20 12:34:51 +00:00
done
else
oldPaths = "/usr/X11R6/lib32/modules/dri\x00/usr/lib32/dri"
newPaths = "/run/opengl-driver-32/lib/dri\x00/dev/null/dri"
sed -i -e " s| $oldPaths | $newPaths | " \
$out /lib/xorg/modules/extensions/fglrx/fglrx-libglx.so
for lib in \
2016-01-20 19:51:52 +00:00
dri/fglrx_dri.so \
fglrx_dri.so \
xorg/modules/glesx.so
2014-09-20 12:34:51 +00:00
do
oldPaths = "/usr/X11R6/lib32/modules/dri/"
newPaths = "/run/opengl-driver-32/lib/dri"
2016-01-20 19:51:52 +00:00
sed -i -e " s| $oldPaths | $newPaths | " $out /lib/$lib
2014-09-20 12:34:51 +00:00
done
oldPaths = "/usr/X11R6/lib32/modules/dri\x00"
newPaths = "/run/opengl-driver-32/lib/dri"
sed -i -e " s| $oldPaths | $newPaths | " $out /lib/fglrx-libGL.so.1.2
fi
2014-01-22 09:57:43 +00:00
# libstdc++ and gcc are needed by some libs
2016-01-20 19:51:52 +00:00
for pelib1 in \
fglrx_dri.so \
dri/fglrx_dri.so
do
patchelf --remove-needed libX11.so.6 $out /lib/$pelib1
done
for pelib2 in \
libatiadlxx.so \
xorg/modules/glesx.so \
dri/fglrx_dri.so \
fglrx_dri.so \
libaticaldd.so
do
2016-05-03 08:54:49 +00:00
patchelf --set-rpath $glibcDir /lib/:$libStdCxx /lib/ $out /lib/$pelib2
2016-01-20 19:51:52 +00:00
done
2010-05-18 19:36:55 +00:00
}
2014-09-06 04:17:00 +00:00
if test -z " $libsOnly " ; then
2010-05-18 19:36:55 +00:00
{ # build samples
2012-01-18 20:16:00 +00:00
mkdir -p $out /bin
2010-05-18 19:36:55 +00:00
mkdir -p samples
cd samples
tar xfz ../common/usr/src/ati/fglrx_sample_source.tgz
2014-01-22 09:57:43 +00:00
eval " $patchPhaseSamples "
2010-05-18 19:36:55 +00:00
2016-05-20 11:05:41 +00:00
2010-05-18 19:36:55 +00:00
( # build and install fgl_glxgears
2016-05-03 08:54:49 +00:00
cd fgl_glxgears;
2010-05-18 19:36:55 +00:00
gcc -DGL_ARB_texture_multisample= 1 -g \
2019-11-26 15:40:39 +00:00
-I$libGL /include -I$libGLU /include \
2010-05-18 19:36:55 +00:00
-I$out /include \
2019-11-26 15:40:39 +00:00
-L$libGL /lib -L$libGLU /lib -lGL -lGLU -lX11 -lm \
2016-05-03 08:54:49 +00:00
-o $out /bin/fgl_glxgears -Wall fgl_glxgears.c
2010-05-18 19:36:55 +00:00
)
true || ( # build and install
2016-01-20 19:51:52 +00:00
###
## FIXME ?
2010-05-18 19:36:55 +00:00
# doesn't build undefined reference to `FGLRX_X11SetGamma'
2016-01-20 19:51:52 +00:00
# which should be contained in -lfglrx_gamma
# This should create $out/lib/libfglrx_gamma.so.1.0 ? because there is
# a symlink named libfglrx_gamma.so.1 linking to libfglrx_gamma.so.1.0 in $out/lib/
2010-05-18 19:36:55 +00:00
cd programs/fglrx_gamma
2016-04-16 17:57:27 +00:00
gcc -fPIC -I${ libXxf86vm .dev } /include \
2018-12-31 03:40:47 +00:00
-I${ xorgproto } /include \
2016-05-20 11:05:41 +00:00
-I$out /X11R6/include \
-L$out /lib \
-Wall -lm -lfglrx_gamma -lX11 -lXext -o $out /bin/fglrx_xgamma fglrx_xgamma.c
2010-05-18 19:36:55 +00:00
)
2016-01-20 19:51:52 +00:00
{
# patch and copy statically linked qt libs used by amdcccle
2016-05-03 08:54:49 +00:00
patchelf --set-interpreter $( echo $glibcDir /lib/ld-linux*.so.2) $TMP /arch/$arch /usr/share/ati/$lib_arch /libQtCore.so.4 &&
2016-01-20 19:51:52 +00:00
patchelf --set-rpath $gcc /$lib_arch / $TMP /arch/$arch /usr/share/ati/$lib_arch /libQtCore.so.4 &&
patchelf --set-rpath $gcc /$lib_arch /:$out /share/ati/:$libXrender /lib/:$libSM /lib/:$libICE /lib/:$libfontconfig /lib/:$libfreetype /lib/ $TMP /arch/$arch /usr/share/ati/$lib_arch /libQtGui.so.4 &&
mkdir -p $out /share/ati
cp -r $TMP /arch/$arch /usr/share/ati/$lib_arch /libQtCore.so.4 $out /share/ati/
cp -r $TMP /arch/$arch /usr/share/ati/$lib_arch /libQtGui.so.4 $out /share/ati/
# copy binaries and wrap them:
2010-05-18 19:36:55 +00:00
BIN = $TMP /arch/$arch /usr/X11R6/bin
2016-01-20 19:51:52 +00:00
patchelf --set-rpath $gcc /$lib_arch /:$out /share/ati/:$libXinerama /lib/:$libXrandr /lib/ $TMP /arch/$arch /usr/X11R6/bin/amdcccle
patchelf --set-rpath $libXrender /lib/:$libXrandr /lib/ $TMP /arch/$arch /usr/X11R6/bin/aticonfig
patchelf --shrink-rpath $BIN /amdcccle
2010-05-18 19:36:55 +00:00
for prog in $BIN /*; do
2016-01-20 19:51:52 +00:00
cp -f $prog $out /bin &&
2016-05-03 08:54:49 +00:00
patchelf --set-interpreter $( echo $glibcDir /lib/ld-linux*.so.2) $out /bin/$( basename $prog ) &&
2020-01-02 00:29:34 +00:00
wrapProgram $out /bin/$( basename $prog ) --prefix LD_LIBRARY_PATH : $out /lib/:$gcc /lib/:$out /share/ati/:$libXinerama /lib/:$libXrandr /lib/:$libfontconfig /lib/:$libfreetype /lib/${ LD_LIBRARY_PATH : + : } $LD_LIBRARY_PATH
2010-05-18 19:36:55 +00:00
done
}
2016-01-20 19:51:52 +00:00
rm -f $out /lib/fglrx/switchlibglx && rm -f $out /lib/fglrx/switchlibGL
2010-05-18 19:36:55 +00:00
}
2013-08-22 10:00:23 +00:00
2014-09-06 04:17:00 +00:00
fi
2013-08-22 10:00:23 +00:00
for p in $extraDRIlibs ; do
for lib in $p /lib/*.so*; do
ln -s $lib $out /lib/
done
done