%define desktop_vendor vine

%define drivername      fglrx
%define xorg_version    pic
%ifarch %ix86
%define xverdir         x%{xorg_version}
%define archdir         arch/x86
%endif
%ifarch x86_64
%define xverdir         x%{xorg_version}_64a
%define archdir         arch/x86_64
%endif
%define xorg_libdir     %{_libdir}/xorg
%define xorg_dridir     %{_libdir}/dri
%define xorg_dridir32   %{_prefix}/lib/dri
%define ld_so_conf_file ati.conf
%define ati_extdir      %{xorg_libdir}/modules/extensions/%{drivername}

%define bundle_qt       0
%define debug_package  %{nil}

Summary: X Window display driver for the ATI graphics accelerators
Summary(ja): プロプライエタリな ATI グラフィックス・アクセラレーターのためのディスプレイ・ドライバ
Name: xorg-x11-drv-fglrx
Version: 8.85
Release: 1%{?_dist_release}
License: Other License(s), see package
Group: User Interface/X Hardware Support
URL: http://ati.amd.com/support/driver.html
Vendor: Project Vine
Distribution: Vine Linux
Packager: kenta
ExclusiveArch: i686 x86_64

Source0: http://www2.ati.com/drivers/linux/ati-driver-installer-11-5-x86.x86_64.run
Source1: atieventsd.init

BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
# Required for proper dkms operation
Requires: gcc, make
Requires(post): dkms, /sbin/ldconfig
Requires(preun): dkms

%description
The display drivers for the ATI Radeon, Mobility Radeon, Radeon Xpress IGP, and 
FireGL series of graphics graphics accelerators. This driver works only with post 
R200 (Radeon 9200) graphics cards. This package provides 2D display drivers, 
precompiled kernel modules, kernel module build environment, control 
panel source code and hardware accelerated OpenGL.

INSTALLING THIS PACKAGE WILL TAINT YOUR KERNEL, SO PLEASE DO NOT REPORT *ANY*
BUGS BEFORE YOU UNINSTALL THE PACKAGE AND REBOOT THE SYSTEM.

%description -l ja
このパッケージには、ATI 製のグラフィックスカードで2D/3Dのハードウエアアクセ
ラレーションを得るためのプロプライエタリなグラフィックスドライバが収録されてい
ます。このドライバには以下のモジュールが含まれています。
 - OpenGLライブラリ
 - Xorg ドライバモジュール
 - DRM カーネルモジュール

注意: このパッケージをインストールすると利用しているカーネルを汚染します。
      Kernelに関するどんなバグレポートを行う場合は、必ずこのパッケージを
      アンインストールしシステムをリブートしてから行って下さい。

%prep
%setup -q -T -c
# Extract the proper "sources" for the current architecture
# We need to extract to a "not yet existing" directory first, so no "."
sh %{SOURCE0} --extract .
mkdir fglrx_tools
# tar -xzf common/usr/src/ati/fglrx_sample_source.tgz -C fglrx_tools

%build
# Nope.

%install
%{__rm} -rf %{buildroot}

# dkms
install -d -m755 %{buildroot}%{_usrsrc}/%{drivername}-%{version}-%{release}
cp -a common/lib/modules/fglrx/build_mod/* %{buildroot}%{_usrsrc}/%{drivername}-%{version}-%{release}
cp -a %{archdir}/lib/modules/fglrx/build_mod/* %{buildroot}%{_usrsrc}/%{drivername}-%{version}-%{release}

%define dkms_name fglrx
%define dkms_vers %{version}-%{release}
%define quiet -q

# Copy dkms conf file
%{__mkdir_p} %{buildroot}%{_usrsrc}/%{dkms_name}-%{dkms_vers}/
%{__cat} > %{buildroot}%{_usrsrc}/%{dkms_name}-%{dkms_vers}/dkms.conf << 'EOF'
PACKAGE_NAME=%{dkms_name}
PACKAGE_VERSION=%{dkms_vers}
BUILT_MODULE_NAME[0]=fglrx
DEST_MODULE_LOCATION[0]=/kernel/drivers/char/drm
MAKE[0]="KERNEL_PATH=\${kernel_source_dir} sh make.sh --uname_r=\${kernelver} --uname_a=none"
CLEAN="rm -rf 2.6.x/.tmp_versions; make -C2.6.x clean"
AUTOINSTALL=YES
EOF

# headers
install -d -m755                %{buildroot}%{_includedir}
cp -a common/usr/include/*      %{buildroot}%{_includedir}
chmod 0644 %{buildroot}%{_includedir}/*/*.h

