##
##  bochs.spec -- OpenPKG RPM Specification
##  Copyright (c) 2000-2003 Cable & Wireless Deutschland GmbH
##  Copyright (c) 2000-2003 The OpenPKG Project <http://www.openpkg.org/>
##  Copyright (c) 2000-2003 Ralf S. Engelschall <rse@engelschall.com>
##
##  Permission to use, copy, modify, and distribute this software for
##  any purpose with or without fee is hereby granted, provided that
##  the above copyright notice and this permission notice appear in all
##  copies.
##
##  THIS SOFTWARE IS PROVIDED AS IS'' AND ANY EXPRESSED OR IMPLIED
##  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
##  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
##  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
##  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
##  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
##  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
##  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
##  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
##  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
##  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
##  SUCH DAMAGE.
##

#   package information
Name:         bochs
Summary:      IA-32 Emulator
URL:          http://bochs.sourceforge.net/
Vendor:       John Doe
Packager:     The OpenPKG Project
Distribution: OpenPKG [EVAL]
Group:        Misc
License:      LGPL
Version:      2.0.1
Release:      20030105

#   list of sources
Source0:      http://osdn.dl.sourceforge.net/sourceforge/bochs/bochs-%{version}.tar.gz
Source1:      http://osdn.dl.sourceforge.net/sourceforge/bochs/fdos-10meg.tar.gz

#   build information
Prefix:       %{l_prefix}
BuildRoot:    %{l_buildroot}
BuildPreReq:  OpenPKG, openpkg >= 20021218, X11, gcc
PreReq:       OpenPKG, openpkg >= 20021218, X11
AutoReq:      no
AutoReqProv:  no

%description
    Bochs is a highly portable open source IA-32 (x86) PC emulator
    written in C++, that runs on most popular platforms. It includes
    emulation of the Intel x86 CPU, common I/O devices, and a custom
    BIOS. Currently, Bochs can be compiled to emulate a 386, 486 or
    Pentium CPU. Bochs is capable of running most Operating Systems
    inside the emulation including Linux, Windows, DOS, etc.

    This package also contains a pre-configured FreeBSD 8h1 image
    for Bochs demonstration purposes and to see Bochs running easily.

%prep
    %setup0 -q
    %setup1 -q -T -D -a 1

    #   remove CVS sub-directories because they would be
    #   picked up by "make install" later.
    find . -type d -name CVS -print | xargs rm -rf

%build
    #   make sure Bochs find the global configuration
    %{l_shtool} subst \
        -e 's;/etc/bochsrc;%{l_prefix}/etc/bochs/bochsrc;' \
        main.cc

    #   configure the sources
    CC="%{l_cc}" \
    CXX="%{l_cxx}" \
    CFLAGS="%{l_cflags -O}" \
    CXXFLAGS="%{l_cxxflags -O}" \
    ./configure \
        --prefix=%{l_prefix} \
        --with-x11 \
        --x-includes=`%{l_prefix}/etc/rc --query x11_incdir` \
        --x-libraries=`%{l_prefix}/etc/rc --query x11_libdir` \
        --enable-cpu-level=5 \
        --enable-all-optimizations \
        --enable-cdrom \
        --enable-ne2000 \
        --disable-shared

    #   build the sources
    %{l_make} %{l_mflags -O}

%install
    rm -rf $RPM_BUILD_ROOT

    #   pre-generate extra directories
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/etc/bochs \
        $RPM_BUILD_ROOT%{l_prefix}/libexec/bochs

    #   perform standard installation procedure
    %{l_make} %{l_mflags} install DESTDIR=$RPM_BUILD_ROOT

    #   post-adjust manual pages
    rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/bochs-dlx.1.gz
    %{l_gzip} -d $RPM_BUILD_ROOT%{l_prefix}/man/man*/*.gz

    #   provide configuration file
    mv $RPM_BUILD_ROOT%{l_prefix}/share/doc/bochs/bochsrc-sample.txt \
       $RPM_BUILD_ROOT%{l_prefix}/etc/bochs/bochsrc.sample
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/share/doc

    #   provide VGA font directory
    ( cd $RPM_BUILD_ROOT%{l_prefix}/share/bochs
      rm -f install-x11-fonts test-x11-fonts
      mkdir fonts; mv vga.pcf fonts/
      x11_bindir=`%{l_prefix}/etc/rc --query x11_bindir`
      $x11_bindir/mkfontdir fonts
    )

    #   provide executable wrapper which finds the VGA font
    strip $RPM_BUILD_ROOT%{l_prefix}/bin/* >/dev/null 2>&1 || true
    mv $RPM_BUILD_ROOT%{l_prefix}/bin/bochs \
       $RPM_BUILD_ROOT%{l_prefix}/libexec/bochs/
    ( echo "#!/bin/sh"
      echo "xset fp+ %{l_prefix}/share/bochs/fonts"
      echo "exec %{l_prefix}/libexec/bochs/bochs \${1+\"\$@\"}"
    ) >$RPM_BUILD_ROOT%{l_prefix}/bin/bochs
    chmod a+x $RPM_BUILD_ROOT%{l_prefix}/bin/bochs

    #   install FreeDOS image as default scratch OS
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/share/bochs/img
    %{l_shtool} install -c -m 644 \
        fdos-10meg/fdosmini.img \
        $RPM_BUILD_ROOT%{l_prefix}/share/bochs/img/freedos.img
    %{l_shtool} install -c -m 644 \
        -e 's;$BXBIOS;%{l_prefix}/share/bochs;g' \
        -e 's;fdosmini.img;%{l_prefix}/share/bochs/img/freedos.img;g' \
        -e '/vga_update_interval.*/d' \
        -e '/realtime_pit/d' \
        fdos-10meg/bochsrc.txt \
        $RPM_BUILD_ROOT%{l_prefix}/etc/bochs/bochsrc

    #   determine installation files
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT %{l_files_std}

%files -f files

%clean
    rm -rf $RPM_BUILD_ROOT

%post
    if [ $1 -eq 1 ]; then
        ( echo "Hint: This Bochs package has a FreeDOS image pre-installed"
          echo "In order to run it as a regular user, you either have to"
          echo "change the permissions and/or the ownership of the image file"
          echo "%{l_prefix}/share/bochs/img/freedos.img manually."
        ) | %{l_rpmtool} msg -b -t notice
    fi

