summary refs log tree commit diff
path: root/pkgs/build-support/setup-hooks/copy-pkgconfig-items.sh
blob: 8c04ec9b5f0ecd7798bad653d1f4a9c702de5365 (plain) (blame)
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
# shellcheck shell=bash

# Setup hook that installs specified pkgconfig items.
#
# Example usage in a derivation:
#
#   { …, makePkgconfigItem, copyPkgconfigItems, … }:
#
#   let pkgconfigItem = makePkgconfigItem { … }; in
#   stdenv.mkDerivation {
#     …
#     nativeBuildInputs = [ copyPkgconfigItems ];
#
#     pkgconfigItems =  [ pkgconfigItem ];
#     …
#   }
#
# This hook will copy files which are either given by full path
# or all '*.pc' files placed inside the 'lib/pkgconfig'
# folder of each `pkgconfigItems` argument.

postInstallHooks+=(copyPkgconfigItems)

copyPkgconfigItems() {
    if [ "${dontCopyPkgconfigItems-}" = 1 ]; then return; fi

    if [ -z "$pkgconfigItems" ]; then
        return
    fi

    pkgconfigdir="${!outputDev}/lib/pkgconfig"
    for pkgconfigItem in $pkgconfigItems; do
        if [[ -f "$pkgconfigItem" ]]; then
            substituteAllInPlace "$pkgconfigItem"
            echo "Copying '$pkgconfigItem' into '${pkgconfigdir}'"
            install -D -m 444 -t "${pkgconfigdir}" "$pkgconfigItem"
            substituteAllInPlace "${pkgconfigdir}"/*
        else
            for f in "$pkgconfigItem"/lib/pkgconfig/*.pc; do
                echo "Copying '$f' into '${pkgconfigdir}'"
                install -D -m 444 -t "${pkgconfigdir}" "$f"
                substituteAllInPlace "${pkgconfigdir}"/*
            done
        fi
    done
}