xref: /curl/.github/scripts/cmp-pkg-config.sh (revision 9f56bb60)
1#!/usr/bin/env bash
2# Copyright (C) Viktor Szakats
3#
4# SPDX-License-Identifier: curl
5
6# Sort list of libs, libpaths, cflags found in libcurl.pc and curl-config files,
7# then diff the autotools and cmake generated ones.
8
9sort_lists() {
10  prevline=''
11  section=''
12  while IFS= read -r l; do
13    if [[ "${prevline}" =~ (--cc|--configure) ]]; then  # curl-config
14      echo "<IGNORED>"
15    else
16      # libcurl.pc
17      if [[ "${l}" =~ ^(Requires|Libs|Cflags)(\.private)?:\ (.+)$ ]]; then
18        if [ "${BASH_REMATCH[1]}" = 'Requires' ]; then
19          # Spec does not allow duplicates here:
20          # https://manpages.debian.org/unstable/pkg-config/pkg-config.1.en.html#Requires:
21          # "You may only mention the same package one time on the Requires: line"
22          val="$(printf '%s' "${BASH_REMATCH[3]}" | tr ',' '\n' | sort | tr '\n' ' ')"
23        else
24          val="$(printf '%s' "${BASH_REMATCH[3]}" | tr ' ' '\n' | sort -u | tr '\n' ' ')"
25        fi
26        l="${BASH_REMATCH[1]}${BASH_REMATCH[2]}: ${val}"
27      # curl-config
28      elif [[ "${section}" =~ (--libs|--static-libs) && "${l}" =~ ^( *echo\ \")(.+)(\")$ ]]; then
29        val="$(printf '%s' "${BASH_REMATCH[2]}" | tr ' ' '\n' | sort -u | tr '\n' ' ')"
30        l="${BASH_REMATCH[1]}${val}${BASH_REMATCH[3]}"
31        section=''
32      fi
33      echo "${l}"
34    fi
35    # curl-config
36    prevline="${l}"
37    if [[ "${l}" =~ --[a-z-]+\) ]]; then
38      section="${BASH_REMATCH[0]}"
39    fi
40  done < "$1"
41}
42
43am=$(mktemp -t autotools.XXX); sort_lists "$1" > "${am}"
44cm=$(mktemp -t cmake.XXX)    ; sort_lists "$2" > "${cm}"
45diff -u "${am}" "${cm}"
46res="$?"
47rm -r -f "${am}" "${cm}"
48
49exit "${res}"
50