1# Since the same derivation can be depended on in multiple ways, we need to
2# accumulate *each* role (i.e. host and target platforms relative the depending
3# derivation) in which the derivation is used.
4#
5# The role is intended to be used as part of other variables names like
6# - $NIX_SOMETHING${role_post}
7
8function getRole() {
9 case $1 in
10 -1)
11 role_post='_FOR_BUILD'
12 ;;
13 0)
14 role_post=''
15 ;;
16 1)
17 role_post='_FOR_TARGET'
18 ;;
19 *)
20 echo "@name@: used as improper sort of dependency" >&2
21 return 1
22 ;;
23 esac
24}
25
26# `hostOffset` describes how the host platform of the package is slid relative
27# to the depending package. `targetOffset` likewise describes the target
28# platform of the package. Both are brought into scope of the setup hook defined
29# for dependency whose setup hook is being processed relative to the package
30# being built.
31
32function getHostRole() {
33 getRole "$hostOffset"
34}
35function getTargetRole() {
36 getRole "$targetOffset"
37}
38
39# `depHostOffset` describes how the host platform of the dependencies are slid
40# relative to the depending package. `depTargetOffset` likewise describes the
41# target platform of dependenices. Both are brought into scope of the
42# environment hook defined for the dependency being applied relative to the
43# package being built.
44
45function getHostRoleEnvHook() {
46 getRole "$depHostOffset"
47}
48function getTargetRoleEnvHook() {
49 getRole "$depTargetOffset"
50}
51
52# This variant is intended specifically for code-producing tool wrapper scripts
53# `NIX_@wrapperName@_TARGET_*_@suffixSalt@` tracks this (needs to be an exported
54# env var so can't use fancier data structures).
55function getTargetRoleWrapper() {
56 case $targetOffset in
57 -1)
58 export NIX_@wrapperName@_TARGET_BUILD_@suffixSalt@=1
59 ;;
60 0)
61 export NIX_@wrapperName@_TARGET_HOST_@suffixSalt@=1
62 ;;
63 1)
64 export NIX_@wrapperName@_TARGET_TARGET_@suffixSalt@=1
65 ;;
66 *)
67 echo "@name@: used as improper sort of dependency" >&2
68 return 1
69 ;;
70 esac
71}