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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
|
#!/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"
# opam - OCaml package manager
# https://opam.ocaml.org/
[package]
name = "opam"
version = "2.5.0"
release = 1
description = "OCaml package manager"
url = "https://opam.ocaml.org/"
license = "LGPL-2.1"
maintainer = "Chris Tusa <chris.tusa@leafscale.com>"
arch = "x86_64"
[dependencies]
runtime = ["ocaml"]
build = ["ocaml", "make", "curl"]
[[source]]
file = "opam-2.5.0.tar.gz"
urls = ["https://github.com/ocaml/opam/archive/refs/tags/2.5.0.tar.gz"]
checksum = "8c5afec91db80f5c0a34b32e5186ea6349933ee65c3ebb48b15fd317464ddbfc"
# Note: Patches are handled in build.sh due to path complexity
[build]
parallel = true
--- a/src/core/opamUnix.c
+++ b/src/core/opamUnix.c
@@ -8,6 +8,12 @@
/* */
/**************************************************************************/
+#ifdef __sun
+/* illumos/Solaris: struct winsize and TIOCGWINSZ in termios */
+#include <sys/termios.h>
+#include <unistd.h>
+#endif
+
#include <sys/ioctl.h>
CAMLprim value opam_stdout_ws_col(value _unit) {
/*
* readdir.c - illumos/Solaris compatible version for dune
*
* This file replaces otherlibs/stdune/dune_filesystem_stubs/readdir.c
* in dune to fix compilation on illumos/Solaris where struct dirent
* does not have d_type field.
*
* Apply by copying this file to:
* dune-X.Y.Z/otherlibs/stdune/dune_filesystem_stubs/readdir.c
*
* For opam's bundled dune-local:
* opam-X.Y.Z/src_ext/dune-local/otherlibs/stdune/dune_filesystem_stubs/readdir.c
*/
#include <caml/alloc.h>
#include <caml/memory.h>
#include <caml/mlvalues.h>
#include <caml/unixsupport.h>
#include <errno.h>
#ifndef _WIN32
#include <caml/signals.h>
#include <errno.h>
#include <sys/types.h>
#include <dirent.h>
/* illumos/Solaris compatibility - d_type not in struct dirent */
#ifndef DT_UNKNOWN
#define DT_UNKNOWN 0
#define DT_FIFO 1
#define DT_CHR 2
#define DT_DIR 4
#define DT_BLK 6
#define DT_REG 8
#define DT_LNK 10
#define DT_SOCK 12
#define DT_WHT 14
#define ILLUMOS_NO_DTYPE 1
#endif
typedef struct dirent directory_entry;
value val_file_type(int typ) {
switch(typ)
{
#ifndef __HAIKU__
case DT_REG:
return Val_int(0);
case DT_DIR:
return Val_int(1);
case DT_CHR:
return Val_int(2);
case DT_BLK:
return Val_int(3);
case DT_LNK:
return Val_int(4);
case DT_FIFO:
return Val_int(5);
case DT_SOCK:
return Val_int(6);
case DT_UNKNOWN:
return Val_int(7);
#endif
default:
return Val_int(7);
}
}
CAMLprim value caml__dune_filesystem_stubs__readdir(value vd)
{
CAMLparam1(vd);
CAMLlocal2(v_filename, v_tuple);
DIR * d;
directory_entry * e;
d = DIR_Val(vd);
if (d == (DIR *) NULL) unix_error(EBADF, "readdir", Nothing);
caml_enter_blocking_section();
errno = 0;
e = readdir((DIR *) d);
caml_leave_blocking_section();
if (e == (directory_entry *) NULL) {
if(errno == 0) {
CAMLreturn(Val_int(0));
} else {
uerror("readdir", Nothing);
}
}
v_filename = caml_copy_string(e->d_name);
v_tuple = caml_alloc_small(2, 0);
Field(v_tuple, 0) = v_filename;
#if defined(__HAIKU__) || defined(ILLUMOS_NO_DTYPE)
/* illumos/Solaris don't have d_type, always return unknown */
Field(v_tuple, 1) = Val_int(7);
#else
Field(v_tuple, 1) = val_file_type(e->d_type);
#endif
CAMLreturn(v_tuple);
}
#else
CAMLprim value caml__dune_filesystem_stubs__readdir(value vd)
{
unix_error(ENOSYS, "readdir", Nothing);
}
#endif
#include <caml/mlvalues.h>
#ifdef _WIN32
#include <caml/fail.h>
void dune_wait4(value v_pid, value flags) { caml_failwith("wait4: not supported"); }
#else
#include <caml/alloc.h>
#include <caml/memory.h>
#include <caml/signals.h>
#include <caml/unixsupport.h>
#include <sys/resource.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <errno.h>
#include <string.h>
#define TAG_WEXITED 0
#define TAG_WSIGNALED 1
#define TAG_WSTOPPED 2
CAMLextern int caml_rev_convert_signal_number(int);
static value alloc_process_status(int status) {
value st;
if (WIFEXITED(status)) { st = caml_alloc_small(1, TAG_WEXITED); Field(st, 0) = Val_int(WEXITSTATUS(status)); }
else if (WIFSTOPPED(status)) { st = caml_alloc_small(1, TAG_WSTOPPED); Field(st, 0) = Val_int(caml_rev_convert_signal_number(WSTOPSIG(status))); }
else { st = caml_alloc_small(1, TAG_WSIGNALED); Field(st, 0) = Val_int(caml_rev_convert_signal_number(WTERMSIG(status))); }
return st;
}
static int wait_flag_table[] = {WNOHANG, WUNTRACED};
value dune_wait4(value v_pid, value flags) {
CAMLparam2(v_pid, flags);
CAMLlocal2(times, res);
int pid, status, cv_flags = caml_convert_flag_list(flags, wait_flag_table);
struct rusage ru;
struct timeval tp;
memset(&ru, 0, sizeof(ru));
caml_enter_blocking_section();
pid = waitpid(Int_val(v_pid), &status, cv_flags);
if (pid > 0) getrusage(RUSAGE_CHILDREN, &ru);
gettimeofday(&tp, NULL);
caml_leave_blocking_section();
if (pid == -1) uerror("wait4", Nothing);
times = caml_alloc_small(2 * Double_wosize, Double_array_tag);
Store_double_field(times, 0, ru.ru_utime.tv_sec + ru.ru_utime.tv_usec / 1e6);
Store_double_field(times, 1, ru.ru_stime.tv_sec + ru.ru_stime.tv_usec / 1e6);
res = caml_alloc_tuple(4);
Store_field(res, 0, Val_int(pid));
Store_field(res, 1, alloc_process_status(status));
Store_field(res, 2, caml_copy_double(((double)tp.tv_sec + (double)tp.tv_usec / 1e6)));
Store_field(res, 3, times);
CAMLreturn(res);
}
#endif
/*
* winsize.c - illumos/Solaris compatible version for notty (used by dune)
*
* This file replaces vendor/notty/src-unix/native/winsize.c
* in dune to fix compilation on illumos/Solaris where TIOCGWINSZ
* is defined in sys/termios.h rather than sys/ioctl.h.
*
* Apply by copying this file to:
* dune-X.Y.Z/vendor/notty/src-unix/native/winsize.c
*
* For opam's bundled dune-local:
* opam-X.Y.Z/src_ext/dune-local/vendor/notty/src-unix/native/winsize.c
*/
#include <caml/mlvalues.h>
#include <caml/alloc.h>
#include <caml/fail.h>
#ifdef __sun
/* illumos/Solaris: struct winsize and TIOCGWINSZ in termios */
#include <sys/termios.h>
#include <sys/ioctl.h>
#else
#include <sys/ioctl.h>
#endif
#include <unistd.h>
#include <signal.h>
CAMLprim value caml_notty_winsize (value fd) {
#ifdef TIOCGWINSZ
struct winsize w;
if (ioctl(Int_val(fd), TIOCGWINSZ, &w) == -1)
caml_failwith("ioctl");
value res = caml_alloc_small(2, 0);
Field(res, 0) = Val_int(w.ws_col);
Field(res, 1) = Val_int(w.ws_row);
return res;
#else
/* Fallback: return default 80x24 */
value res = caml_alloc_small(2, 0);
Field(res, 0) = Val_int(80);
Field(res, 1) = Val_int(24);
return res;
#endif
}
/* Return SIGWINCH signal number */
CAMLprim value caml_notty_winch_number (value unit) {
#ifdef SIGWINCH
return Val_int(SIGWINCH);
#else
return Val_int(0);
#endif
}
|