|
root / lang / opam / build.sh
build.sh Bash 95 lines 2.6 KB
 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
#!/bin/bash
# Build script for opam on illumos
#
# opam requires illumos-specific patches for its vendored dune
# and also patches for opamUnix.c (terminal handling on illumos)

set -e
cd "$SRCDIR"

# Ensure OCaml is in PATH
export PATH="$PREFIX/bin:$PATH"

# Force 64-bit compilation
export CC="gcc -m64"
export CXX="g++ -m64"
export CFLAGS="-m64"
export CXXFLAGS="-m64"
export LDFLAGS="-m64 $LDFLAGS"

# libatomic is at /usr/lib (hammerhead BSD layout)
export LD_LIBRARY_PATH="/usr/lib:${LD_LIBRARY_PATH:-}"
export LIBRARY_PATH="/usr/lib:${LIBRARY_PATH:-}"

# PORTDIR may not be set - derive from script location or use default
if [[ -z "$PORTDIR" ]]; then
    PORTDIR="/usr/ports/devel/opam"
fi
PATCHDIR="$PORTDIR/patches"

# Apply opamUnix.c patch for illumos terminal handling
if [[ -f "src/core/opamUnix.c" ]] && [[ -f "$PATCHDIR/opamUnix.c.patch" ]]; then
    echo "Applying opamUnix.c patch..."
    patch -p1 < "$PATCHDIR/opamUnix.c.patch"
fi

# Configure without mccs solver (C++ compat issues on illumos)
./configure --prefix=$PREFIX --with-vendored-deps --without-mccs

# Build external dependencies
gmake lib-ext

# Apply illumos file replacements to vendored dune
echo "Applying illumos file replacements to vendored dune..."

# Find and replace readdir.c
DUNE_READDIR=""
for path in \
    "src_ext/dune-local/otherlibs/stdune/src/readdir.c" \
    "src_ext/dune-local/otherlibs/stdune/dune_filesystem_stubs/readdir.c" \
    "src_ext/dune/otherlibs/stdune/dune_filesystem_stubs/readdir.c" \
    "vendor/dune-local/otherlibs/stdune/dune_filesystem_stubs/readdir.c"; do
    if [[ -f "$path" ]]; then
        DUNE_READDIR="$path"
        break
    fi
done
if [[ -n "$DUNE_READDIR" ]] && [[ -f "$PATCHDIR/readdir.c" ]]; then
    cp "$PATCHDIR/readdir.c" "$DUNE_READDIR"
    echo "  - Replaced readdir.c"
fi

# Find and replace winsize.c
WINSIZE_FILE=""
for path in \
    "src_ext/dune-local/vendor/notty/src-unix/native/winsize.c" \
    "src_ext/dune/vendor/notty/src-unix/native/winsize.c"; do
    if [[ -f "$path" ]]; then
        WINSIZE_FILE="$path"
        break
    fi
done
if [[ -n "$WINSIZE_FILE" ]] && [[ -f "$PATCHDIR/winsize.c" ]]; then
    cp "$PATCHDIR/winsize.c" "$WINSIZE_FILE"
    echo "  - Replaced winsize.c"
fi

# Find and replace wait4_stubs.c
WAIT4_FILE=""
for path in \
    "src_ext/dune-local/otherlibs/stdune/src/wait4_stubs.c"; do
    if [[ -f "$path" ]]; then
        WAIT4_FILE="$path"
        break
    fi
done
if [[ -n "$WAIT4_FILE" ]] && [[ -f "$PATCHDIR/wait4_stubs.c" ]]; then
    cp "$PATCHDIR/wait4_stubs.c" "$WAIT4_FILE"
    echo "  - Replaced wait4_stubs.c"
fi

# Build opam
gmake -j${JOBS:-1}

gmake install DESTDIR="$PKGDIR"