summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: a72fd541b179321b6452804d6f3c3a99ac8d959e (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
# Maintainer of this PKBGUILD file: Martino Pilia <martino.pilia@gmail.com>
pkgname=salome-meca-bin
pkgver=2017.0.2
pkgrel=6
pkgdesc='Integration of the Code_Aster solver in the Salome platform'
arch=('x86_64')
url='https://www.code-aster.org/spip.php?article303'
license=('LGPL')
depends=('openblas')
makedepends=()
optdepends=()
provides=('salome-meca')
source=("https://www.code-aster.org/FICHIERS/Salome-Meca-${pkgver}-LGPL-1.tgz")
md5sums=('e65b4da01a8200492b94a278db621029')

build() {
	cd "${srcdir}"

	echo "Extracting installer..."

	# remove previous build folder if present, otherwise the installer will fail
	rm -rf ${srcdir}/salome_meca || :

	# self-extract
	./Salome-Meca-2017.0.2-LGPL-1.run &> /dev/null <<-EOF
	${srcdir}/salome_meca
	EOF

	cd "${srcdir}/salome_meca/V2017.0.2/" 

	# impose the right path for the setup script
	sed -i \
		"107iSALOMEDIR=${srcdir}/salome_meca/V2017.0.2/" \
		create_appli.sh

	# use the bundled version of python
	export PATH="${srcdir}/salome_meca/V2017.0.2/prerequisites/Python-2710/bin/":$PATH

	# try using the system freetype2 library
	# update to freetype2 2.9 breaks the bundled version
	rm "${srcdir}/salome_meca/V2017.0.2/prerequisites/Freetype-2411"/lib/libfreetype.so*

	echo "Building virtual application..."

	# create virtual application
	# -D to not automatically create a (wrong) desktop and menu entry
	./create_appli.sh -D &> /dev/null <<-EOF
	${srcdir}/salome_meca/appli_V2017.0.2
	EOF

	# ensure that the extraction did not fail
	if [ ! -e "${srcdir}/salome_meca/appli_V2017.0.2/salome" ]; then
		error "Extraction of the application failed, please check '${srcdir}/salome_meca/appli_V2017.0.2/appli_V2017.0.2.log' for relevant error messages."
		exit 1
	fi

	# create .desktop file from template
	sed -e "s,APPLIDIR/salome,/usr/bin/salome_meca," \
		-e "s,SALOMEDIR,/opt/salome_meca/V2017.0.2," \
		${srcdir}/salome_meca/V2017.0.2/.salome_meca_V2017.0.2.desktop \
		> ${srcdir}/salome_meca.desktop

	echo "Fixing references..."

	# fix references to srcdir
	for f in `grep -RI "${srcdir}" ${srcdir} | cut -d: -f1`; do
		sed -i "s,${srcdir},/opt,g" $f
	done

	echo "Fixing symlinks..."

	# fix symlinks pointing to srcdir
	# https://stackoverflow.com/questions/31020219/how-change-symlink-path-for-many-files
	_oldpath="${srcdir}"
	_newpath='/opt'
	find ${srcdir}/salome_meca -type l -execdir bash -c 'p="$(readlink "{}")"; if [ "${p:0:1}" != "/" ]; then p="$(echo "$(pwd)/$p" | sed -e "s|/\./|/|g" -e ":a" -e "s|/[^/]*/\.\./|/|" -e "t a")"; fi; if [ "${p:0:'${#_oldpath}'}" == "'"$_oldpath"'" ]; then ln -snf "'"$_newpath"'${p:'${#_oldpath}'}" "{}"; fi;' \;
}

package() {
	cd ${srcdir}

	# create launcher script
	# use the bundled libraries and Python version 
	_path='PATH=/opt/salome_meca/V2017.0.2/prerequisites/Python-2710/bin/:$PATH'
	_ld_path="LD_LIBRARY_PATH=\$(find /opt/salome_meca/V2017.0.2/ -type d -name lib  | tr '\\n' ':' | sed 's/:$//'):\$LD_LIBRARY_PATH"
	mkdir -p ${pkgdir}/usr/bin
	cat > ${pkgdir}/usr/bin/salome_meca <<-EOF
	#!/usr/bin/env bash
	$_path $_ld_path /opt/salome_meca/appli_V2017.0.2/salome "\$@"
	EOF
	chmod +x ${pkgdir}/usr/bin/salome_meca

	# install bash completions
	mkdir -p $pkgdir/usr/share/bash-completion/completions
	install -D -m644 \
		"${srcdir}/salome_meca/appli_V2017.0.2/.salome-completion.sh" \
		"${pkgdir}/usr/share/bash-completion/completions/salome"

	# install application
	mkdir ${pkgdir}/opt
	mv ${srcdir}/salome_meca ${pkgdir}/opt/salome_meca

	# install .desktop file
	mkdir -p ${pkgdir}/usr/share/applications
	install -D -m644 \
		"${srcdir}/salome_meca.desktop" \
		"${pkgdir}/usr/share/applications/salome_meca.desktop"
}