summaryrefslogtreecommitdiff
path: root/auto-meson-pc-cmp.sh
blob: 88d1cd8616ea424bb09142dd13e96f45ece382c1 (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
#!/bin/sh
# Compare semantically pc files between two dirs, with same relative
# pathnames, say one generated by autotools, the other one generated
# by meson, by not requesting lexical identity but by
# checking that the same vars are available, and that they eventually 
# have the same definition, whatever way (with whatever pkconf
# variable) they have been expressed.
#
# Copyright 2024 Thierry LARONDE <tlaronde@kergis.com>
# SPDX-License-Identifier: MIT

# Pc file paths have to be given fully qualified to be independent
# from PKG_CONFIG_LIBDIR and PKG_CONFIG_PATH definition.
#
test $# -eq 2 && test -d "$1" && test -d "$2"\
	&& test "${1#/}" != "$1" && test "${2#/}" != "$2" || {
	echo "Usage: $(basename $0) fqdir1 fqdir2" >&2
	exit 1
}

: ${TMPDIR:=/tmp}

log() {
	printf "$@" >&2
}

cleantmp() {
	rm "$TMPDIR"/$$.*
}

dir1="$1"
dir2="$2"

# Start by simply comparing the list of pc files between the two dirs.
#
(cd "$dir1"; find . -type f -name "*.pc") | sort > "$TMPDIR/$$.1"
(cd "$dir2"; find . -type f -name "*.pc") | sort > "$TMPDIR/$$.2"
cmp "$TMPDIR/$$.1" "$TMPDIR/$$.2" 2>/dev/null || {
	log "Pc files not matching between %s and %s:\n" "$dir1" "$dir2"
	diff -u "$TMPDIR/$$.1" "$TMPDIR/$$.2" >&2
	cleantmp
	exit 1
}

status=0
while read pcfile; do
	pcfile=${pcfile#./}
	ifile=0
	for pc in "$dir1/$pcfile" "$dir2/$pcfile"; do
		ifile=$(($ifile + 1))
		pkgconf --print-variables "$pc"\
			| sort\
			| while read var; do
				test "$var" != "pcfiledir" || continue
				pkgconf --variable=$var "$pc"\
					| sed "s!^!$var=!"
			done >"$TMPDIR/$$.pc$ifile"
	done
	if ! cmp "$TMPDIR/$$.pc1" "$TMPDIR/$$.pc2" 2>/dev/null; then
		log "!!! %s generated files differ:\n" "$pcfile"
		diff -U0 "$TMPDIR/$$.pc1" "$TMPDIR/$$.pc2" >&2
		status=$(($status + 1))
	fi
done  <"$TMPDIR/$$.1"

cleantmp
if test "$status" -ne 0; then
	log "%d pc files in %s and %s differ semantically.\n" "$status" "$dir1" "$dir2"
	exit 1
else
	exit 0
fi