summaryrefslogtreecommitdiff
path: root/dev-libs/wiringPi/wiringPi-2.44-r7.ebuild
blob: 13975b8934d352c05f1d6cc4cca10c6aab3c5173 (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
# Copyright (c) 2017 sakaki <sakaki@deciban.com>
# License: GPL v3+
# NO WARRANTY

EAPI=6
inherit flag-o-matic toolchain-funcs git-r3

KEYWORDS="~arm ~arm64"

DESCRIPTION="GPIO interface libraries (and utility) for the Raspberry Pi"
HOMEPAGE="http://wiringpi.com/"
SRC_URI=""
LICENSE="LGPL-3+"
SLOT="0"
IUSE=""
RESTRICT="mirror"

EGIT_REPO_URI="git://git.drogon.net/wiringPi"
EGIT_BRANCH="master"
# fetch the branch matching the ebuild version
EGIT_COMMIT="${PV}"

DEPEND=""
RDEPEND="
	${DEPEND}"
	
PATCHES=( "${FILESDIR}/${PV}-makefiles.patch" )

src_prepare() {
	local DIR
	# put header files in include subdirectory
	# don't make library links directly (these break)
	# update manpage location to non-deprecated value
	# get rid of suid (security risk); install utility as sbin instead
	# if on arm64, install to /usr/lib64, not /usr/lib
	# purge upstream email addresses as Gentoo is an unsupported platform
	for DIR in wiringPi devLib gpio; do
		sed -e "s#/include#/include/${PN}#" \
		-e 's:/man/man:/share/man/man:g' \
		-e 's:/bin:/sbin:g' \
		-e 's:4755:0755:g' \
		-i "${DIR}"/Makefile
		if use arm64; then
			sed -e 's:$(PREFIX)/lib:$(PREFIX)/lib64:g' \
			-e 's:/lib/:/lib64/:g' \
			-i "${DIR}"/Makefile
		fi
	done
	sed -e 's/projects@drogon.net/(email removed, Gentoo unsupported)/g' \
	-i $(find . -type f -exec grep -l "projects@drogon.net" {} +)
	# deal with problem that RPi3 in 64-bit mode does not have
	# the 'Hardware' line in /proc/cpuinfo, which the wiringPi library
	# checks, by making it look in /etc/wiringpi/cpuinfo instead
	use arm64 && epatch "${FILESDIR}/${PV}-pseudo-cpuinfo.patch"
	default
}

src_compile() {
	# git archive contains object files
	cd wiringPi
	emake V=1 clean
	append-cflags "-fPIC" "-I${S}/wiringPi"
	# ensure the right compiler and flags get used
	emake V=1 CC=$(tc-getCC) CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
		LDCONFIG=/bin/true
	# set up symlink for library
	ln -s libwiringPi.so.* libwiringPi.so

	# now ditto for other directories

	cd ../devLib
	emake V=1 clean
	append-cflags "-I${S}/devLib"
	emake V=1 CC=$(tc-getCC) CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
		LDCONFIG=/bin/true
	ln -s libwiringPiDev.so.* libwiringPiDev.so

	cd ../gpio
	emake V=1 clean
	append-cflags "-I${S}/cpio"
	append-ldflags "-L${S}/wiringPi" "-L${S}/devLib"
	emake V=1 CC=$(tc-getCC) CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" \
                LDCONFIG=/bin/true
}

src_install() {
	local LIBDIR="${D%/}/usr/lib"
	if use arm64; then
		LIBDIR+="64"
	fi
	cd wiringPi
	emake DESTDIR="${D%/}" PREFIX="/usr" install
	cp --no-dereference libwiringPi.so "${LIBDIR}/"
	cd ../devLib
	emake DESTDIR="${D%/}" PREFIX="/usr" install
	cp --no-dereference libwiringPiDev.so "${LIBDIR}/"
	cd ../gpio
	mkdir -p "${D%/}/usr/sbin"
	emake DESTDIR="${D%/}" PREFIX="/usr" install
	cd ..
	DOCS=( README.TXT People )
	if use arm64; then
		# following is a snippet of cpuinfo, for use on Pi3s (which
		# don't contain all the expected fields when booted in 64-bit
		# mode)
		insinto "/etc/${PN}"
		newins "${FILESDIR}/cpuinfo-1" "cpuinfo"
	fi
	einstalldocs
}

pkg_postinst() {
	if [[ -z ${REPLACING_VERSIONS} ]] && use arm64; then
		elog "The file /etc/${PN}/cpuinfo has been created."
		elog "The library will look there, instead of /proc/cpuinfo"
		elog "when determining system type; this is necessary because"
		elog "some /proc/cpuinfo data is not output in 64-bit mode."
		elog "It only contains the necessary stanzas."
		elog "You can modify this file as required." 
	fi
}