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://0001-m4-readline-add-missing-includes.patch \
20           file://run-ptest \
21           "
22
23SRC_URI[sha256sum] = "378f8864ec21cfceaa048f7e1869ac9b4597b449087caf1eb55e440d30273336"
24
25inherit autotools gettext texinfo update-alternatives
26
27FILES:${PN} += "${datadir}/awk"
28FILES:${PN}-dev += "${libdir}/${BPN}/*.la"
29
30PACKAGES =+ "${PN}-gawkbug"
31FILES:${PN}-gawkbug += "${bindir}/gawkbug"
32
33ALTERNATIVE:${PN} = "awk"
34ALTERNATIVE_TARGET[awk] = "${bindir}/gawk"
35ALTERNATIVE_PRIORITY = "100"
36
37do_install:append() {
38	# remove the link since we don't package it
39	rm ${D}${bindir}/awk
40	# Strip non-reproducible build flags (containing build paths)
41	sed -i -e 's|^CC.*|CC=""|g' -e 's|^CFLAGS.*|CFLAGS=""|g' ${D}${bindir}/gawkbug
42}
43
44inherit ptest
45
46do_install_ptest() {
47	mkdir ${D}${PTEST_PATH}/test
48	ln -s ${bindir}/gawk ${D}${PTEST_PATH}/gawk
49	# The list of tests is all targets in Maketests, apart from the dummy Gt-dummy
50	TESTS=$(awk -F: '$1 == "Gt-dummy" { next } /[[:alnum:]]+:$/ { print $1 }' ${S}/test/Maketests)
51	for i in $TESTS Maketests inclib.awk; do
52		cp ${S}/test/$i* ${D}${PTEST_PATH}/test
53	done
54	sed -i \
55	    -e 's|#! /bin/gawk|#! ${bindir}/gawk|g' \
56	    -e 's|#! /usr/local/bin/gawk|#! ${bindir}/gawk|g' \
57	    -e 's|#!${base_bindir}/awk|#!${bindir}/awk|g' ${D}${PTEST_PATH}/test/*.awk
58
59	sed -i -e "s|GAWKLOCALE|LANG|g" ${D}${PTEST_PATH}/test/Maketests
60
61	# These tests require an unloaded host as otherwise timing sensitive tests can fail
62	# https://bugzilla.yoctoproject.org/show_bug.cgi?id=14371
63	rm -f ${D}${PTEST_PATH}/test/time.*
64	rm -f ${D}${PTEST_PATH}/test/timeout.*
65	for t in time timeout; do
66		echo $t >> ${D}${PTEST_PATH}/test/skipped.txt
67	done
68}
69
70do_install_ptest:append:libc-musl() {
71	# Reported  https://lists.gnu.org/archive/html/bug-gawk/2021-02/msg00005.html
72	rm -f ${D}${PTEST_PATH}/test/clos1way6.*
73	# Needs en_US.UTF-8 but then does not work with musl
74	rm -f ${D}${PTEST_PATH}/test/backsmalls1.*
75	# Needs en_US.UTF-8 but then does not work with musl
76	rm -f ${D}${PTEST_PATH}/test/commas.*
77	# The below two need LANG=C inside the make rule for musl
78	rm -f ${D}${PTEST_PATH}/test/rebt8b1.*
79	rm -f ${D}${PTEST_PATH}/test/regx8bit.*
80	for t in clos1way6 backsmalls1 commas rebt8b1 regx8bit; do
81		echo $t >> ${D}${PTEST_PATH}/test/skipped.txt
82	done
83}
84
85RDEPENDS:${PN}-ptest += "make locale-base-en-us coreutils"
86
87RDEPENDS:${PN}-ptest:append:libc-glibc = " locale-base-en-us.iso-8859-1"
88RDEPENDS:${PN}-ptest:append:libc-musl = " musl-locales"
89
90BBCLASSEXTEND = "native nativesdk"
91