summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 685d8c480cb87882b88f2f501a5cbc4eade13136 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
# Based on the AUR package, adapted to my PETSc
# (Metis, Hypre, OpenMPI, VTK, HDF5, ifem, nodeconstraint
# shared libraries; Methods: opt oprof dbg; x86_64)
#
# Maintainer eDgar <eDgar % a t % openmail cc>

pkgname=libmesh-petsc
pkgbase=libmesh
pkgrel=1
pkgver=cpp03_final.r6839.g3e858a733
pkgdesc="A C++ Finite Element Library"
arch=("x86_64")
url="http://libmesh.github.io/"
license=('LGPL')
provides=($pkgbase "metaphysicl" "timpi")
conflicts=($pkgbase)
depends=('eigen' 'hdf5' 'boost-libs' 'intel-tbb' 'vtk'
         'glpk' 'netcdf' 'nlopt' "petsc" "hypre"
         "openmpi" "metis")
makedepends=('bison' 'coreutils')
# From tar.bz2
# source=("https://github.com/libMesh/libmesh/releases/download/v${pkgver}/libmesh-${pkgver}.tar.bz2")
# sha256sums=('638cf30d05c249315760f16cbae4804964db8857a04d5e640f37617bef17ab0f')
source=(
  "${pkgbase}::git+https://github.com/libMesh/libmesh"
)
sha256sums=('SKIP')

#  From UPC: Building And Using Static And Shared "C"
#  Libraries.html
# #+begin_QUOTE
# we need that all jump calls ("goto", in assembly speak)
# and subroutine calls will use relative addresses, and not
# absolute addresses. Thus, we need to use ... ~-fPIC~ or
# ~-fpic~
# #+end_QUOTE
#
#  From makepkg.conf
# -march (or -mcpu) builds exclusively for an architecture
# -mtune optimizes for an architecture, but builds for
#  whole processor family
#
# -O3 optimises
#
# -D-FORTIFY-SOURCE=2
# | https://stackoverflow.com/a/16604146
# |- man 7 feature_test_macros
# checks to be performed to detect some buffer overflow
# errors when employing various string and memory
# manipulation functions ... some  conforming programs
# might fail
#
# -fcf-protection
# | Info pages for gcc (gnu compiler collection)
# intended to protect against such threats as
# Return-oriented Programming (ROP), and similarly
# call/jmp-oriented programming (COP/JOP)
#
# -pipe
# | Info pages for gcc (controlling the kind of output)
# Use pipes rather than temporary files for communication
# between the various stages of compilation
#
# -fno-plt
# | Info pages for gcc (code generation conventions)
# leads to more efficient code by eliminating PLT stubs and
# exposing GOT loads to optimizations
#
# -fopenmp
# | Info pages for gcc (controlling c dialect)
# Enable handling of OpenMP directives

# I used these for PETSc
# safe_flags="-D-FORTIFY-SOURCE=2 -fcf-protection -fno-plt -fstack-clash-protection -Wformat -Werror=format-security"
safe_flags="-Wp,-D_FORTIFY_SOURCE=2,-D_GLIBCXX_ASSERTIONS"
safe_flags+=" -fcf-protection -fno-plt"
safe_flags+=" -fstack-clash-protection -Wformat"
safe_flags+=" -Werror=format-security"
generic_flags="-pipe -fno-plt -fPIC -fopenmp"
generic_flags+=" -march=native"
generic_flags+=" -mtune=native ${safe_flags}"
opt_flags="${generic_flags} -O3"
generic_flags="${generic_flags} -O2"

export COPTFLAGS="${opt_flags}"
export CXXOPTFLAGS="$COPTFLAGS"
export FOPTFLAGS="$COPTFLAGS"
export CPPFLAGS="$generic_flags"
export CXXFLAGS="$CPPFLAGS"
export CFLAGS="$generic_flags"
export FFLAGS="$generic_flags"
export FCFLAGS="$generic_flags"
export F90FLAGS="$generic_flags"
export F77FLAGS="$generic_flags"
# I used these (from MOOSE)
# export METHODS="opt oprof dbg"
export METHODS="opt dbg"

export OMPI_MCA_opal_cuda_support=0
# export OMPI_MCA_mpi_oversubscribe=0
export CC=mpicc CXX=mpicxx FC=mpifort
# Find the location of the header files of PETSc
# # Get the PETSc directory
# petsc_incl=$(pkgconf --cflags-only-I PETSc)
# export PETSC_DIR=${petsc_incl##-I}
[ -f "/etc/profile.d/petsc.sh" ] &&
  source "/etc/profile.d/petsc.sh"

# Use English, metres, dates like the rest of us
export LANG=en_IE.UTF-8 LANGUAGE=en_IE.UTF-8 LC_ALL=en_IE.UTF-8

pkgver() {
  cd $pkgbase
  git describe --long --tags | sed 's/\([^-]*-g\)/r\1/;s/-/./g'
}

prepare() {
  buildir="${srcdir}"/build
  # Directory for out of source build
  [[ -d "${buildir}" ]] || mkdir "${buildir}"

  # Update Git sub-modules
  cd "${srcdir}/${pkgbase}"
  sed -i 's-=[[:space:]]*../../-=https://github.com/-g' .gitmodules
  git submodule sync --recursive
  git submodule update --init

  # Replace contrib/netcdf with system netcdf if available
  # (reminder -d: go to the right dir; by default the
  # directories are removed from path)
  patch -d "${srcdir}"/libmesh/m4 -i "${srcdir}"/netcdf.m4.patch
  cd "${srcdir}/${pkgbase}"
  autoconf
  [[ -f /usr/include/netcdf.h ]] && \
    sed -i "s-\(ac_subdirs_all='\)contrib/netcdf/v4-\1-g; s-\(subdirs=\"\$subdirs\) contrib/netcdf/v4-\1-g" configure
  patch -d "${srcdir}"/"${pkgbase}" -p1 -i "${srcdir}"/0001-Avoid-calling-virtual-function-from-DenseMatrix-resi.patch
}

