summaryrefslogtreecommitdiff
blob: 77c3bde5c40bc46c9b5faa2ec238d2a503c4bf42 (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
# Copyright 1999-2021 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=7

WX_GTK_VER="3.0-gtk3"
VIRTUALX_REQUIRED="manual"

inherit flag-o-matic java-pkg-opt-2 java-ant-2 toolchain-funcs virtualx wxwidgets

DESCRIPTION="A WAM based Prolog system"
HOMEPAGE="http://ctp.di.fct.unl.pt/~amd/cxprolog"
SRC_URI="http://ctp.di.fct.unl.pt/~amd/cxprolog/cxunix/${P}.src.tgz"

LICENSE="GPL-3+"
SLOT="0"
KEYWORDS="amd64 x86"
IUSE="examples java +readline test wxwidgets"
RESTRICT="!test? ( test )"

RDEPEND="readline? ( sys-libs/readline:= )
	java? ( >=virtual/jdk-1.8:= )
	wxwidgets? ( x11-libs/wxGTK:${WX_GTK_VER}[X] )"

DEPEND="${RDEPEND}
	test? (
		java? ( ${VIRTUALX_DEPEND} )
		wxwidgets? ( ${VIRTUALX_DEPEND} )
	)"

S="${WORKDIR}"/${P}

src_prepare() {
	eapply "${FILESDIR}"/${P}-portage.patch
	eapply "${FILESDIR}"/${P}-test-io.patch
	eapply_user

	sed -i -e "s|lib/cxprolog|$(get_libdir)/cxprolog|" "${S}"/src/FileSys.c || die
	cp "${FILESDIR}"/build.xml "${S}"/build.xml || die
	cp "${FILESDIR}"/cx_dev_boot.pl "${S}"/cx_dev_boot.pl || die
	rm -f "${S}"/pl/test_file_io_1.txt

	use wxwidgets && setup-wxwidgets
}

src_compile() {
	local CX_EXT_DEFINES
	local CX_EXT_CFLAGS
	local CX_EXT_LDFLAGS
	local CX_EXT_LIBS

	if use readline; then
		CX_EXT_DEFINES="$CX_EXT_DEFINES -DUSE_READLINE"
		CX_EXT_LIBS="$CX_EXT_LIBS -lreadline"
	fi

	if use java; then
		local java_arch
		use x86 && java_arch=i386
		use amd64 && java_arch=amd64
		CX_JVM="${JAVA_HOME}/jre/lib/${java_arch}/server"
		CX_EXT_DEFINES="$CX_EXT_DEFINES -DUSE_JAVA"
		CX_EXT_CFLAGS="$CX_EXT_CFLAGS $(java-pkg_get-jni-cflags)"
		CX_EXT_LDFLAGS="$CX_EXT_LDFLAGS -Wl,-rpath,${CX_JVM}"
		CX_EXT_LIBS="$CX_EXT_LIBS -L${CX_JVM} -ljvm"
	fi

	if use wxwidgets; then
		CX_EXT_DEFINES="$CX_EXT_DEFINES -DUSE_WXWIDGETS"
		CX_EXT_CFLAGS="$CX_EXT_CFLAGS $(${WX_CONFIG} --cflags)"
		CX_EXT_LIBS="$CX_EXT_LIBS $(${WX_CONFIG} --libs)"
	fi

	emake lib \
		PREFIX=/usr \
		TMP_DIR="${S}/tmp" \
		CC=$(tc-getCC) \
		CPP=$(tc-getCXX) \
		LD=$(tc-getLD) \
		CFLAGS="${CFLAGS}" \
		LDFLAGS="${LDFLAGS}" \
		EXT_DEFINES="${CX_EXT_DEFINES}" \
		EXT_CFLAGS="-Wall ${CX_EXT_CFLAGS}" \
		EXT_LDFLAGS="${CX_EXT_LDFLAGS}" \
		EXT_LIBS="${CX_EXT_LIBS}"

	if use java; then
		JAVA_SRC_DIR="${S}/lib/cxprolog/java"
		eant jar
	fi
}

cxprolog_src_test() {
	cd "${S}"/pl

	if use java; then
		local test_javadir="${S}"/pl/$(get_libdir)/cxprolog/java
		mkdir -p "${test_javadir}" || die
		ln -s "${S}"/dist/prolog.jar "${test_javadir}"/prolog.jar || die
	fi

	LD_LIBRARY_PATH="${S}" \
		"${S}"/cxprolog_shared \
		--boot "${S}"/cx_dev_boot.pl \
		--script "${S}"/pl/test_all.pl \
		| tee "${S}"/cxprolog_test.log
}

src_test() {
	if use java || use wxwidgets; then
		virtx cxprolog_src_test
	else
		cxprolog_src_test
	fi

	grep -q "ALL THE TESTS PASSED" "${S}"/cxprolog_test.log \
		|| die "cxprolog unit tests failed"
}

src_install() {
	newbin cxprolog_shared cxprolog
	dolib.so libcxprolog.so

	insinto /usr/$(get_libdir)/cxprolog
	doins lib/cxprolog/lib.pl

	insinto /usr/share/${PN}/pl
	doins pl/*.{pl,txt}

	if use java; then
		insinto /usr/$(get_libdir)/cxprolog/java
		doins dist/prolog.jar
	fi

	dodoc ChangeLog.txt MANUAL.txt README.txt

	if use examples; then
		dodoc -r examples
	fi
}