# Copyright 1999-2006 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # Made by Sebastiaan Breedveld (s.breedveld@erasmusmc.nl) # # Installing EGSnrc and BEAMnrc seperately is not possible. The # Mortran compiler provided by EGSnrc wants to have write-access to # files which are already installed by EGSnrc, and no write-access is # required. It is much, much easier to install both packages in one # ebuild. Also because BEAMnrc requieres a `patch' to EGSnrc. inherit distutils eutils flag-o-matic toolchain-funcs versionator qt3 fortran DESCRIPTION="The EGSnrc Monte Carlo and BEAMnrc Radiotherapy package." HOMEPAGE="http://www.irs.inms.nrc.ca/EGSnrc/EGSnrc.html" SRC_URI="http://www.irs.inms.nrc.ca/EGSnrc/install_egs http://www.irs.inms.nrc.ca/EGSnrc/V${PV}_EGSnrc.tar.bz2 http://www.irs.inms.nrc.ca/EGSnrc/V${PV}_spinms.tar.bz2 http://www.irs.inms.nrc.ca/EGSnrc/V${PV}_user_codes.tar.bz2 http://www.irs.inms.nrc.ca/EGSnrc/V${PV}_manuals.tar.bz2 http://www.irs.inms.nrc.ca/EGSnrc/V${PV}_EGSgui.tar.bz2 http://www.irs.inms.nrc.ca/BEAM/user_manuals/install_beam http://www.irs.inms.nrc.ca/BEAM/user_manuals/V${PV}_BEAMnrc.tar.bz2 http://www.irs.inms.nrc.ca/BEAM/user_manuals/V${PV}_BEAMnrc_CT.tar.bz2 http://www.irs.inms.nrc.ca/BEAM/user_manuals/V${PV}_BEAMnrc_phsp.tar.bz2 http://www.irs.inms.nrc.ca/BEAM/user_manuals/beamnrc.mortran http://www.irs.inms.nrc.ca/BEAM/user_manuals/phsp_macros.mortran http://www.irs.inms.nrc.ca/EGS_Windows/EGS_Windows_${PV}.0.2.tar.gz" LICENSE="EGSnrc" KEYWORDS="~x86 ~amd64" SLOT="0" IUSE="X" RDEPEND="X? ( dev-lang/tk ) X? ( =x11-libs/qt-3* ) X? ( sci-visualization/grace ) X? ( x11-libs/xforms )" DEPEND="${RDEPEND}" FORTRAN="ifc gfortran g77" MYPN=BEAMnrc EGSDIR=${WORKDIR}/${MYPN} src_unpack() { return } src_compile() { # Firstly, install EGSnrc ewarn "" ewarn "Note that the installation script will fail if" ewarn "the unique machine name and therefore the whole" ewarn "pathname is too long: a MORTRAN inconvenience." ewarn if [ -n "${interactive}" ]; then einfo "" einfo "" einfo "You have chosen to interactively configure EGSnrc." einfo "To answer the first two questions:" einfo "The EGSnrc/BEAMnrc distribution files are installed in: " einfo "" einfo " ${PORTAGE_TMPDIR}/portage/${PF}/distdir" einfo "" einfo "You should install EGSnrc in this directory: " einfo "" einfo " ${EGSDIR}" einfo "" einfo "" ebeep 2 einfo "Compiling egs with user interaction..." sh distdir/install_egs || die "Make failed!" # Figure out CONFIGNAME CONFIGNAME=`ls ${EGSDIR}/bin/` else # Use defaults # Default to ifort and icc # # This is somewhat inconvenient, but Gentoo # deceided not to use the ifc useflag anymore ifortbin=`which ifort 2> /dev/null` if test -x "${ifortbin}"; then FORTRANC=ifort else # No ifort installed, let the # fortran.eclass handle this fortran_pkg_setup fi iccbin=`which icc 2> /dev/null` if test -x "${iccbin}"; then CCOMPILER=icc else # No icc installed, use gcc CCOMPILER=gcc fi ewarn "" ewarn "Note that this ebuild defaults to the Intel Fortran" ewarn "Compiler and the Intel C Compiler to compile the EGSnrc." ewarn "If it is not installed, an alternative compiler will be used" ewarn "(gfortran, g77 or gcc)." ewarn "" ewarn "Selected compilers are: ${FORTRANC} ${CCOMPILER}" ewarn "" ewarn "If this is not what you want, set 'interactive=1' and" ewarn "re-emerge for manual configuration." ewarn "" ewarn "You can choose your own compilers. The source compiles" ewarn "best with gcc-3 and g77, but icc 9 and ifort 9 also works well." ewarn "Do not use gfortran, since an important program will fail to" ewarn "build (ctcreate)." ewarn "" ewarn "Note that with any combination of compilers, one or more" ewarn "user files will not compile, but this is not critical." ewarn "" ebeep 2 CONFIGNAME="${ARCH}-${FORTRANC}" # Make answer list echo $" $WORKDIR/../distdir/ $EGSDIR ${FORTRANC} $CCOMPILER ${CONFIGNAME}.conf ${CONFIGNAME}" > answers.txt einfo "Compiling egs..." sh distdir/install_egs < answers.txt || die "Make failed!" fi # Set environment variables export EGS_CONFIG="${EGSDIR}/specs/${CONFIGNAME}.conf" export MY_MACHINE="${CONFIGNAME}" export EGS_HOME="${EGSDIR}/egsnrc_for_user/" export HEN_HOUSE="${EGSDIR}/" mkdir $EGS_HOME # Figure out which compilers where used and where the Intel libraries are FORTRANC=`grep 'F77 = ' ${EGSDIR}/specs/${CONFIGNAME}.conf | cut -c7-` if [ "${FORTRANC}" == "ifort" ]; then FORTRANC_LIBPATH=`which ifort` FORTRANC_LIBPATH=`dirname ${FORTRANC_LIBPATH}` FORTRANC_LIBPATH=`dirname ${FORTRANC_LIBPATH}` export FORTRANC_LIBPATH="${FORTRANC_LIBPATH}/lib" # Replace / by \/ for use with sed echo $FORTRANC_LIBPATH | sed 's/\//\\\//g' > ${PORTAGE_TMPDIR}/portage/${PF}/temp/sedtemp sedFORTRANC_LIBPATH=`cat ${PORTAGE_TMPDIR}/portage/${PF}/temp/sedtemp` fi CCOMPILER=`grep 'CC = ' ${EGSDIR}/specs/${CONFIGNAME}.conf | cut -c6-` if [ "${CCOMPILER}" == "icc" ]; then CCOMPILER_LIBPATH=`which icc` CCOMPILER_LIBPATH=`dirname ${CCOMPILER_LIBPATH}` CCOMPILER_LIBPATH=`dirname ${CCOMPILER_LIBPATH}` export CCOMPILER_LIBPATH="${CCOMPILER_LIBPATH}/lib" # Replace / by \/ for use with sed echo $CCOMPILER_LIBPATH | sed 's/\//\\\//g' > ${PORTAGE_TMPDIR}/portage/${PF}/temp/sedtemp sedCCOMPILER_LIBPATH=`cat ${PORTAGE_TMPDIR}/portage/${PF}/temp/sedtemp` fi # Make egspp/egs++ if [ "${CCOMPILER}" == "gcc" ]; then if [ "${ARCH}" == "amd64" ]; then cp ${EGSDIR}/specs/egspp_gcc64_example.conf "${EGSDIR}/specs/egspp_${CONFIGNAME}.conf" else cp ${EGSDIR}/specs/egspp_gcc_example.conf "${EGSDIR}/specs/egspp_${CONFIGNAME}.conf" fi # Patch configuration if [ "$(gcc_major_version)" -eq 4 ]; then sed -i 's/fortran_libs = -lg2c/fortran_libs = -lgfortran/' "${EGSDIR}/specs/egspp_${CONFIGNAME}.conf" fi # Only if ifort is used if [ "${FORTRANC}" == "ifort" ]; then sed -i "s/fortran_libs =/fortran_libs = -L$sedFORTRANC_LIBPATH -lifcore -lifport -lpthread/" "${EGSDIR}/specs/egspp_${CONFIGNAME}.conf" fi else # assume icc cp ${EGSDIR}/specs/egspp_intel1_example.conf "${EGSDIR}/specs/egspp_${CONFIGNAME}.conf" sed -i "s/-L\/home\/iwan\/intel\/fc8.0\/lib/ -L$sedFORTRANC_LIBPATH/" "${EGSDIR}/specs/egspp_${CONFIGNAME}.conf" sed -i "s/extra =/extra = -L$sedCCOMPILER_LIBPATH/" "${EGSDIR}/specs/egspp_${CONFIGNAME}.conf" sed -i "s/lib_link1 =/lib_link1 = -L$sedCCOMPILER_LIBPATH/" "${EGSDIR}/specs/egspp_${CONFIGNAME}.conf" sed -i 's/opt = /opt = -lstdc++ /' "${EGSDIR}/specs/egspp_${CONFIGNAME}.conf" if [ "${ARCH}" == "amd64" ]; then # Patch with -fPIC sed -i 's/opt = /opt = -fPIC /' "${EGSDIR}/specs/egspp_${CONFIGNAME}.conf" fi fi cd ${EGSDIR}/egs++ einfo "Compiling EGS++..." emake -j1 cd ${PORTAGE_TMPDIR}/portage/${PF} if use X; then einfo "Compiling the gui..." cd ${EGSDIR}/gui # First patch some GUI files for gcc-4 if [ "$(gcc-major-version)" -eq 4 ]; then patch -p1 < "${FILESDIR}"/gcc-4.patch fi emake cd ${PORTAGE_TMPDIR}/portage/${PF} fi # Precompile user directory echo $"${EGS_HOME} yes 1" > answers2.txt einfo "Compiling the EGSnrc user files..." ${EGSDIR}/scripts/finalize_egs_foruser < answers2.txt # Secondly, install BEAMnrc # Patch the install_beam script for Makefile errors cp distdir/install_beam temp/install_beam patch temp/install_beam "${FILESDIR}"/install_beam.patch echo $" $WORKDIR/../distdir/" > answers3.txt einfo "Compiling BEAMnrc..." sh ${PORTAGE_TMPDIR}/portage/${PF}/temp/install_beam < answers3.txt # Precompile user directory einfo "Compiling BEAMnrc user files..." ${EGSDIR}/scripts/finalize_beam_foruser # Patch (http://www.irs.inms.nrc.ca/BEAM/user_manuals/DISTRIBUTION.html) einfo "Patching beamnrc.mortran and phsp_macros.mortran..." cp ${PORTAGE_TMPDIR}/portage/${PF}/distdir/beamnrc.mortran ${EGSDIR}/omega/beamnrc/ cp ${PORTAGE_TMPDIR}/portage/${PF}/distdir/phsp_macros.mortran ${EGSDIR}/utils/ # Thirdly, compile the viewer einfo "Compiling the EGS_Windows viewer..." cd ${WORKDIR}/ unpack "EGS_Windows_${PV}.0.2.tar.gz" cd EGS_Windows/ # Set correct compilers (just use gcc here). sed -i "s/cc/gcc/" Makefile.Linux if [ "$(gcc-major-version)" -eq 4 ]; then sed -i "s/g77/gfortran/" Makefile.Linux fi # Fix library dependence sed "s/LIBS=/LIBS=-lXpm/" Makefile.Linux > Makefile emake cp EGS_Windows_${PV}.0.Linux.exe ${EGSDIR}/bin/${CONFIGNAME}/show } src_install() { # Remove portage paths in installation files einfo "Correct portage paths in files:" for sedfile in `grep -RHlI '/var/tmp/portage/beamnrc-4/work/' $EGSDIR` do echo $sedfile sed -i 's/\/var\/tmp\/portage\/beamnrc-4\/work/\/opt/' $sedfile done # Correct permissions: no file should be world writable chmod g-w,o-w $EGSDIR/mortran3/mortran3.f # Permissions are really, really messed up. # Root owns the place, make the tcl scripts # world executable and all files world readable. chown -R root:root ${EGSDIR}/* find ${EGSDIR}/ -name '*.tcl' | xargs chmod a+rx chmod -R a+r ${EGSDIR} # Add convenience links to bin directory for common commands cd ${EGSDIR}/bin/${CONFIGNAME}/ ln -s ../../omega/progs/gui/beamnrc/beamnrc_gui.tcl beamnrc_gui ln -s ../../omega/progs/gui/beamnrc/beamnrc_gui.tcl beam_gui ln -s ../../omega/progs/gui/dosxyznrc/dosxyznrc_gui.tcl dosxyznrc_gui ln -s ../../omega/progs/gui/dosxyznrc/dosxyznrc_gui.tcl dosxyz_gui ln -s ../../omega/progs/gui/beamdp/beamdp_gui.tcl beamdp_gui ln -s ../../scripts/pprocess pprocess # Very dirty, dirty binary patch einfo "Doing a dirty and dangerous binary patch on beam_build.exe and pegs4.exe." sed -i 's/\/var\/tmp\/portage\/beamnrc-4\/work\/BEAMnrc\/omega/\/opt\/BEAMnrc\/omega\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\//' ${EGSDIR}/bin/${CONFIGNAME}/beam_build.exe sed -i 's/\/var\/tmp\/portage\/beamnrc-4\/work\/BEAMnrc\/specs/\/opt\/BEAMnrc\/specs\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\//' ${EGSDIR}/bin/${CONFIGNAME}/beam_build.exe sed -i 's/\/var\/tmp\/portage\/beamnrc-4\/work\/BEAMnrc/\/opt\/BEAMnrc\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\//' ${EGSDIR}/bin/${CONFIGNAME}/pegs4.exe sed -i 's/\/var\/tmp\/portage\/beamnrc-4\/work\/BEAMnrc/\/opt\/BEAMnrc\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\//' ${EGSDIR}/egsnrc_for_user/${CONFIGNAME}/dosxyznrc # Patch file so a batch job redirects output to batch.log cd ${EGSDIR}/omega/progs/gui/beamnrc patch < "${FILESDIR}"/run_beamnrc.patch cd ${PORTAGE_TMPDIR}/portage/${PF}/ # Keep empty directories in $EGS_HOME/pegs4 keepdir ${EGSDIR}/egsnrc_for_user/pegs4/data keepdir ${EGSDIR}/egsnrc_for_user/pegs4/density keepdir ${EGSDIR}/egsnrc_for_user/pegs4/inputs # Add paths to environment echo "HEN_HOUSE=/opt/${MYPN}" >> ${T}/71${PN} echo "EGS_CONFIG=/opt/${MYPN}/specs/${CONFIGNAME}.conf" >> ${T}/71${PN} echo 'EGS_HOME=~/egsnrc/' >> ${T}/71${PN} echo "EGS_BATCH_SYSTEM=at" >> ${T}/71${PN} echo "OMEGA_HOME=/opt/${MYPN}/omega/" >> ${T}/71${PN} echo "PATH=/opt/${MYPN}/bin/${CONFIGNAME}/" >> ${T}/71${PN} doenvd ${T}/71${PN} # Build and install this package in /opt due to # the internal references to the programs and data # used in the package (so do not integrate the # binaries of this package in the main system). dodir /opt mv ${EGSDIR} ${D}/opt # cleanup portage directory rm ${PORTAGE_TMPDIR}/portage/${PF}/*.txt rm ${PORTAGE_TMPDIR}/portage/${PF}/*.log rm ${PORTAGE_TMPDIR}/portage/${PF}/*.status return } pkg_postinst() { ewarn "" ewarn "For each user, copy /opt/${MYPN}/egsnrc_for_user to /home/USER/egsnrc" ewarn "and chown -R for the user." ewarn "" ewarn "Because BEAMnrc fails to detect the executable paths correctly," ewarn "add this to the login script for each user (e.g. .bashrc):" ewarn "" ewarn ' export PATH=$PATH:$HOME/egsnrc/bin/'"${CONFIGNAME}/" ewarn ' export EGS_HOME=$HOME/egsnrc/' ewarn "" ebeep 2 return }