forgejo-lts: 7.0.10 -> 7.0.11
[NixPkgs.git] / pkgs / os-specific / bsd / setup-hook.sh
blob08dfdd4b14b6fb094d3ea5e9adddebd893177803
1 # shellcheck shell=bash disable=SC2154,SC2164
3 # BSD makefiles should be able to detect this
4 # but without they end up using gcc on Darwin stdenv
5 addMakeFlags() {
6 export setOutputFlags=
8 export LIBCRT0=
9 export LIBCRTI=
10 export LIBCRTEND=
11 export LIBCRTBEGIN=
12 export LIBC=
13 export LIBUTIL=
14 export LIBSSL=
15 export LIBCRYPTO=
16 export LIBCRYPT=
17 export LIBCURSES=
18 export LIBTERMINFO=
19 export LIBM=
20 export LIBL=
22 export _GCC_CRTBEGIN=
23 export _GCC_CRTBEGINS=
24 export _GCC_CRTEND=
25 export _GCC_CRTENDS=
26 export _GCC_LIBGCCDIR=
27 export _GCC_CRTI=
28 export _GCC_CRTN=
29 export _GCC_CRTDIR=
31 # Definitions passed to share/mk/*.mk. Should be pretty simple -
32 # eventually maybe move it to a configure script.
33 export USETOOLS=never
34 export NOCLANGERROR=yes
35 export NOGCCERROR=yes
36 export LEX=flex
37 export MKUNPRIVED=yes
38 export EXTERNAL_TOOLCHAIN=yes
40 prependToVar makeFlags "MACHINE=$MACHINE"
41 prependToVar makeFlags "MACHINE_ARCH=$MACHINE_ARCH"
42 prependToVar makeFlags "AR=$AR"
43 prependToVar makeFlags "CC=$CC"
44 prependToVar makeFlags "CPP=$CPP"
45 prependToVar makeFlags "CXX=$CXX"
46 prependToVar makeFlags "LD=$LD"
47 prependToVar makeFlags "STRIP=$STRIP"
49 prependToVar makeFlags "BINDIR=${!outputBin}/bin"
50 prependToVar makeFlags "LIBDIR=${!outputLib}/lib"
51 prependToVar makeFlags "SHLIBDIR=${!outputLib}/lib"
52 prependToVar makeFlags "SHAREDIR=${!outputLib}/share"
53 prependToVar makeFlags "INFODIR=${!outputInfo}/share/info"
54 prependToVar makeFlags "DOCDIR=${!outputDoc}/share/doc"
55 prependToVar makeFlags "LOCALEDIR=${!outputLib}/share/locale"
57 # Parallel building. Needs the space.
58 prependToVar makeFlags "-j $NIX_BUILD_CORES"
61 setBSDSourceDir() {
62 sourceRoot=$PWD/$sourceRoot
63 export BSDSRCDIR=$sourceRoot
64 export _SRC_TOP_=$BSDSRCDIR
65 cd "$sourceRoot"
68 cdBSDPath() {
69 if [ -d "$COMPONENT_PATH" ]
70 then sourceRoot=$sourceRoot/$COMPONENT_PATH
71 cd "$COMPONENT_PATH"
75 includesPhase() {
76 if [ -z "${skipIncludesPhase:-}" ]; then
77 runHook preIncludes
79 local flagsArray=()
80 concatTo flagsArray makeFlags makeFlagsArray
81 flagsArray+=(includes)
83 echoCmd 'includes flags' "${flagsArray[@]}"
84 make ${makefile:+-f $makefile} "${flagsArray[@]}"
86 moveUsrDir
88 runHook postIncludes
92 moveUsrDir() {
93 if [ -d "$prefix" ]; then
94 # Remove lingering /usr references
95 if [ -d "$prefix/usr" ]; then
96 # Didn't try using rsync yet because per
97 # https://unix.stackexchange.com/questions/127712/merging-folders-with-mv,
98 # it's not neessarily better.
99 pushd "$prefix/usr"
100 find . -type d -exec mkdir -p "$out/{}" \;
101 find . \( -type f -o -type l \) -exec mv "{}" "$out/{}" \;
102 popd
105 find "$prefix" -type d -empty -delete
109 postUnpackHooks+=(setBSDSourceDir)
110 postPatchHooks+=(cdBSDPath)
111 preConfigureHooks+=(addMakeFlags)
112 preInstallHooks+=(includesPhase)
113 fixupOutputHooks+=(moveUsrDir)