summary refs log tree commit diff
path: root/pkgs/os-specific/bsd/setup-hook.sh
blob: 45babc38d7a5623b22d17596f28f7f7cb7b8e11c (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# BSD makefiles should be able to detect this
# but without they end up using gcc on Darwin stdenv
addMakeFlags() {
  export setOutputFlags=

  export LIBCRT0=
  export LIBCRTI=
  export LIBCRTEND=
  export LIBCRTBEGIN=
  export LIBC=
  export LIBUTIL=
  export LIBSSL=
  export LIBCRYPTO=
  export LIBCRYPT=
  export LIBCURSES=
  export LIBTERMINFO=
  export LIBM=
  export LIBL=

  export _GCC_CRTBEGIN=
  export _GCC_CRTBEGINS=
  export _GCC_CRTEND=
  export _GCC_CRTENDS=
  export _GCC_LIBGCCDIR=
  export _GCC_CRTI=
  export _GCC_CRTN=
  export _GCC_CRTDIR=

  # Definitions passed to share/mk/*.mk. Should be pretty simple -
  # eventually maybe move it to a configure script.
  export DESTDIR=
  export USETOOLS=never
  export NOCLANGERROR=yes
  export NOGCCERROR=yes
  export LEX=flex
  export MKUNPRIVED=yes
  export EXTERNAL_TOOLCHAIN=yes

  export INSTALL_FILE="install -U -c"
  export INSTALL_DIR="xinstall -U -d"
  export INSTALL_LINK="install -U -l h"
  export INSTALL_SYMLINK="install -U -l s"

  makeFlags="MACHINE=$MACHINE $makeFlags"
  makeFlags="MACHINE_ARCH=$MACHINE_ARCH $makeFlags"
  makeFlags="AR=$AR $makeFlags"
  makeFlags="CC=$CC $makeFlags"
  makeFlags="CPP=$CPP $makeFlags"
  makeFlags="CXX=$CXX $makeFlags"
  makeFlags="LD=$LD $makeFlags"
  makeFlags="STRIP=$STRIP $makeFlags"

  makeFlags="BINDIR=${!outputBin}/bin $makeFlags"
  makeFlags="LIBDIR=${!outputLib}/lib $makeFlags"
  makeFlags="SHLIBDIR=${!outputLib}/lib $makeFlags"
  makeFlags="MANDIR=${!outputMan}/share/man $makeFlags"
  makeFlags="INFODIR=${!outputInfo}/share/info $makeFlags"
  makeFlags="DOCDIR=${!outputDoc}/share/doc $makeFlags"
  makeFlags="LOCALEDIR=${!outputLib}/share/locale $makeFlags"

  # Parallel building. Needs the space.
  makeFlags="-j $NIX_BUILD_CORES $makeFlags"
}

setBSDSourceDir() {
  # merge together all extra paths
  # there should be a better way to do this
  sourceRoot=$PWD/$sourceRoot
  export BSDSRCDIR=$sourceRoot
  export _SRC_TOP_=$BSDSRCDIR
  chmod -R u+w $sourceRoot
  for path in $extraPaths; do
    cd $path
    find . -type d -exec mkdir -p $sourceRoot/\{} \;
    find . -type f -exec cp -pr \{} $sourceRoot/\{} \;
    chmod -R u+w $sourceRoot
  done

  cd $sourceRoot
  if [ -d "$BSD_PATH" ]
    then sourceRoot=$sourceRoot/$BSD_PATH
  fi
}

includesPhase() {
  if [ -z "${skipIncludesPhase:-}" ]; then
    runHook preIncludes

    local flagsArray=(
         $makeFlags ${makeFlagsArray+"${makeFlagsArray[@]}"}
         DESTDIR=${!outputInclude} includes
    )

    echoCmd 'includes flags' "${flagsArray[@]}"
    make ${makefile:+-f $makefile} "${flagsArray[@]}"

    moveUsrDir

    runHook postIncludes
  fi
}

moveUsrDir() {
  if [ -d $prefix ]; then
    # Remove lingering /usr references
    if [ -d $prefix/usr ]; then
      pushd $prefix/usr
      find . -type d -exec mkdir -p $out/\{} \;
      find . \( -type f -o -type l \) -exec mv \{} $out/\{} \;
      popd
    fi

    find $prefix -type d -empty -delete
  fi
}

postUnpackHooks+=(setBSDSourceDir)
preConfigureHooks+=(addMakeFlags)
preInstallHooks+=(includesPhase)
fixupOutputHooks+=(moveUsrDir)