1# shellcheck shell=bash
2
3# Setup hook that installs specified pkgconfig items.
4#
5# Example usage in a derivation:
6#
7# { …, makePkgconfigItem, copyPkgconfigItems, … }:
8#
9# let pkgconfigItem = makePkgconfigItem { … }; in
10# stdenv.mkDerivation {
11# …
12# nativeBuildInputs = [ copyPkgconfigItems ];
13#
14# pkgconfigItems = [ pkgconfigItem ];
15# …
16# }
17#
18# This hook will copy files which are either given by full path
19# or all '*.pc' files placed inside the 'lib/pkgconfig'
20# folder of each `pkgconfigItems` argument.
21
22postInstallHooks+=(copyPkgconfigItems)
23
24copyPkgconfigItems() {
25 if [ "${dontCopyPkgconfigItems-}" = 1 ]; then return; fi
26
27 if [ -z "$pkgconfigItems" ]; then
28 return
29 fi
30
31 pkgconfigdir="${!outputDev}/lib/pkgconfig"
32 for pkgconfigItem in $pkgconfigItems; do
33 if [[ -f "$pkgconfigItem" ]]; then
34 substituteAllInPlace "$pkgconfigItem"
35 echo "Copying '$pkgconfigItem' into '${pkgconfigdir}'"
36 install -D -m 444 -t "${pkgconfigdir}" "$pkgconfigItem"
37 substituteAllInPlace "${pkgconfigdir}"/*
38 else
39 for f in "$pkgconfigItem"/lib/pkgconfig/*.pc; do
40 echo "Copying '$f' into '${pkgconfigdir}'"
41 install -D -m 444 -t "${pkgconfigdir}" "$f"
42 substituteAllInPlace "${pkgconfigdir}"/*
43 done
44 fi
45 done
46}