1 # Copyright 1999-2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
6 JAVA_PKG_IUSE="doc source"
8 inherit eutils java-pkg-2 java-pkg-simple
10 DESCRIPTION="JFlex is a lexical analyzer generator for Java"
11 HOMEPAGE="http://www.jflex.de/"
12 SRC_URI="http://${PN}.de/${P}.tar.gz"
15 KEYWORDS="amd64 ~arm arm64 ppc64 x86 ~ppc-macos ~x64-macos ~x86-macos"
16 IUSE="examples test vim-syntax"
17 RESTRICT="!test? ( test )"
19 CDEPEND="dev-java/ant-core:0"
21 RDEPEND=">=virtual/jre-1.6
22 vim-syntax? ( || ( app-editors/vim app-editors/gvim ) )
25 DEPEND=">=virtual/jdk-1.6
26 test? ( dev-java/junit:4 )
29 PDEPEND=">=dev-java/javacup-0.11b_p20151001:0"
32 JAVA_SRC_DIR="src/main/java"
35 # See below for details.
36 epatch "${FILESDIR}/icedtea-arm.patch"
38 # We need the bundled jflex.jar.
39 rm -rv ${JAVA_SRC_DIR}/java_cup examples/pom.xml || die
41 # Remove the bundled java-cup.jar if unneeded.
42 if has_version ${PDEPEND}; then
43 rm -v lib/java-cup-*.jar || die
48 # javacup is a cyclic dependency. Use the package if we have it,
49 # otherwise use the bundled version and install the package later.
50 if has_version ${PDEPEND}; then
51 # Use PORTAGE_QUIET to suppress a QA warning that is spurious
52 # thanks to has_version above. This is Portage-specific but
53 # showing the warning elsewhere isn't the end of the world.
54 JAVACUP=$(PORTAGE_QUIET=1 java-pkg_getjar --build-only javacup javacup.jar)
56 JAVACUP=$(echo lib/java-cup-*.jar)
59 JAVA_GENTOO_CLASSPATH_EXTRA="$(java-pkg_getjars --build-only ant-core):${JAVACUP}"
63 java "${@}" jflex.Main -d ${JAVA_SRC_DIR}/${PN} --skel src/main/${PN}/skeleton.nested src/main/${PN}/LexScan.flex || die
64 java-pkg-simple_src_compile
65 java-pkg_addres ${PN}.jar src/main/resources
69 java -jar "${JAVACUP}" -destdir ${JAVA_SRC_DIR}/${PN} -package ${PN} -parser LexParse -interface src/main/cup/LexParse.cup || die
71 # The IcedTea ARM HotSpot port (as of 2.6.1) hangs when running
72 # jflex. We have patched jflex to fix it but we have to run the
73 # bundled version first. -Xint works around the problem. See
74 # http://icedtea.classpath.org/bugzilla/show_bug.cgi?id=2678.
75 use arm && local JFLEX_ARGS="-Xint"
77 # First compile (without doc/source) using the bundled jflex.
78 JAVA_PKG_IUSE= jflex_compile -cp "lib/${P}.jar:${JAVACUP}" ${JFLEX_ARGS}
80 # Then recompile using the fresh jflex.
81 jflex_compile -cp "${PN}.jar:${JAVACUP}"
85 java-pkg-simple_src_install
86 java-pkg_dolauncher ${PN} --main ${PN}.Main
88 java-pkg_register-dependency javacup javacup-runtime.jar
89 java-pkg_register-ant-task
91 use examples && java-pkg_doexamples examples
92 dodoc {changelog,README}.md
97 dodoc doc/*.{css,html,png} doc/COPYRIGHT
100 if use vim-syntax; then
101 insinto /usr/share/vim/vimfiles/syntax
107 if use arm && java-pkg_current-vm-matches oracle-jdk-bin-1.8; then
108 # This results in a StackOverflowError as of 1.8.0.65 but works
109 # fine on icedtea:7. Don't know about icedtea:8 yet.
110 rm -v src/test/java/jflex/EmitterTest.java || die
113 local CP="src/test/java:${PN}.jar:${JAVA_GENTOO_CLASSPATH_EXTRA}:$(java-pkg_getjars junit-4)"
115 local TESTS=$(find src/test/java -name "*Test*.java" -printf "%P\n")
116 TESTS="${TESTS//.java}"
117 TESTS="${TESTS//\//.}"
119 ejavac -classpath "${CP}" $(find src/test/java -name "*.java")
120 ejunit4 -classpath "${CP}" ${TESTS}