summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 4733320b3ac65739401a7cf73ff634250e2e3b89 (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
# Maintainer: acxz <akashpatel2008 at yahoo dot com>
# Contributor: Norbert Weber <norbert.weber_at_hzdr.de>
# Contributor: Marc Olesen
# Contributor: Xwang <xwaang1976@gmail.com>
# Contributor: George Eleftheriou <eleftg>
# Contributor: Andrew Fischer <andrew_at_apastron.co>
# Contributor: <gucong43216@gmail.com>

pkgname=openfoam-com-git
pkgver=r25230.6e1fca0e46
_distname=OpenFOAM
_dist=openfoam
pkgrel=2
pkgdesc="The open source CFD toolbox (www.openfoam.com)"
arch=('i686' 'x86_64')
url="http://www.openfoam.com"
license=('GPL3')
install="openfoam-com.install"
depends=('cgal' 'fftw' 'boost' 'openmpi' 'paraview' 'utf8cpp' 'scotch' 'metis' 'parmetis' 'kahip')
makedepends=('git')
source=("git+https://develop.openfoam.com/Development/openfoam.git")
sha256sums=('SKIP')

pkgver() {
  cd "${_dist}"
  printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

prepare() {
  if [ -n "$WM_PROJECT_DIR" ]
  then
    echo
    echo -e "\e[1m\e[5m\e[31mPlease make sure that no OpenFOAM version is sourced in bashrc.\e[0m"
    echo
    return 1
  fi

  projectDir="${srcdir}/${_dist}"

  # Configure components.
  # Use system values for boost/cgal, fftw, kahip, metis, scotch, paraview

  "${projectDir}"/bin/tools/foamConfigurePaths \
    -boost boost-system \
    -cgal  cgal-system \
    -fftw  fftw-system \
    -kahip kahip-system \
    -metis metis-system \
    -scotch scotch-system \
    -paraview paraview-system \
    ;
}

build() {
  if [ -n "$WM_PROJECT_DIR" ]
  then
    echo
    echo -e "\e[1m\e[5m\e[31mPlease make sure that no OpenFOAM version is sourced in bashrc.\e[0m"
    echo
    return 1
  fi

  projectDir="${srcdir}/${_dist}"
  [ -f "$projectDir/etc/bashrc" ] || {
      echo "No $projectDir/etc/bashrc found"
      return 1
  }

  # changes to avoid linking problems related to gcc 11
  # check this for the next upgrade!
  pwd
  sed -i 's/g++$(COMPILER_VERSION) -std=c++11/g++$(COMPILER_VERSION) -std=c++14/g' $projectDir/wmake/rules/General/Gcc/c++

  # Avoid external influence on the environment
  export FOAM_CONFIG_MODE="o"
  unset FOAM_SETTINGS

  set +e  # Turn errexit off

  source "$projectDir"/etc/bashrc '' || \
    echo "Ignore spurious sourcing error"

  # it seems, the bashrc file destroys 'projectDir'
  projectDir="${srcdir}/${_dist}"

  set -e  # Turn errexit back on
  cd "$projectDir" || exit

  # Dummy application for testing
  #./applications/test/00-dummy/Allwmake

  ./Allwmake -j -q -s -log=log.build

  # Check log for this type of content:
  #
  #   api   = 2006
  #   patch = 1
  #   bin   = 283 entries
  #   lib   = 139 entries

  [ -f log.build ] || {
      echo "No log.build file - build failed entirely"
      exit 1
  }

  bins="$( cat log.build | sed -ne 's/.*bin *= *\([0-9][0-9]*\).*/\1/p;' | sed -ne '$p' )"
  libs="$( cat log.build | sed -ne 's/.*lib *= *\([0-9][0-9]*\).*/\1/p;' | sed -ne '$p' )"

  if [ "${bins:=0}" = 0 ] || [ "${libs:=0}" = 0 ]
  then
      echo
      echo "Build failed with $bins executables and $libs libraries"
      echo "Check the log.build file"
      echo
      exit 1
  fi
}


package() {
  cd ${srcdir}

  # Installation directories
  parentDir="${pkgdir}/opt/${_distname}"
  projectDir="${parentDir}/${_dist}"

  # Create destination directories
  install -d "${parentDir}" "${pkgdir}"/etc/profile.d || return 1

  # Copy package to pkgdir
  cp -r "${srcdir}/${_dist}" "${parentDir}" || return 1

  # Permission fixes - for system-wide install and use
  chmod -R go+r "${pkgdir}"/opt
  chmod -R 755 "${projectDir}"/bin
  chmod -R 755 "${projectDir}"/etc

  [ -e "${projectDir}"/ThirdParty ] || \
      echo "system dependencies" >| "${projectDir}"/ThirdParty

#  # Install shell-session script. Could be via post-install
#  session="/usr/bin/openfoam${pkgver#v}"
#  wrapper="$projectDir/bin/tools/openfoam.in"
#
#  if [ -f "$wrapper" ]
#  then
#      echo "Create $session"
#      sed -e "s#@PROJECT_DIR@#${projectDir}#" "$wrapper" >| "$session"
#      chmod 0755 "$session"
#  else
#      echo "No method to create $session for openfoam${pkgver#v}"
#  fi

  # create alias in .bashrc
  echo "alias of='source /opt/${_distname}/${_dist}/etc/bashrc'" >> ~/.bashrc
  echo "alias paraFoam='paraFoam -builtin'" >> ~/.bashrc
}

# ---------------------------------------------------------------------------