summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 15143ef13613b111735a3f79dbcfb929f6ab4a6d (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
# Contributor: fishburn <frankthefishburn@gmail.com>

# Note: As of 5.0.11 certain key scripts (imcp, imglob, immv) are no longer shipped by upstream
# Their recommendation is to install fslpython, but this requires running an opaque installer and
# doubles the package size with no additional obvious benefit than these 3 tiny scripts. So I 
# have decided to just bundle the scripts from 5.0.10 with the package from now on.

pkgname=fsl
pkgver=5.0.11
pkgrel=1
pkgdesc="A comprehensive library of analysis tools for FMRI, MRI and DTI brain imaging data"
arch=("i686" "x86_64")
url="http://www.fmrib.ox.ac.uk/fsl/"
license=(custom)
depends=(gd libxml2 libxml++2.6 gsl libpng nlopt newmat tcl tk zlib python glu boost-libs vtk6 sqlite)
makedepends=(boost fftw)
optdepends=(cuda)
sha1sums=('4e80fce7b9626c351766966ba3be5d428e1c27cc'
          '7f9d1289887f6ff684599ce3d7a260f3d81011f2'
          '679c65c90e79b7f748ad1c2d4b5abeebebf05dfd'
          'db514c2eaa48ae924cb1c26d8b0b25d47a812876'
          '2df550b126a6ec6022a164a18dddffe4e59962f9'
          'e2d4cc873a23eedcea093715b49ace41fc6f6e1c'
          'f6d6d0177561b0f036a7e1fae4443332becd134b'
          'efb997fbaaffb5129eca2ea9388b45421e6e6de4')

source=("http://www.fmrib.ox.ac.uk/fsldownloads/fsl-${pkgver}-sources.tar.gz"
        "http://www.fmrib.ox.ac.uk/fsldownloads/fsl-${pkgver}-feeds.tar.gz"
	"systemvars.mk"
	"externallibs.mk"
	"fsl_exec.patch"
	"imcp"
	"imglob"
	"immv")

prepare() {
	
	cd "${srcdir}"

	export FSLDIR="${srcdir}/fsl"
	. "${FSLDIR}/etc/fslconf/fsl.sh"
	export FSLMACHTYPE=`${FSLDIR}/etc/fslconf/fslmachtype.sh`

	# Create new configuration
	mkdir -p "${FSLDIR}/config/${FSLMACHTYPE}"
	cp "${srcdir}/systemvars.mk" "${FSLDIR}/config/${FSLMACHTYPE}/"
	cp "${srcdir}/externallibs.mk" "${FSLDIR}/config/${FSLMACHTYPE}/"

	# Copy makepkg build flags into configuration
	sed -i '0,/${AccumulatedIncFlags}/{s^${AccumulatedIncFlags}^& '"${CFLAGS}"'^}' "${srcdir}/fsl/config/common/vars.mk"
	sed -i '0,/${AccumulatedIncFlags}/{s^${AccumulatedIncFlags}^& '"${CPPFLAGS}"'^}' "${srcdir}/fsl/config/common/vars.mk"
	sed -i '1,/${AccumulatedIncFlags}/!{s^${AccumulatedIncFlags}^& '"${CXXFLAGS}"'^}' "${srcdir}/fsl/config/common/vars.mk"
	sed -i '1,/${AccumulatedIncFlags}/!{s^${AccumulatedIncFlags}^& '"${CPPFLAGS}"'^}' "${srcdir}/fsl/config/common/vars.mk"
	sed -i 's^LDFLAGS = .*$^& '"${LDFLAGS}"'^g' "${srcdir}/fsl/config/common/vars.mk"

	# Fix 32-bit
	if test "$CARCH" == i686; then
	    sed -i "s^-m64^^g" "${FSLDIR}/config/${FSLMACHTYPE}/systemvars.mk"
	fi

	# Use system TCL/Tk
	sed -i 's^$FSLDIR/bin/fsltclsh^/usr/bin/tclsh^g' "${FSLDIR}/etc/fslconf/fsl.sh"
	sed -i 's^$FSLDIR/bin/fsltclsh^/usr/bin/tclsh^g' "${FSLDIR}/etc/fslconf/fsl-devel.sh"
	sed -i 's^$FSLDIR/bin/fsltclsh^/usr/bin/tclsh^g' "${FSLDIR}/etc/fslconf/fsl.csh"
	sed -i 's^$FSLDIR/bin/fslwish^/usr/bin/wish^g' "${FSLDIR}/etc/fslconf/fsl.sh"
	sed -i 's^$FSLDIR/bin/fslwish^/usr/bin/wish^g' "${FSLDIR}/etc/fslconf/fsl-devel.sh"
	sed -i 's^$FSLDIR/bin/fslwish^/usr/bin/wish^g' "${FSLDIR}/etc/fslconf/fsl.csh"

	# Disable building of system libraries
	sed -i 's/ libgd / /g' "${FSLDIR}/extras/build"
	sed -i 's/ libxml2-2.9.2 / /g' "${FSLDIR}/extras/build"
	sed -i 's/ libxml++-2.34.0 / /g' "${FSLDIR}/extras/build"
	sed -i 's/ newmat / /g' "${FSLDIR}/extras/build"
	sed -i 's/ boost / /g' "${FSLDIR}/extras/build"
	sed -i 's/ libnlopt / /g' "${FSLDIR}/extras/build"
	sed -i 's/ libpng"/"/g' "${FSLDIR}/extras/build"
	sed -i 's/ libiconv"/"/g' "${FSLDIR}/extras/build"
	sed -i 's/ zlib"/"/g' "${FSLDIR}/extras/build"
	sed -i 's/ fftw"/"/g' "${FSLDIR}/extras/build"
	sed -i 's/"tcl tk"/""/g' "${FSLDIR}/extras/build"

	# Link mist-clean against system sqlite
	sed -i 's^${SQLITE_LIB}/libsqlite3.a^-lsqlite3^g' "${srcdir}/fsl/src/mist-clean/Makefile"

	# Fix Melodic use of ifstream
	sed -i 's^if(in>0)^if(!!in)^g' "${FSLDIR}/src/melodic/meldata.cc"

	# Add missing library directories
	sed -i 's^-L${LIB_ZLIB}$^& -L${LIB_PROB}^g' "${FSLDIR}/src/asl_mfree/Makefile"
	sed -i 's^-L${LIB_NEWMAT} $^&-L${LIB_PROB}^g' "${FSLDIR}/src/first/Makefile"
	sed -i 's^-L${LIB_NEWMAT} $^&-L${LIB_PROB}^g' "${FSLDIR}/src/topup/Makefile"

	# Fix problem w/ dynamically-linked boost
	sed -i 's^USRCXXFLAGS = -std=c++11$^& -DBOOST_LOG_DYN_LINK^g' "${FSLDIR}/src/mist-clean/Makefile"

	# Fix fsl_exec.tcl session issue (https://www.jiscmail.ac.uk/cgi-bin/webadmin?A2=fsl;e8fa48c1.1501)
	patch -p0 < fsl_exec.patch

	# Fix missing library path in Eddy makefile
	sed -i 's^USRLDFLAGS=-L${LIB_NEWMAT}^USRLDFLAGS=-L${LIB_PROB} -L${LIB_NEWMAT}^g' "${FSLDIR}/src/eddy/Makefile"
	
}

build() {

	export FSLDIR="${srcdir}/fsl"
	cd "${FSLDIR}"
	./build

	cp -v "${srcdir}"/{imcp,imglob,immv} "${srcdir}/fsl/bin"
}

check() {

	export FSLDIR="${srcdir}/fsl"
	export FEEDSDIR="${srcdir}/feeds"
	. "${FSLDIR}/etc/fslconf/fsl.sh"
	cd "${FEEDSDIR}"
	time ./RUN all
}

package() {

	rm -rf "${srcdir}/fsl/src"
	rm -rf "${srcdir}/fsl/extras/src"
	rm -rf "${srcdir}/fsl/extras/include"
	mkdir -p "${pkgdir}/opt/fsl"

	cp -r "${srcdir}/fsl/bin"	"${pkgdir}/opt/fsl/"
	cp -r "${srcdir}/fsl/data"	"${pkgdir}/opt/fsl/"
	cp -r "${srcdir}/fsl/doc"	"${pkgdir}/opt/fsl/"
	cp -r "${srcdir}/fsl/etc"	"${pkgdir}/opt/fsl/"
	cp -r "${srcdir}/fsl/extras"	"${pkgdir}/opt/fsl/"
	cp -r "${srcdir}/fsl/lib"	"${pkgdir}/opt/fsl/"
	cp -r "${srcdir}/fsl/refdoc"	"${pkgdir}/opt/fsl/"
	cp -r "${srcdir}/fsl/tcl"	"${pkgdir}/opt/fsl/"
	cp -r "${srcdir}/feeds"	        "${pkgdir}/opt/fsl/"

	mkdir -p "${pkgdir}/etc/profile.d"
	echo 'FSLDIR=/opt/fsl' >			"${pkgdir}/etc/profile.d/fsl.sh"
	echo '. ${FSLDIR}/etc/fslconf/fsl.sh' >>	"${pkgdir}/etc/profile.d/fsl.sh"
	echo 'export FSLDIR' >>				"${pkgdir}/etc/profile.d/fsl.sh"
	echo 'export PATH=$PATH:${FSLDIR}/bin' >>	"${pkgdir}/etc/profile.d/fsl.sh"

	mkdir -p "${pkgdir}/usr/share/licenses/fsl"
	grep -v \< "${srcdir}/fsl/doc/fsl/licence.html" | cat -s > "${pkgdir}/usr/share/licenses/fsl/LICENSE"

	find "${pkgdir}" -type f -exec chmod 644 {} \;
	find "${pkgdir}" -type d -exec chmod 755 {} \;
	find "${pkgdir}/opt/fsl/bin" -exec chmod 755 {} \;
	find "${pkgdir}/opt/fsl/etc/fslconf" -exec chmod 755 {} \;
	chmod 755 "${pkgdir}/etc/profile.d/fsl.sh"
	
	mkdir -p "${pkgdir}/opt/fsl/feeds/results"
	chmod -R 777 "${pkgdir}/opt/fsl/feeds/results"
	chmod 755 "${pkgdir}/opt/fsl/feeds/RUN"
	
	find "${pkgdir}" -empty -delete
	find "${pkgdir}" -type f -exec sed -i 's^/usr/local/fsl^/opt/fsl^g' "{}" \;
}