summaryrefslogtreecommitdiff
blob: be242ba3b31c3bf85a0bf2b912ed3659e195d553 (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
# By eroen <eroen-overlay@occam.eroen.eu>, 2012 - 2017
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.

EAPI=6

inherit versionator git-r3 cmake-utils

df_PV=$(get_version_component_range 1-3)

DESCRIPTION="Memory hacking library for Dwarf Fortress and a set of tools that use it"
HOMEPAGE="http://github.com/DFHack/dfhack"
EGIT_REPO_URI="https://github.com/DFHack/dfhack.git"
if [[ $PV == *.9999 ]]; then
	EGIT_BRANCH="develop"
elif [[ $PV == *_alpha* || $PV == *_beta* ]]; then
	EGIT_MIN_CLONE="single"
	EGIT_COMMIT="${PV/_alpha/-alpha}"
	EGIT_COMMIT="${EGIT_COMMIT/_beta/-beta}"
else
	EGIT_MIN_CLONE_TYPE=mirror
	EGIT_COMMIT="7a5902418e10aed3b15cdc2edc2d45c0491bdea2"
	# xml_EGIT_COMMIT="X"
fi

SRC_URI="https://github.com/DFHack/dfhack-bin/releases/download/0.44.09/linux64-libruby187.so.gz"

KEYWORDS="-* ~amd64" # ~x86

CMAKE_MIN_VERSION=2.8.0
CMAKE_REMOVE_MODULES_LIST="FindCurses FindDoxygen CMakeVS10FindMake"

LICENSE="ZLIB MIT BSD-2 BSD CC-BY-SA-3.0"
SLOT="0"
IUSE=""

# dfhack bundles lua (5.3 as of 0.43.05-alpha1)
HDEPEND="
	>=sys-devel/gcc-4.5
	dev-lang/perl
	dev-perl/XML-LibXML
	dev-perl/XML-LibXSLT
	"
LIBRARY_DEPEND="
	sys-libs/zlib
	"
DEPEND="${LIBRARY_DEPEND}
	${HDEPEND}"
RDEPEND="${LIBRARY_DEPEND}
	~games-roguelike/dwarf-fortress-$df_PV"

PATCHES=( "$FILESDIR"/dfhack-$PV )

QA_PREBUILT="opt/dfhack/hack/libruby.so"

src_unpack() {
	git-r3_src_unpack
	if [[ -n $xml_EGIT_COMMIT ]]; then
		cd "$S/library/xml" || die
		git checkout "$xml_EGIT_COMMIT" || die
	fi

	default
	#mv "$WORKDIR/linux64-libruby187.so" "$S/plugins/ruby/linux64/" || die

	#cp "$A" "$S/plugins/ruby/linux64/libruby.so.gz"
}

src_prepare() {
	cmake-utils_src_prepare
	local install="\${HOME}/.dwarf-fortress-${df_PV}_dfhack" exe="./libs/Dwarf_Fortress"
	sed -e "s:^install=.*:install=${install}:" \
		-e "s:^exe=.*:exe=\"${exe}\":" \
		"$FILESDIR"/dfhack > "$T"/dfhack || die
	cp "$FILESDIR"/dfhack-run "$T" || die

	# No idea how this is supposed to work
	sed -e 's/@.*@/gentoo/' \
		-e 's/#cmakedefine/#define/' \
		< library/include/git-describe.h.in \
		> library/include/git-describe.h || die

	# missing -lpthread
	sed -e 's/${CMAKE_THREAD_LIBS_INIT}/& pthread/' \
		-i plugins/devel/CMakeLists.txt || die
}

src_configure() {
	local mycmakeargs=(
		-DDFHACK_BUILD_ARCH=$(usex amd64 64 "")$(usex x86 32 "")
		-DEXTERNAL_TINYXML=NO # https://bugs.gentoo.org/show_bug.cgi?id=592696
		-DCMAKE_INSTALL_PREFIX=/opt/dfhack
		-DDFHACK_DATA_DESTINATION=/opt/dfhack/hack
		-DDFHACK_LUA_DESTINATION=/opt/dfhack/hack/lua
		-DDFHACK_PLUGIN_DESTINATION=/opt/dfhack/hack/plugins
		-DDFHACK_LIBRARY_DESTINATION=/opt/dfhack/hack
		-DDFHACK_RUBY_DESTINATION=/opt/dfhack/hack/ruby
		-DBUILD_RUBY=ON
		-DDOWNLOAD_RUBY=OFF
		-DBUILD_DEV_PLUGINS=ON
		-DBUILD_SKELETON=ON
		)

	cmake-utils_src_configure
}

DOCS=""
src_install() {
	cmake-utils_src_install

	dobin "$T"/dfhack{,-run}

	insinto /opt/dfhack/hack
	insopts -m0755
	newins $WORKDIR/linux64-libruby187.so libruby.so
}

pkg_postinst() {
	elog "Due to Dwarf Fortress' special needs regarding working directory,"
	elog "specifying relative paths to DFHack plugins can give unintended results."
	elog
	elog "Your dfhack.init should be placed in \${HOME}/.dwarf-fortress-${df_PV}_dfhack/ ,"
	elog "otherwise the example configuration will be used."
	elog
	elog "To start DFHack, please run dfhack"
	elog
	elog "If you experience segfaults on launch, please try rebuilding dwarf-fortress"
	elog "with compiler optimizations disabled (CXXFLAGS=\"-O0\""
}