app-forensics/magicrescue: stabilize on x86
[gentoo.git] / app-forensics / sleuthkit / sleuthkit-4.6.7.ebuild
1 # Copyright 1999-2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=6
5
6 JAVA_PKG_BSFIX_NAME="build.xml build-unix.xml"
7 inherit autotools java-pkg-opt-2 java-ant-2
8
9 DESCRIPTION="A collection of file system and media management forensic analysis tools"
10 HOMEPAGE="https://www.sleuthkit.org/sleuthkit/"
11 # TODO: sqlite-jdbc does not exist in the tree, we bundle it for now
12 # TODO: Upstream uses a very specific version of libewf which is not in
13 #       the tree anymore. So we statically compile and link to sleuthkit.
14 #       Hopefully upstream will figure something out in the future.
15 SRC_URI="https://github.com/${PN}/${PN}/releases/download/${P}/${P}.tar.gz
16         java? (
17                 http://repo1.maven.org/maven2/org/xerial/sqlite-jdbc/3.25.2/sqlite-jdbc-3.25.2.jar
18                 http://repo1.maven.org/maven2/com/zaxxer/SparseBitSet/1.1/SparseBitSet-1.1.jar
19         )
20         ewf? ( https://github.com/sleuthkit/libewf_64bit/archive/VisualStudio_2010.tar.gz -> sleuthkit-libewf_64bit-20130416.tar.gz )"
21
22 LICENSE="BSD CPL-1.0 GPL-2+ IBM java? ( Apache-2.0 )"
23 SLOT="0/13" # subslot = major soname version
24 KEYWORDS="~amd64 ~hppa ~ppc ~x86"
25 IUSE="aff doc ewf java postgres static-libs test +threads zlib"
26 RESTRICT="!test? ( test )"
27
28 # Note: It is not possible to move the dep on dev-java/jdbc-postgresql
29 # inside a conditional postgres? block because java sources import
30 # org.postgres unconditionally as of writing this (version 4.6.4). The
31 # postgres USE flag will be used for the TSK postgresql support however.
32 DEPEND="
33         dev-db/sqlite:3
34         dev-lang/perl:*
35         aff? ( app-forensics/afflib )
36         ewf? ( sys-libs/zlib )
37         java? (
38                 >=virtual/jdk-1.8:*
39                 >=dev-java/c3p0-0.9.5:0
40                 >=dev-java/jdbc-postgresql-9.4:0
41         )
42         postgres? ( dev-db/postgresql:= )
43         zlib? ( sys-libs/zlib )
44 "
45 # TODO: add support for not-in-tree libraries libvhdi and libvmdk
46 # libvhdi: https://github.com/libyal/libvhdi
47 # libvmdk: https://github.com/libyal/libvmdk
48 # DEPEND="${DEPEND}
49 #       vhdi? ( dev-libs/libvhdi )
50 #       vmdk? ( dev-libs/libvmdk )
51 # "
52
53 RDEPEND="${DEPEND}
54         java? ( >=virtual/jre-1.8:= )
55 "
56 DEPEND="${DEPEND}
57         doc? ( app-doc/doxygen )
58         test? ( >=dev-util/cppunit-1.2.1 )
59 "
60
61 PATCHES=(
62         "${FILESDIR}"/${PN}-4.1.0-tools-shared-libs.patch
63         "${FILESDIR}"/${PN}-4.6.4-default-jar-location-fix.patch
64 )
65
66 src_unpack() {
67         local f
68
69         unpack ${P}.tar.gz
70
71         if use ewf; then
72                 pushd "${T}" &>/dev/null || die
73                 unpack sleuthkit-libewf_64bit-20130416.tar.gz
74                 export TSK_LIBEWF_SRCDIR="${T}"/libewf_64bit-VisualStudio_2010
75                 popd &>/dev/null || die
76         fi
77
78         # Copy the jar files that don't exist in the tree yet
79         if use java; then
80                 TSK_JAR_DIR="${T}/lib"
81                 mkdir "${TSK_JAR_DIR}" || die
82                 for f in ${A}; do
83                         if [[ ${f} =~ .jar$ ]]; then
84                                 cp "${DISTDIR}"/"${f}" "${TSK_JAR_DIR}" || die
85                         fi
86                 done
87                 export TSK_JAR_DIR
88         fi
89 }
90
91 tsk_prepare_libewf() {
92         # Inlining breaks the compilation, disable it
93         sed -e 's/LIBUNA_INLINE inline/LIBUNA_INLINE/' \
94                 -i "${TSK_LIBEWF_SRCDIR}"/libuna/libuna_inline.h || die
95 }
96
97 src_prepare() {
98         use ewf && tsk_prepare_libewf
99
100         if use java; then
101                 pushd "${S}"/bindings/java &>/dev/null || die
102
103                 # Prevent "make install" from installing
104                 # jar files under /usr/share/java
105                 # We'll use the java eclasses for this
106                 sed -e '/^jar_DATA/ d;' -i Makefile.am || die
107
108                 java-pkg-opt-2_src_prepare
109
110                 popd &>/dev/null || die
111         fi
112
113         # Override the doxygen output directories
114         if use doc; then
115                 sed -e "/^OUTPUT_DIRECTORY/ s|=.*$|= ${T}/doc|" \
116                         -i tsk/docs/Doxyfile \
117                         -i bindings/java/doxygen/Doxyfile || die
118         fi
119
120         # It's safe to call this even after java-pkg-opt-2_src_prepare
121         # because future calls to eapply_user do nothing and return 0
122         default
123
124         eautoreconf
125 }
126
127 tsk_compile_libewf() {
128         local myeconfargs=(
129                 --prefix=/
130                 --libdir=/lib
131                 --enable-static
132                 --disable-shared
133                 --disable-winapi
134                 --without-libbfio
135                 --with-zlib
136                 --without-bzip2
137                 --without-libhmac
138                 --without-openssl
139                 --without-libuuid
140                 --without-libfuse
141
142                 --with-libcstring=no
143                 --with-libcerror=no
144                 --with-libcdata=no
145                 --with-libclocale=no
146                 --with-libcnotify=no
147                 --with-libcsplit=no
148                 --with-libuna=no
149                 --with-libcfile=no
150                 --with-libcpath=no
151                 --with-libbfio=no
152                 --with-libfcache=no
153                 --with-libfvalue=no
154
155         )
156         # We want to contain our build flags
157         local CFLAGS="${CFLAGS}"
158         local LDFLAGS="${LDFLAGS}"
159
160         pushd "${TSK_LIBEWF_SRCDIR}" &>/dev/null || die
161
162         # Produce relocatable code
163         CFLAGS+=" -fPIC"
164         LDFLAGS+=" -fPIC"
165         econf "${myeconfargs[@]}"
166
167         # Do not waste CPU cycles on building ewftools
168         sed -e '/ewftools/ d' -i Makefile || die
169         emake
170
171         # Only install the headers and the library
172         emake -C libewf DESTDIR="${T}"/image install
173         emake -C include DESTDIR="${T}"/image install
174         find "${T}"/image -name '*.la' -delete || die
175
176         popd &>/dev/null || die
177 }
178
179 src_configure() {
180         local myeconfargs=(
181                 --enable-offline="${TSK_JAR_DIR}"
182                 $(use_enable java)
183                 $(use_enable static-libs static)
184                 $(use_enable threads multithreading)
185                 $(use_with aff afflib)
186                 $(use_with zlib)
187         )
188         # Workaround the automagic detection of postgresql
189         local -x ac_cv_lib_pq_PQlibVersion="$(usex postgres)"
190         # TODO: add support for non-existing libraries libvhdi and libvmdk
191         # myeconfargs+=(
192         #       $(use_with vhdi libvhdi)
193         #       $(use_with vmdk libvmdk)
194         # )
195         myeconfargs+=(
196                 --without-libvhdi
197                 --without-libvmdk
198         )
199
200         use ewf && tsk_compile_libewf
201         myeconfargs+=( $(use_with ewf libewf "${T}"/image) )
202
203         if use java; then
204                 pushd "${S}"/bindings/java &>/dev/null || die
205                 java-ant-2_src_configure
206                 popd &>/dev/null || die
207         fi
208
209         econf "${myeconfargs[@]}"
210 }
211
212 src_compile() {
213         # Give it an existing bogus ivy home #672220
214         local -x IVY_HOME="${T}"
215
216         # Create symlinks of jars for the required dependencies
217         if use java; then
218                 pushd "${S}"/bindings/java &>/dev/null || die
219
220                 java-pkg_jar-from --into "${TSK_JAR_DIR}" c3p0
221                 java-pkg_jar-from --into "${TSK_JAR_DIR}" jdbc-postgresql
222
223                 popd &>/dev/null || die
224         fi
225
226         # Create the doc output dirs if requested
227         if use doc; then
228                 mkdir -p "${T}"/doc/{api-docs,jni-docs} || die
229         fi
230
231         emake all $(usex doc api-docs "")
232 }
233
234 src_install() {
235         local f
236
237         if use java; then
238                 pushd "${S}"/bindings/java &>/dev/null || die
239
240                 java-pkg_newjar "dist/${P}.jar" "${PN}.jar"
241
242                 # Install the bundled jar files
243                 pushd "${TSK_JAR_DIR}" &>/dev/null || die
244                 for f in *; do
245                         # Skip the symlinks java-pkg_jar-from created
246                         [[ -f ${f} ]] || continue
247
248                         # Strip the version numbers as per eclass recommendation
249                         [[ ${f} =~ -([0-9]+\.)+jar$ ]] || continue
250
251                         java-pkg_newjar "${f}" "${f/${BASH_REMATCH[0]}/.jar}"
252                 done
253                 popd &>/dev/null || die
254
255                 popd &>/dev/null || die
256         fi
257
258         default
259
260         # It unconditionally builds both api and jni docs
261         # We install conditionally based on the provided use flags
262         if use doc; then
263                 dodoc -r "${T}"/doc/api-docs
264                 use java && dodoc -r "${T}"/doc/jni-docs
265         fi
266
267         find "${D}" -name '*.la' -delete || die
268 }