# install binaries
install -d -m755                                        %{buildroot}%{_sbindir}
install -m755 %{archdir}/usr/sbin/*                     %{buildroot}%{_sbindir}
install -m755 common/usr/sbin/*                         %{buildroot}%{_sbindir}
install -d -m755                                        %{buildroot}%{_bindir}
install -m755 %{archdir}/usr/X11R6/bin/*                %{buildroot}%{_bindir}
install -m755 common/usr/X11R6/bin/*                    %{buildroot}%{_bindir}

# atieventsd initscript
install -d -m755 %{buildroot}%{_initrddir}
install -m755 %{SOURCE1} %{buildroot}%{_initrddir}/atieventsd

# amdcccle data files
install -d -m755 %{buildroot}%{_datadir}/ati/amdcccle
rm -f amdcccle.langs
for fullname in common/usr/share/ati/amdcccle/*.qm; do
        file=$(basename $fullname)
        lang=${file#*_}
        lang=${lang%%.qm}
%if !%{bundle_qt}
        # qt localization not necessary with non-bundled qt
        [ "$file" = "${file#qt}" ] || continue
%endif
        install -m644 $fullname %{buildroot}%{_datadir}/ati/amdcccle
        echo "%%lang($lang) %{_datadir}/ati/amdcccle/$file" >> amdcccle.langs
done

# amdcccle super-user mode
install -d -m755 %{buildroot}%{_sysconfdir}/security/console.apps
install -d -m755 %{buildroot}%{_sysconfdir}/pam.d
install -m644 common/etc/security/console.apps/* %{buildroot}%{_sysconfdir}/security/console.apps
ln -s su %{buildroot}%{_sysconfdir}/pam.d/amdcccle-su

# man pages
install -d -m755 %{buildroot}%{_mandir}/man1 %{buildroot}%{_mandir}/man8
install -m644 common/usr/share/man/man8/* %{buildroot}%{_mandir}/man8

# menu entry
install -d -m755 %{buildroot}%{_datadir}/applications
install -m644 common/usr/share/applications/* %{buildroot}%{_datadir}/applications
sed -i 's,^Icon=.*$,Icon=%{drivername}-amdcccle,' %{buildroot}%{_datadir}/applications/*.desktop
# control center doesn't really use GNOME/KDE libraries:
sed -i 's,GNOME;KDE;,,' %{buildroot}%{_datadir}/applications/*.desktop


# icons
install -d -m755 %{buildroot}%{_miconsdir} %{buildroot}%{_iconsdir} %{buildroot}%{_liconsdir}
convert common/usr/share/icons/ccc_large.xpm -resize 16x16 %{buildroot}%{_miconsdir}/%{drivername}-amdcccle.png
convert common/usr/share/icons/ccc_large.xpm -resize 32x32 %{buildroot}%{_iconsdir}/%{drivername}-amdcccle.png
convert common/usr/share/icons/ccc_large.xpm -resize 48x48 %{buildroot}%{_liconsdir}/%{drivername}-amdcccle.png

# install libraries
install -d -m755                                        %{buildroot}%{_libdir}/%{drivername}
install -m755 %{archdir}/usr/X11R6/%{_lib}/fglrx/*      %{buildroot}%{_libdir}/%{drivername}
install -m755 %{archdir}/usr/X11R6/%{_lib}/*.*          %{buildroot}%{_libdir}/%{drivername}
install -m755 %{archdir}/usr/%{_lib}/*.*                %{buildroot}%{_libdir}/%{drivername}
mv %{buildroot}%{_libdir}/%{drivername}/{fglrx-,}libGL.so.1.2
chmod 0644                                              %{buildroot}%{_libdir}/%{drivername}/*.a
# create devel symlinks
for file in %{buildroot}%{_libdir}/%{drivername}/*.so.*.*; do
	ln -s $(basename $file) ${file%%.so*}.so;
done

%ifarch x86_64
install -d -m755                                        %{buildroot}%{_prefix}/lib/%{drivername}
install -m755 arch/x86/usr/X11R6/lib/fglrx/*            %{buildroot}%{_prefix}/lib/%{drivername}
install -m755 arch/x86/usr/X11R6/lib/*.*                %{buildroot}%{_prefix}/lib/%{drivername}
install -m755 arch/x86/usr/lib/*.*                      %{buildroot}%{_prefix}/lib/%{drivername}
mv %{buildroot}%{_prefix}/lib/%{drivername}/{fglrx-,}libGL.so.1.2
chmod 0644                                              %{buildroot}%{_prefix}/lib/%{drivername}/*.a
# create devel symlinks
for file in %{buildroot}%{_prefix}/lib/%{drivername}/*.so.*.*; do
        ln -s $(basename $file) ${file%%.so*}.so;
done
%endif


# install X.org files
install -d -m755                                                %{buildroot}%{xorg_libdir}/modules/drivers
install -m755 %{xverdir}/usr/X11R6/%{_lib}/modules/drivers/*.so* %{buildroot}%{xorg_libdir}/modules/drivers
install -d -m755                                                %{buildroot}%{xorg_libdir}/modules/linux
install -m755 %{xverdir}/usr/X11R6/%{_lib}/modules/linux/*.so*  %{buildroot}%{xorg_libdir}/modules/linux
install -m644 %{xverdir}/usr/X11R6/%{_lib}/modules/*.*o         %{buildroot}%{xorg_libdir}/modules
install -d -m755                                                %{buildroot}%{ati_extdir}
install -m755 %{xverdir}/usr/X11R6/%{_lib}/modules/extensions/fglrx/*.so* %{buildroot}%{ati_extdir}
mv %{buildroot}%{ati_extdir}/{fglrx-,}libglx.so

# etc files
install -d -m755                %{buildroot}%{_sysconfdir}/ati
install -m644 common/etc/ati/*  %{buildroot}%{_sysconfdir}/ati
chmod 0755                      %{buildroot}%{_sysconfdir}/ati/*.sh

# dri libraries
install -d -m755                                                %{buildroot}%{xorg_dridir}
install -m755 %{archdir}/usr/X11R6/%{_lib}/modules/dri/*        %{buildroot}%{xorg_dridir}
%ifarch x86_64
install -d -m755                                                %{buildroot}%{xorg_dridir32}
install -m755 arch/x86/usr/X11R6/lib/modules/dri/*              %{buildroot}%{xorg_dridir32}
%endif

# ld.so.conf
install -d -m755                        %{buildroot}%{_sysconfdir}/ld.so.conf.d
echo "%{_libdir}/%{drivername}" >       %{buildroot}%{_sysconfdir}/ld.so.conf.d/%{ld_so_conf_file}
%ifarch x86_64
echo "%{_prefix}/lib/%{drivername}" >>  %{buildroot}%{_sysconfdir}/ld.so.conf.d/%{ld_so_conf_file}
%endif


## # Install modprobe.d file
## %{__install} -D -p -m 0644 %{SOURCE5} \
##     %{buildroot}%{_sysconfdir}/modprobe.d/nvidia.conf

## # Install blacklist-nouveau.conf
## %{__install} -D -p -m 0644 %{SOURCE7} \
##     %{buildroot}%{_sysconfdir}/modprobe.d/blacklist-nouveau.conf

## # Install ld.so.conf.d file
## %{__mkdir_p} %{buildroot}%{_sysconfdir}/ld.so.conf.d/
## echo %{nvidialibdir} >    %{buildroot}%{_sysconfdir}/ld.so.conf.d/nvidia.conf
## %ifarch x86_64
## echo %{nvidialib32dir} >> %{buildroot}%{_sysconfdir}/ld.so.conf.d/nvidia.conf
## %endif

## # Install profile.d files
## %{__install} -D -p -m 0644 %{SOURCE2} \
##     %{buildroot}%{_sysconfdir}/profile.d/nvidia.sh
## %{__install} -D -p -m 0644 %{SOURCE3} \
##     %{buildroot}%{_sysconfdir}/profile.d/nvidia.csh

## # Install X configuration script
## %{__install} -D -p -m 0755 %{SOURCE4} \
##     %{buildroot}%{_sbindir}/nvidia-config-display

## # Install udev "configuration" file
## %{__install} -D -p -m 0644 %{SOURCE6} \
##     %{buildroot}%{_sysconfdir}/udev/makedev.d/60-nvidia.nodes

## # Install udev rules
## %{__install} -D -p -m 0644 %{SOURCE8} \
##     %{buildroot}%{_sysconfdir}/udev/rules.d/50-nvidia.rules


%clean
%{__rm} -rf %{buildroot}


%post
/sbin/ldconfig

# Add to DKMS registry
dkms add -m %{dkms_name} -v %{dkms_vers} %{?quiet} || :
# Rebuild and make available for the currenty running kernel
dkms build -m %{dkms_name} -v %{dkms_vers} %{?quiet} || :
dkms install -m %{dkms_name} -v %{dkms_vers} %{?quiet} --force || :

%preun
# Remove all versions from DKMS registry
dkms remove -m %{dkms_name} -v %{dkms_vers} %{?quiet} --all || :

# rmmod any old driver if present and not in use (e.g. by X)
rmmod fglrx > /dev/null 2>&1 || true

%postun -p /sbin/ldconfig


%files
%defattr(-,root,root,-)
%dir %{_sysconfdir}/ati
%dir %{_libdir}/fglrx
%config(noreplace) %{_sysconfdir}/ati/control
%config %{_sysconfdir}/ati/logo.xbm.example
%config %{_sysconfdir}/ati/atiogl.xml
%config %{_sysconfdir}/ati/amdpcsdb.default
%config %{_sysconfdir}/ati/logo_mask.xbm.example
%config %{_sysconfdir}/ld.so.conf.d/ati.conf
# %config %{_sysconfdir}/acpi/events/*aticonfig.conf
# %{_sysconfdir}/acpi/actions/ati-powermode.sh
%{_sysconfdir}/ati/authatieventsd.sh
%{_sysconfdir}/ati/signature
%{_initrddir}/atieventsd
%{_sbindir}/atieventsd
%{_sbindir}/amdnotifyui
%{_sbindir}/atigetsysteminfo.sh
%{_bindir}/amdupdaterandrconfig
%{_bindir}/amdxdg-su
%{_bindir}/aticonfig
%{_bindir}/atiodcli
%{_bindir}/atiode
%{_bindir}/fgl_glxgears
%{_bindir}/fglrxinfo
#%{_bindir}/fglrx_xgamma
%dir %{ati_extdir}
%{ati_extdir}/libglx.so
%{xorg_dridir}/fglrx_dri.so
%ifarch x86_64
%dir %{xorg_dridir32}
%{xorg_dridir32}/fglrx_dri.so
%endif
%{xorg_libdir}/modules/drivers/*fglrx*.*
%{xorg_libdir}/modules/linux/*fglrx*.*
%{xorg_libdir}/modules/glesx.so
%{xorg_libdir}/modules/amdxmm.so
%{_libdir}/%{drivername}/libati*.so
%{_libdir}/%{drivername}/libAMDXvBA.so
%{_libdir}/%{drivername}/libXvBAW.so
%{_libdir}/%{drivername}/libfglrx_dm.so
%{_libdir}/%{drivername}/*.cap
%{_libdir}/%{drivername}/*.so.*
%ifarch x86_64
%{_prefix}/lib/%{drivername}/libati*.so
%{_prefix}/lib/%{drivername}/libAMDXvBA.so
%{_prefix}/lib/%{drivername}/libXvBAW.so
%{_prefix}/lib/%{drivername}/libfglrx_dm.so
%{_prefix}/lib/%{drivername}/*.cap
%{_prefix}/lib/%{drivername}/*.so.*
%endif
%{_mandir}/man[1-9]/atieventsd.*

# control-center
%doc common/usr/share/doc/fglrx/ATI_LICENSE.TXT
%doc common/usr/share/doc/amdcccle/*
%{_sysconfdir}/security/console.apps/amdcccle-su
%{_sysconfdir}/pam.d/amdcccle-su
%{_bindir}/amdcccle
%{_miconsdir}/%{drivername}-amdcccle.png
%{_iconsdir}/%{drivername}-amdcccle.png
%{_liconsdir}/%{drivername}-amdcccle.png
%{_datadir}/ati/amdcccle/amdcccle_*.qm
%{_datadir}/applications/amdcccle.desktop
%{_datadir}/applications/amdccclesu.desktop

# devel
%dir %{_includedir}/GL
%{_includedir}/GL/*ATI.h
%dir %{_includedir}/ATI
%dir %{_includedir}/ATI/GL
%{_includedir}/ATI/GL/*.h
%{_libdir}/%{drivername}/libGL.so
%{_libdir}/%{drivername}/*.a
%ifarch x86_64
%{_prefix}/lib/%{drivername}/libGL.so
%{_prefix}/lib/%{drivername}/*.a
%endif

# kernel-module - dkms
%{_usrsrc}/%{drivername}-%{version}-%{release}

%changelog
* Sun May 29 2011 NAKAMURA Kenta <kenta@vinelinux.org> 8.85-1
- initial release for Vine Linux
