build.sh: add libXpresent
[xorg-util-modular.git] / auto-meson-pc-cmp.sh
blob88d1cd8616ea424bb09142dd13e96f45ece382c1
1 #!/bin/sh
2 # Compare semantically pc files between two dirs, with same relative
3 # pathnames, say one generated by autotools, the other one generated
4 # by meson, by not requesting lexical identity but by
5 # checking that the same vars are available, and that they eventually
6 # have the same definition, whatever way (with whatever pkconf
7 # variable) they have been expressed.
9 # Copyright 2024 Thierry LARONDE <tlaronde@kergis.com>
10 # SPDX-License-Identifier: MIT
12 # Pc file paths have to be given fully qualified to be independent
13 # from PKG_CONFIG_LIBDIR and PKG_CONFIG_PATH definition.
15 test $# -eq 2 && test -d "$1" && test -d "$2"\
16 && test "${1#/}" != "$1" && test "${2#/}" != "$2" || {
17 echo "Usage: $(basename $0) fqdir1 fqdir2" >&2
18 exit 1
21 : ${TMPDIR:=/tmp}
23 log() {
24 printf "$@" >&2
27 cleantmp() {
28 rm "$TMPDIR"/$$.*
31 dir1="$1"
32 dir2="$2"
34 # Start by simply comparing the list of pc files between the two dirs.
36 (cd "$dir1"; find . -type f -name "*.pc") | sort > "$TMPDIR/$$.1"
37 (cd "$dir2"; find . -type f -name "*.pc") | sort > "$TMPDIR/$$.2"
38 cmp "$TMPDIR/$$.1" "$TMPDIR/$$.2" 2>/dev/null || {
39 log "Pc files not matching between %s and %s:\n" "$dir1" "$dir2"
40 diff -u "$TMPDIR/$$.1" "$TMPDIR/$$.2" >&2
41 cleantmp
42 exit 1
45 status=0
46 while read pcfile; do
47 pcfile=${pcfile#./}
48 ifile=0
49 for pc in "$dir1/$pcfile" "$dir2/$pcfile"; do
50 ifile=$(($ifile + 1))
51 pkgconf --print-variables "$pc"\
52 | sort\
53 | while read var; do
54 test "$var" != "pcfiledir" || continue
55 pkgconf --variable=$var "$pc"\
56 | sed "s!^!$var=!"
57 done >"$TMPDIR/$$.pc$ifile"
58 done
59 if ! cmp "$TMPDIR/$$.pc1" "$TMPDIR/$$.pc2" 2>/dev/null; then
60 log "!!! %s generated files differ:\n" "$pcfile"
61 diff -U0 "$TMPDIR/$$.pc1" "$TMPDIR/$$.pc2" >&2
62 status=$(($status + 1))
64 done <"$TMPDIR/$$.1"
66 cleantmp
67 if test "$status" -ne 0; then
68 log "%d pc files in %s and %s differ semantically.\n" "$status" "$dir1" "$dir2"
69 exit 1
70 else
71 exit 0