summaryrefslogtreecommitdiff
blob: ca95b9fefd98efdd1f285514f34d301fdf2d0f92 (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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# Copyright 1999-2024 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=6

inherit fortran-2 flag-o-matic toolchain-funcs

MY_P="${PN}${PV//.}"

DESCRIPTION="FORTRAN/C device-independent scientific graphic library"
HOMEPAGE="https://www.astro.caltech.edu/~tjp/pgplot/"
SRC_URI="ftp://ftp.astro.caltech.edu/pub/pgplot/${MY_P}.tar.gz"

LICENSE="free-noncomm"
SLOT="0"
KEYWORDS="amd64 ~arm ~ia64 ~ppc ~x86 ~amd64-linux ~x86-linux"
IUSE="doc motif static-libs tk"

RDEPEND="
	media-libs/libpng:=
	x11-libs/libX11:=
	x11-libs/libXt:=
	motif? ( x11-libs/motif:= )
	tk? ( dev-lang/tk:= )"
DEPEND="${RDEPEND}
	doc? ( virtual/latex-base )"

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

PATCHES=(
	"${FILESDIR}"/${PN}-drivers.patch
	"${FILESDIR}"/${PN}-makemake.patch
	"${FILESDIR}"/${PN}-compile-setup.patch
	"${FILESDIR}"/${PN}-headers.patch
	"${FILESDIR}"/${PN}-libpng15.patch
	"${FILESDIR}"/${PN}-tk86.patch
)

src_prepare() {
	default

	# fix pointers for 64 bits
	if use amd64 || use ia64; then
		sed -e 's/INTEGER PIXMAP/INTEGER*8 PIXMAP/g' \
			-i drivers/{gi,pp,wd}driv.f || die "sed 64bits failed"
	fi

	cp sys_linux/g77_gcc.conf local.conf

	sed -e "s:FCOMPL=.*:FCOMPL=\"$(tc-getFC)\":g" \
		-e "s:CCOMPL=.*:CCOMPL=\"$(tc-getCC)\":g" \
		-i local.conf || die "sed flags failed"

	if [[ "$(tc-getFC)" = if* ]]; then
		sed -e 's/-Wall//g' \
			-e 's/TK_LIBS="/TK_LIBS="-nofor-main /' \
			-i local.conf || die "sed drivers failed"
	fi

	sed -e "s:/usr/local/pgplot:${EPREFIX}/usr/$(get_libdir)/pgplot:g" \
		-e "s:/usr/local/bin:${EPREFIX}/usr/bin:g" \
		-i src/grgfil.f makehtml maketex || die "sed path failed"

	use motif && sed -i -e '/XMDRIV/s/!//' drivers.list
	use tk && sed -i -e '/TKDRIV/s/!//' drivers.list
}

src_configure() {
	# -Werror=lto-type-mismatch
	# https://bugs.gentoo.org/862918
	#
	# Upstream contact method is email. I have sent one.
	filter-lto

	# GCC 10 workaround
	# bug #722190
	append-fflags $(test-flags-FC -fallow-argument-mismatch)

	./makemake . linux
	# post makefile creation prefix hack
	sed -i -e "s|/usr|${EPREFIX}/usr|g" makefile || die
}

src_compile() {
	emake \
		CFLAGS="${CFLAGS} -fPIC" \
		FFLAGS="${FFLAGS} -fPIC" \
		shared cpg-shared pgxwin_server pgdisp pgplot.doc

	use tk && emake CFLAGS="${CFLAGS} -fPIC" libtkpgplot.so
	use motif && emake CFLAGS="${CFLAGS} -fPIC" libXmPgplot.so

	emake -j1 clean
	use static-libs && emake all cpg

	if use doc; then
		export VARTEXFONTS="${T}/fonts"
		emake pgplot.html pgplot-routines.tex
		pdflatex pgplot-routines.tex
		pdflatex pgplot-routines.tex
	fi

	# this just cleans out not needed files
	emake -j1 clean
}

src_test() {
	# i can go to 16
	local i j
	for i in 1 2 3; do
		emake pgdemo${i}
		# j can also be LATEX CPS...
		for j in NULL PNG PS CPS LATEX; do
			local testexe=./test_${j}_${i}
			echo "LD_LIBRARY_PATH=. ./pgdemo${i} <<EOF" > ${testexe}
			echo "/${j}" >> ${testexe}
			echo "EOF" >> ${testexe}
			sh ${testexe} || die "test ${i} failed"
		done
	done
}

src_install() {
	insinto /usr/$(get_libdir)/pgplot
	doins grfont.dat grexec.f *.inc rgb.txt
	echo "PGPLOT_FONT=${EPREFIX}/usr/$(get_libdir)/pgplot/grfont.dat" >> 99pgplot
	doenvd 99pgplot

	dolib.so libpgplot.so*
	dobin pgxwin_server pgdisp

	# C binding
	insinto /usr/include
	doins cpgplot.h
	dolib.so libcpgplot.so*

	if use motif; then
		insinto /usr/include
		doins XmPgplot.h
		dolib.so libXmPgplot.so*
	fi

	if use tk; then
		insinto /usr/include
		doins tkpgplot.h
		dolib.so libtkpgplot.so*
	fi

	use static-libs && dolib.a lib*pgplot.a

	# minimal doc
	dodoc aaaread.me pgplot.doc
	newdoc pgdispd/aaaread.me pgdispd.txt

	if use doc; then
		dodoc cpg/cpgplot.doc applications/curvefit/curvefit.doc pgplot.html
		dodoc pgplot-routines.pdf pgplot-routines.tex
		docinto examples
		dodoc -r examples/. cpg/cpgdemo.c
		docompress -x /usr/share/doc/${PF}/examples
		dodoc -r applications
		docompress -x /usr/share/doc/${PF}/applications
		if use motif; then
			docinto pgm
			dodoc -r pgmf/. drivers/xmotif/pgmdemo.c
			docompress -x /usr/share/doc/${PF}/pgm
		fi
		if use tk; then
			docinto pgtk
			dodoc drivers/xtk/pgtkdemo.*
			docompress -x /usr/share/doc/${PF}/pgtk
		fi
	fi
}