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