1SUMMARY = "GNU awk text processing utility"
2DESCRIPTION = "The GNU version of awk, a text processing utility. \
3Awk interprets a special-purpose programming language to do \
4quick and easy text pattern matching and reformatting jobs."
5HOMEPAGE = "https://www.gnu.org/software/gawk/"
6BUGTRACKER  = "bug-gawk@gnu.org"
7SECTION = "console/utils"
8
9# gawk <= 3.1.5: GPL-2.0-only
10# gawk >= 3.1.6: GPL-3.0-only
11LICENSE = "GPL-3.0-only"
12LIC_FILES_CHKSUM = "file://COPYING;md5=d32239bcb673463ab874e80d47fae504"
13
14PACKAGECONFIG ??= "readline"
15PACKAGECONFIG[readline] = "--with-readline,--without-readline,readline"
16PACKAGECONFIG[mpfr] = "--with-mpfr,--without-mpfr, mpfr"
17
18SRC_URI = "${GNU_MIRROR}/gawk/gawk-${PV}.tar.gz \
19           file://run-ptest \
20           "
21
22SRC_URI[sha256sum] = "378f8864ec21cfceaa048f7e1869ac9b4597b449087caf1eb55e440d30273336"
23
24inherit autotools gettext texinfo update-alternatives
25
26FILES:${PN} += "${datadir}/awk"
27FILES:${PN}-dev += "${libdir}/${BPN}/*.la"
28
29PACKAGES =+ "${PN}-gawkbug"
30FILES:${PN}-gawkbug += "${bindir}/gawkbug"
31
32ALTERNATIVE:${PN} = "awk"
33ALTERNATIVE_TARGET[awk] = "${bindir}/gawk"
34ALTERNATIVE_PRIORITY = "100"
35
36do_install:append() {
37	# remove the link since we don't package it
38	rm ${D}${bindir}/awk
39	# Strip non-reproducible build flags (containing build paths)
40	sed -i -e 's|^CC.*|CC=""|g' -e 's|^CFLAGS.*|CFLAGS=""|g' ${D}${bindir}/gawkbug
41}
42
43inherit ptest
44
45do_install_ptest() {
46	mkdir ${D}${PTEST_PATH}/test
47	ln -s ${bindir}/gawk ${D}${PTEST_PATH}/gawk
48	# The list of tests is all targets in Maketests, apart from the dummy Gt-dummy
49	TESTS=$(awk -F: '$1 == "Gt-dummy" { next } /[[:alnum:]]+:$/ { print $1 }' ${S}/test/Maketests)
50	for i in $TESTS Maketests inclib.awk; do
51		cp ${S}/test/$i* ${D}${PTEST_PATH}/test
52	done
53	sed -i \
54	    -e 's|#!${base_bindir}/awk|#!${bindir}/awk|g' ${D}${PTEST_PATH}/test/*.awk
55
56	sed -i -e "s|GAWKLOCALE|LANG|g" ${D}${PTEST_PATH}/test/Maketests
57
58	# These tests require an unloaded host as otherwise timing sensitive tests can fail
59	# https://bugzilla.yoctoproject.org/show_bug.cgi?id=14371
60	rm -f ${D}${PTEST_PATH}/test/time.*
61	rm -f ${D}${PTEST_PATH}/test/timeout.*
62	for t in time timeout; do
63		echo $t >> ${D}${PTEST_PATH}/test/skipped.txt
64	done
65}
66
67do_install_ptest:append:libc-musl() {
68	# Reported  https://lists.gnu.org/archive/html/bug-gawk/2021-02/msg00005.html
69	rm -f ${D}${PTEST_PATH}/test/clos1way6.*
70	# Needs en_US.UTF-8 but then does not work with musl
71	rm -f ${D}${PTEST_PATH}/test/backsmalls1.*
72	# Needs en_US.UTF-8 but then does not work with musl
73	rm -f ${D}${PTEST_PATH}/test/commas.*
74	# The below two need LANG=C inside the make rule for musl
75	rm -f ${D}${PTEST_PATH}/test/rebt8b1.*
76	rm -f ${D}${PTEST_PATH}/test/regx8bit.*
77	for t in clos1way6 backsmalls1 commas rebt8b1 regx8bit; do
78		echo $t >> ${D}${PTEST_PATH}/test/skipped.txt
79	done
80}
81
82RDEPENDS:${PN}-ptest += "make locale-base-en-us coreutils"
83
84RDEPENDS:${PN}-ptest:append:libc-glibc = " locale-base-en-us.iso-8859-1"
85RDEPENDS:${PN}-ptest:append:libc-musl = " musl-locales"
86
87BBCLASSEXTEND = "native nativesdk"
88