cns-1.2.1-r8.ebuild 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. # Copyright 1999-2014 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. EAPI=5
  4. inherit eutils fortran-2 toolchain-funcs versionator flag-o-matic
  5. MY_PN="${PN}_solve"
  6. MY_PV="$(delete_version_separator 2)"
  7. MY_P="${MY_PN}_${MY_PV}"
  8. DESCRIPTION="Crystallography and NMR System"
  9. HOMEPAGE="http://cns.csb.yale.edu/"
  10. SRC_URI="
  11. ${MY_P}_all-mp.tar.gz
  12. aria? ( aria2.3.2.tar.gz )"
  13. SLOT="0"
  14. LICENSE="cns"
  15. KEYWORDS="amd64 x86 ~amd64-linux ~x86-linux"
  16. IUSE="aria openmp"
  17. RDEPEND="app-shells/tcsh"
  18. DEPEND="${RDEPEND}"
  19. FORTRAN_NEED_OPENMP=1
  20. S="${WORKDIR}/${MY_P}"
  21. RESTRICT="fetch test"
  22. pkg_nofetch() {
  23. elog "Fill out the form at http://cns.csb.yale.edu/cns_request/"
  24. use aria && elog "and http://aria.pasteur.fr/"
  25. elog "and place these files:"
  26. elog ${A}
  27. elog "in ${DISTDIR}."
  28. }
  29. get_fcomp() {
  30. case $(tc-getFC) in
  31. *gfortran* )
  32. FCOMP="gfortran" ;;
  33. ifort )
  34. FCOMP="ifc" ;;
  35. * )
  36. FCOMP=$(tc-getFC) ;;
  37. esac
  38. }
  39. pkg_setup() {
  40. fortran-2_pkg_setup
  41. get_fcomp
  42. }
  43. get_bitness() {
  44. echo > "${T}"/test.c
  45. $(tc-getCC) ${CFLAGS} -c "${T}"/test.c -o "${T}"/test.o
  46. case $(file "${T}"/test.o) in
  47. *64-bit*|*ppc64*|*x86_64*) export _bitness="64";;
  48. *32-bit*|*ppc*|*i386*) export _bitness="32";;
  49. *) die "Failed to detect whether your arch is 64bits or 32bits, disable distcc if you're using it, please";;
  50. esac
  51. }
  52. src_prepare() {
  53. epatch \
  54. "${FILESDIR}"/${PV}-gentoo.patch \
  55. "${FILESDIR}"/${PV}-parallel.patch
  56. get_bitness
  57. if use aria; then
  58. pushd "${WORKDIR}"/aria* >& /dev/null
  59. # Update the cns sources in aria for version 1.2.1
  60. epatch "${FILESDIR}"/1.2.1-aria2.3.patch
  61. # Update the code with aria specific things
  62. cp -rf cns/src/* "${S}"/source/ || die
  63. popd >& /dev/null
  64. fi
  65. # the code uses Intel-compiler-specific directives
  66. if [[ $(tc-getFC) =~ gfortran ]]; then
  67. epatch "${FILESDIR}"/${PV}-allow-gcc-openmp.patch
  68. use openmp && \
  69. append-flags -fopenmp && append-ldflags -fopenmp
  70. COMP="gfortran"
  71. [[ ${_bitness} == 64 ]] && \
  72. append-fflags -fdefault-integer-8
  73. elif [[ $(tc-getFC) == if* ]]; then
  74. epatch "${FILESDIR}"/${PV}-ifort.patch
  75. use openmp && \
  76. append-flags -openmp && append-ldflags -openmp
  77. COMP="ifort"
  78. [[ ${_bitness} == 64 ]] && append-fflags -i8
  79. fi
  80. [[ ${_bitness} == 64 ]] && \
  81. append-cflags "-DINTEGER='long long int'"
  82. # Set up location for the build directory
  83. # Uses obsolete `sort` syntax, so we set _POSIX2_VERSION
  84. cp "${FILESDIR}"/cns_solve_env_sh "${T}"/ || die
  85. sed \
  86. -e "s:_CNSsolve_location_:${S}:g" \
  87. -e "17 s:\(.*\):\1\nsetenv _POSIX2_VERSION 199209:g" \
  88. -i "${S}"/cns_solve_env || die
  89. sed \
  90. -e "s:_CNSsolve_location_:${S}:g" \
  91. -e "17 s:\(.*\):\1\nexport _POSIX2_VERSION; _POSIX2_VERSION=199209:g" \
  92. -i "${T}"/cns_solve_env_sh || die
  93. einfo "Fixing shebangs..."
  94. find "${S}" -type f \
  95. -exec sed "s:/bin/csh:${EPREFIX}/bin/csh:g" -i '{}' + || die
  96. }
  97. src_compile() {
  98. local GLOBALS
  99. local MALIGN
  100. if [[ $(tc-getFC) =~ g77 ]]; then
  101. GLOBALS="-fno-globals"
  102. MALIGN='\$(CNS_MALIGN_I86)'
  103. fi
  104. # Set up the compiler to use
  105. ln -s Makefile.header instlib/machine/unsupported/g77-unix/Makefile.header.${FCOMP} || die
  106. # make install really means build, since it's expected to be used in-place
  107. # -j1 doesn't mean we do no respect MAKEOPTS!
  108. emake -j1 \
  109. CC="$(tc-getCC)" \
  110. F77=$(tc-getFC) \
  111. LD=$(tc-getFC) \
  112. CCFLAGS="${CFLAGS} -DCNS_ARCH_TYPE_\$(CNS_ARCH_TYPE) \$(EXT_CCFLAGS)" \
  113. LDFLAGS="${LDFLAGS}" \
  114. F77OPT="${FCFLAGS} ${MALIGN}" \
  115. F77STD="${GLOBALS}" \
  116. OMPLIB="${OMPLIB}" \
  117. compiler="${COMP}" \
  118. install
  119. }
  120. src_test() {
  121. # We need to force on g77 manually, because we can't get aliases working
  122. # when we source in a -c
  123. einfo "Running tests ..."
  124. csh -c \
  125. "export CNS_G77=ON; source ${S}/cns_solve_env; make run_tests" \
  126. || die "tests failed"
  127. einfo "Displaying test results ..."
  128. cat "${S}"/*_g77/test/*.diff-test
  129. }
  130. src_install() {
  131. # Install to locations resembling FHS
  132. sed \
  133. -e "s:${S}:usr:g" \
  134. -e "s:^\(setenv CNS_SOLVE.*\):\1\nsetenv CNS_ROOT ${EPREFIX}/usr:g" \
  135. -e "s:^\(setenv CNS_SOLVE.*\):\1\nsetenv CNS_DATA \$CNS_ROOT/share/cns:g" \
  136. -e "s:^\(setenv CNS_SOLVE.*\):\1\nsetenv CNS_DOC \$CNS_ROOT/share/doc/${PF}:g" \
  137. -e "s:CNS_LIB \$CNS_SOLVE/libraries:CNS_LIB \$CNS_DATA/libraries:g" \
  138. -e "s:CNS_MODULE \$CNS_SOLVE/modules:CNS_MODULE \$CNS_DATA/modules:g" \
  139. -e "s:CNS_HELPLIB \$CNS_SOLVE/helplib:CNS_HELPLIB \$CNS_DATA/helplib:g" \
  140. -e "s:\$CNS_SOLVE/bin/cns_info:\$CNS_DATA/cns_info:g" \
  141. -e "/^g77on/d" \
  142. -i "${S}"/cns_solve_env || die
  143. # I don't entirely understand why the sh version requires a leading /
  144. # for CNS_SOLVE and CNS_ROOT, but it does
  145. sed \
  146. -e "s:${S}:/usr:g" \
  147. -e "s:^\(^[[:space:]]*CNS_SOLVE=.*\):\1\nexport CNS_ROOT=${EPREFIX}/usr:g" \
  148. -e "s:^\(^[[:space:]]*CNS_SOLVE=.*\):\1\nexport CNS_DATA=\$CNS_ROOT/share/cns:g" \
  149. -e "s:^\(^[[:space:]]*CNS_SOLVE=.*\):\1\nexport CNS_DOC=\$CNS_ROOT/share/doc/${PF}:g" \
  150. -e "s:CNS_LIB=\$CNS_SOLVE/libraries:CNS_LIB=\$CNS_DATA/libraries:g" \
  151. -e "s:CNS_MODULE=\$CNS_SOLVE/modules:CNS_MODULE=\$CNS_DATA/modules:g" \
  152. -e "s:CNS_HELPLIB=\$CNS_SOLVE/helplib:CNS_HELPLIB=\$CNS_DATA/helplib:g" \
  153. -e "s:\$CNS_SOLVE/bin/cns_info:\$CNS_DATA/cns_info:g" \
  154. -e "/^g77on/d" \
  155. -e "/^g77off/d" \
  156. -i "${T}"/cns_solve_env_sh || die
  157. # Get rid of setup stuff we don't need in the installed script
  158. sed \
  159. -e "83,$ d" \
  160. -e "37,46 d" \
  161. -i "${S}"/cns_solve_env || die
  162. sed \
  163. -e "84,$ d" \
  164. -e "39,50 d" \
  165. -i "${T}"/cns_solve_env_sh || die
  166. newbin "${S}"/*linux*/bin/cns_solve* cns_solve
  167. # Can be run by either cns_solve or cns
  168. dosym cns_solve /usr/bin/cns
  169. # Don't want to install this
  170. rm -f "${S}"/*linux*/utils/Makefile || die
  171. dobin "${S}"/*linux*/utils/*
  172. sed \
  173. -e "s:\$CNS_SOLVE/doc/:\$CNS_SOLVE/share/doc/${PF}/:g" \
  174. -i "${S}"/bin/cns_web || die
  175. dobin "${S}"/bin/cns_{edit,header,transfer,web}
  176. insinto /usr/share/cns
  177. doins -r "${S}"/libraries "${S}"/modules "${S}"/helplib
  178. doins "${S}"/bin/cns_info
  179. insinto /etc/profile.d
  180. newins "${S}"/cns_solve_env cns_solve_env.csh
  181. newins "${T}"/cns_solve_env_sh cns_solve_env.sh
  182. dohtml \
  183. -A iq,cgi,csh,cv,def,fm,gif,hkl,inp,jpeg,lib,link,list,mask,mtf,param,pdb,pdf,pl,ps,sc,sca,sdb,seq,tbl,top \
  184. -f all_cns_info_template,omac,def \
  185. -r doc/html/*
  186. # Conflits with app-text/dos2unix
  187. rm -f "${D}"/usr/bin/dos2unix || die
  188. }
  189. pkg_postinst() {
  190. if use openmp; then
  191. elog "Set OMP_NUM_THREADS to the number of threads you want."
  192. elog "If you get segfaults on large structures, set the GOMP_STACKSIZE"
  193. elog "variable if using gcc (16384 should be good)."
  194. fi
  195. }