build() {
  # This happens in ${pkgdir} (out-of-source)
  # Out of source build (recommended by Roy Stogner)
  buildir="${srcdir}"/build
  cd "${buildir}"
  # Remove unneeded files in-between compilations
  #   It could be that config.status and Makefile are the
  #   only things to remove in-between compilations (just to
  #   be safe, remove all files; keep directories to avoid
  #   recompiling)
  rm * || printf ""

  CONFOPTS=(
    --quiet
    --enable-silent-rules
    --srcdir="${srcdir}/${pkgbase}"
    # target directory
    --prefix=/usr
    # read-only single-machine data (Make.common)
    --sysconfdir=/etc/
    # Binary directory
    --bindir=/usr/bin
    # Base data dir (affects doc and others)
    --datadir=/usr/share
    # Make sure that the documentation is in the right place (does not work)
    --docdir=/usr/share/doc/libmesh
    # use relative addresses for jumps
    --with-pic
    # get -march flag for this system
    --enable-march
    # shared libraries
    --enable-shared

    # force C++11 standard (todo: check for update)
    --enable-cxx11-required
    # recommended by MOOSE
    --enable-petsc-hypre-required
    # recommended by MOOSE
    --enable-metaphysicl-required
    # Complex numbers
    # make sure to compile PETSc with complex too
    --enable-complex
    # CURL
    --enable-curl
    # FFTW
    --enable-fftw
    # HDF5
    --enable-hdf5
    # OpenMPI
    --enable-mpi
    # METIS
    # use PETSCs' metis
    --with-metis=/usr/lib/
    --with-metis-include=/usr/include/
    # MUMPS
    --enable-mumps
    --with-mumps=/usr/include
    --with-mumps-lib=/usr/lib
    # NETCDF
    --enable-netcdf
    --with-netcdf=/usr/include
    --with-netcdf-lib=/usr/lib
    # NLOPT
    --with-nlopt=/usr/include
    --with-nlopt-lib=/usr/lib
    # VTK
    --enable-vtk-required
    # --with-vtk-lib=/usr/lib
    # --with-vtk-include=/usr/include/vtk/

    # infinite elements
    --enable-ifem
    --enable-unique-id          # from libmesh GitHub wiki
    --enable-nodeconstraint     # from libmesh GitHub wiki

    --enable-superlu            # Does this work ?
  )

  # Configure
  local config_file="${srcdir}/${pkgbase}"/configure
  CC=mpicc \
    CXX=mpicxx \
    FC=mpifort \
    PETSC_DIR="${PETSC_DIR}" \
    OMPI_MCA_opal_warn_on_missing_libcuda=0 \
    $config_file $(for (( i=1; i<=${#CONFOPTS[@]}; i++)); do
                   echo "${CONFOPTS[$i]}";
                 done)

  # Actual build
  make
  # Is there a way to directly install the documentation in
  # the right place?
  make doc
  make examples_doc
}

# check() {
#   buildir="${srcdir}"/build
#   cd "${buildir}"
#   make check
# }

package() {
  export OMPI_MCA_opal_warn_on_missing_libcuda=0
  _buildir="${srcdir}"/build

  cd "${_buildir}"
  make DESTDIR="${pkgdir}" install

  _docdir="${pkgdir}"/usr/share/doc/libmesh/
  install -d "${_docdir}"
  install -d "${_docdir}"/examples

  # Move libtool (and contrib) to usr/share/libmesh
  mv "${pkgdir}/usr/contrib" "${pkgdir}/usr/share/libmesh/"
  # Set right path for libtool from libMesh
  sed -i 's-/usr/contrib/bin/libtool-/usr/share/libmesh/bin/libtool-g' "${pkgdir}"/{etc/libmesh,usr/lib/pkgconfig}/Make.common

  # Place examples and documentation in the right directory
  install -d "${pkgdir}"/usr/share/doc/
  cp -a "${_buildir}"/doc/html "${_docdir}"
  mv "${pkgdir}"/usr/examples "${pkgdir}"/usr/share/doc/libmesh/
  # Make local links to the source of the examples
  find "${_docdir}"/html/examples -type f -name '*.html' \
       -exec sed -i 's-https://github.com/libMesh/libmesh/tree/master/examples/\([^/]*\)/\1_\(ex\)-/usr/share/doc/libmesh/examples/\1/\2-g' \{\} +
  # Remove calls to analytics and prying eyes
  find "${_docdir}" -type f -exec \
       sed -i 's_google_google-removed_g' \{\} +

  # Set right path for Make.common
  find "${_docdir}"/examples -type f -name Makefile \
       -exec sed -i 's-\(LIBMESH_DIR[^=]*=\).*-\1 /etc/libmesh/-g' \{\} +
  # Set right path for run_common.sh
  find "${_docdir}"/examples -type f -name 'run.sh' \
       -exec sed -i 's-source LIBMESH_DIR/examples/.*-source /usr/share/doc/libmesh/examples/-g' \{\} +

  # Remove /usr/Make.common (already in /etc/libmesh)
  rm -f "${pkgdir}"/usr/Make.common || echo "removed"
}