*/*: Clean PYTHON_COMPAT of obsolete impls
[gentoo.git] / sys-apps / file / file-9999.ebuild
1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=7
5
6 PYTHON_COMPAT=( python2_7 python3_{6,7,8} )
7 DISTUTILS_OPTIONAL=1
8
9 inherit distutils-r1 libtool toolchain-funcs multilib-minimal
10
11 if [[ ${PV} == "9999" ]] ; then
12         EGIT_REPO_URI="https://github.com/glensc/file.git"
13         inherit autotools git-r3
14 else
15         SRC_URI="ftp://ftp.astron.com/pub/file/${P}.tar.gz"
16         KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~m68k ~mips ~ppc ~ppc64 ~riscv ~s390 ~sh ~sparc ~x86 ~ppc-aix ~x64-cygwin ~amd64-linux ~x86-linux ~ppc-macos ~x64-macos ~x86-macos ~m68k-mint ~sparc-solaris ~sparc64-solaris ~x64-solaris ~x86-solaris"
17 fi
18
19 DESCRIPTION="identify a file's format by scanning binary data for patterns"
20 HOMEPAGE="https://www.darwinsys.com/file/"
21
22 LICENSE="BSD-2"
23 SLOT="0"
24 IUSE="bzip2 lzma python seccomp static-libs zlib"
25 REQUIRED_USE="python? ( ${PYTHON_REQUIRED_USE} )"
26
27 DEPEND="
28         bzip2? ( app-arch/bzip2[${MULTILIB_USEDEP}] )
29         lzma? ( app-arch/xz-utils[${MULTILIB_USEDEP}] )
30         python? (
31                 ${PYTHON_DEPS}
32                 dev-python/setuptools[${PYTHON_USEDEP}]
33         )
34         zlib? ( >=sys-libs/zlib-1.2.8-r1[${MULTILIB_USEDEP}] )"
35 RDEPEND="${DEPEND}
36         python? ( !dev-python/python-magic )
37         seccomp? ( sys-libs/libseccomp[${MULTILIB_USEDEP}] )"
38
39 src_prepare() {
40         default
41
42         [[ ${PV} == "9999" ]] && eautoreconf
43         elibtoolize
44
45         # don't let python README kill main README #60043
46         mv python/README.md python/README.python.md || die
47         sed 's@README.md@README.python.md@' -i python/setup.py || die #662090
48 }
49
50 multilib_src_configure() {
51         local myeconfargs=(
52                 --enable-fsect-man5
53                 $(use_enable bzip2 bzlib)
54                 $(use_enable lzma xzlib)
55                 $(use_enable seccomp libseccomp)
56                 $(use_enable static-libs static)
57                 $(use_enable zlib)
58         )
59         econf "${myeconfargs[@]}"
60 }
61
62 build_src_configure() {
63         local myeconfargs=(
64                 --disable-shared
65                 --disable-libseccomp
66                 --disable-bzlib
67                 --disable-xzlib
68                 --disable-zlib
69         )
70         tc-env_build econf "${myeconfargs[@]}"
71 }
72
73 need_build_file() {
74         # when cross-compiling, we need to build up our own file
75         # because people often don't keep matching host/target
76         # file versions #362941
77         tc-is-cross-compiler && ! has_version -b "~${CATEGORY}/${P}"
78 }
79
80 src_configure() {
81         local ECONF_SOURCE=${S}
82
83         if need_build_file; then
84                 mkdir -p "${WORKDIR}"/build || die
85                 cd "${WORKDIR}"/build || die
86                 build_src_configure
87         fi
88
89         multilib-minimal_src_configure
90 }
91
92 multilib_src_compile() {
93         if multilib_is_native_abi ; then
94                 emake
95         else
96                 cd src || die
97                 emake magic.h #586444
98                 emake libmagic.la
99         fi
100 }
101
102 src_compile() {
103         if need_build_file; then
104                 emake -C "${WORKDIR}"/build/src magic.h #586444
105                 emake -C "${WORKDIR}"/build/src file
106                 local -x PATH="${WORKDIR}/build/src:${PATH}"
107         fi
108         multilib-minimal_src_compile
109
110         if use python ; then
111                 cd python || die
112                 distutils-r1_src_compile
113         fi
114 }
115
116 multilib_src_install() {
117         if multilib_is_native_abi ; then
118                 default
119         else
120                 emake -C src install-{nodist_includeHEADERS,libLTLIBRARIES} DESTDIR="${D}"
121         fi
122 }
123
124 multilib_src_install_all() {
125         dodoc ChangeLog MAINT README
126
127         # Required for `file -C`
128         dodir /usr/share/misc/magic
129         insinto /usr/share/misc/magic
130         doins -r magic/Magdir/*
131
132         if use python ; then
133                 cd python || die
134                 distutils-r1_src_install
135         fi
136         find "${ED}" -type f -name "*.la" -delete || die
137 }