Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support OCaml 5.2 #134

Open
wants to merge 94 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
29c00c1
Add -Wl,--start-group & -Wl,--end-group
dinosaure Jan 9, 2023
e9d913e
Delete the usage of `sed -i` (and replace it by `sed && mv`)
dinosaure Jan 9, 2023
98e4758
Specify the architecture into the OCaml's `./configure` script
dinosaure Jan 9, 2023
d05bbac
Add $$PTHREAD_LIB into our pattern to modify nativecclibs
dinosaure Jan 9, 2023
07238eb
Add runtime/primitives as a dependency for the coldstart rule
dinosaure Jan 9, 2023
644739f
ocamlrun{,d,i} are located into the runtime directory
dinosaure Jan 9, 2023
02a476b
Delete fake libcamlrun{,d,i}.a from the Makefile
dinosaure Jan 9, 2023
c993540
/runtime/Makefile was deleted (OCaml 5.0) and everything is into /Mak…
dinosaure Jan 11, 2023
2198725
Replace ocamlyacc by $$(ocamlyacc_PROGRAM)
dinosaure Jan 9, 2023
bccd114
Replace the number of domains into our OCaml runtime
dinosaure Jan 9, 2023
432adb0
Disable debug runtime
dinosaure Jan 9, 2023
56e3fb5
Delete unecessary tweak Makefile rule about objinfo_helper
dinosaure Jan 11, 2023
4e5e5b9
Add a missing / into our nolibc's test-include/%.c rule
dinosaure Jan 9, 2023
99a5773
Add the -p option when we use mkdir (nolibc's Makefile)
dinosaure Jan 9, 2023
65e3f5f
Set NATIVE_COMPILER to true into the OCaml's Makefile.config
dinosaure Jan 9, 2023
488a2b8
Add test-include/sys/ as a dependency for test-headers (nolibc's Make…
dinosaure Jan 9, 2023
8d567df
Define EBUSY
dinosaure Jan 9, 2023
05a8490
Define O_RDWR
dinosaure Jan 9, 2023
8820541
Define SIG_BLOCK/SIG_SETMASK
dinosaure Jan 9, 2023
691fe8a
Define S_{IR,IW}USR
dinosaure Jan 11, 2023
187b70a
Stub pthread
dinosaure Jan 9, 2023
cd18b80
Stub sigfillset
dinosaure Jan 9, 2023
ab12ae0
Stub fputs, fopen and fclose and implement puts and putchar
dinosaure Jan 13, 2023
3c72775
Stub strerror_r
dinosaure Jan 11, 2023
2f65413
Stub ftruncate
dinosaure Jan 11, 2023
8480160
Stub usleep
dinosaure Jan 11, 2023
4f85232
Export stdrup & strcpy
dinosaure Jan 11, 2023
08733e1
Export qsort and mktemp
dinosaure Jan 9, 2023
880b162
Export fstat
dinosaure Jan 11, 2023
f88eb59
Export islanum and tolower
dinosaure Jan 9, 2023
5692066
Add longjmp & setjmp
dinosaure Jan 9, 2023
45cd68a
Add the sched.h interface (and the CPU_ZERO value)
dinosaure Jan 9, 2023
f300741
Add the stdatomic.h
dinosaure Jan 11, 2023
39a345e
Add sysconf.c (to let OCaml to know the _SC_PAGE{,_}SIZE)
dinosaure Jan 13, 2023
888fe5f
Add the mmap() function
dinosaure Jan 13, 2023
1da2cb4
Initialise the Thread Local Store
dinosaure Jan 11, 2023
9e43136
Upgrade ocaml-solo5 with OCaml 5.0
dinosaure Jan 11, 2023
a56e3fc
Upgrade GitHub workflow and Cirrus CI with OCaml 5.0
dinosaure Jan 11, 2023
f9e2a5e
Use __c11 atomic macros when they are available (and fix the LLVM sup…
dinosaure Jan 19, 2023
0e4b0af
Update to the new Solo5 API.
palainp Feb 7, 2023
61be221
minor change to trigger CI
hannesm May 19, 2023
ba4d715
use linux defines constants
palainp Oct 18, 2023
5c6d799
bump solo5 version
palainp Oct 18, 2023
83af258
explicit conversion from size_t to int
palainp Oct 18, 2023
6484f7f
add munmap
palainp Oct 18, 2023
e588baa
bump ocaml version
palainp Oct 18, 2023
6e8a52f
fix mmap and munmap
palainp Oct 18, 2023
6f07102
add CHAR_BIT
palainp Oct 18, 2023
37a801b
relax alignment with mmap when addr is not NULL
palainp Nov 20, 2023
43090c8
Stub `sigwait`
shym Feb 26, 2024
47d9fc8
Stub `execv`
shym Feb 28, 2024
b236359
Define `static_assert`
shym Feb 27, 2024
4c36d2e
Define `strnlen`
shym Feb 27, 2024
6519ea3
Define some extra `errno` values
shym Feb 27, 2024
7409a98
Use the compiler-provided `stdatomic.h`
shym Feb 27, 2024
aca0bcb
Do not rebuild `nolibc.a` when nothing changed
shym Mar 28, 2024
14ad422
Trim down `configure.sh` and adapt Makefiles
shym Mar 26, 2024
44e322a
Clean up typos in `configure.sh`
shym Apr 4, 2024
da5847d
Add a `sysroot` configuration option
shym Apr 5, 2024
1a824f5
Create a OCaml/Solo5-specific cross toolchain
shym Apr 4, 2024
a32c459
Define __BSD_VISIBLE and __XSI_VISIBLE when compiling C files
shym Apr 4, 2024
cbe8d87
Disable a Clang warning
shym Apr 16, 2024
e16d76a
Clean up options to build libraries
shym Apr 4, 2024
5037b9d
Use OCaml's cross-compiler-aware configure and make
shym Apr 4, 2024
fca6e03
Remove workaround for #101
shym Apr 4, 2024
65f0bd2
Generate `solo5.conf` with available .opt programs
shym Mar 28, 2024
222f81f
Update {,dist}clean targets
shym Apr 4, 2024
c8ea625
Update the dependencies of the `all` target
shym Apr 4, 2024
1881de8
Add a `test` rule
shym Apr 4, 2024
b49efc5
Split up the declaration of phoniness of targets
shym Apr 5, 2024
53de3c9
Add a rule to build an empty file to use as `META`
shym Apr 4, 2024
fa35d71
Generate an OPAM .install file
shym Apr 4, 2024
8a1c310
Use opam-installer for the install and uninstall targets
shym Mar 29, 2024
0b19a07
Drop ocaml-option-nnp, not available in OCaml 5+, from .opam
shym Mar 26, 2024
ec7da20
Update the rules and dependencies of the OPAM packages
shym Apr 5, 2024
7c3c044
WIP OPAM package: Depend on the 5.2.x OCaml compiler
shym Apr 5, 2024
ba106f9
DROPME Add patches for 5.2.0
shym Apr 17, 2024
53eedc4
Add patches for OCaml 5.2.1
shym Nov 26, 2024
2bd43c5
Update the compiler version in CI to 5.2.1
shym Apr 5, 2024
f9e94fc
Use an order-only dependency for nolibc test directory
shym Apr 9, 2024
84fc994
Update comments in nolibc' `signal.h`
shym Apr 9, 2024
42b3f0d
Ignore `sigfillset`
shym Apr 12, 2024
9f298ac
Change pthread_create stub to report a failure to create
shym Apr 16, 2024
dd61f3d
Ensure that library dependencies work across Makefiles
shym Apr 16, 2024
3274a9a
Handle `mmap(addr..., MAP_FIXED, ...)` uses
shym May 6, 2024
07d9f35
Reformulate two comments in `mmap`
shym May 6, 2024
893e12d
specify the source for constants macros
palainp Nov 22, 2024
9cd964b
Define `strerror_r` using OpenBSD `sys_errlist`
shym Nov 25, 2024
3cd5108
Drop `strdup`
shym Nov 25, 2024
f688a59
Add a SOLO5TEST variable to have multiple examples
shym Nov 25, 2024
90c2094
Add an example test that intentionnally fails
shym Nov 25, 2024
d106864
Run the sysfail example in CI
shym Nov 25, 2024
453abc9
Update the supported compiler version to 5.2.1 in README
shym Nov 26, 2024
75f9acf
DROPME Add a temporary ocaml-src.5.2.1 package
shym Nov 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ freebsd_task:
OPAMYES: 1
env:
matrix:
- OCAML_VERSION: 4.12.1
- OCAML_VERSION: 4.13.1
- OCAML_VERSION: 4.14.2
- OCAML_VERSION: 5.2.1
pkg_install_script: pkg install -y ocaml-opam gmp gmake pkgconf bash
opam_ocaml_cache:
folder: $HOME/.opam
Expand All @@ -19,6 +17,7 @@ freebsd_task:
populate_script:
- opam init -a --comp=$OCAML_VERSION
setup_script:
- OPAMEDITOR="cp ocaml-src.xpam" opam pin add -eyn ocaml-src - < /dev/null
- opam update
- opam install dune
- opam pin add -n -t .
Expand Down
10 changes: 9 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ jobs:
test:
strategy:
matrix:
ocaml-compiler: ["4.12", "4.13", "4.14"]
ocaml-compiler: [5.2.1]
name: OCaml ${{ matrix.ocaml-compiler }}
runs-on: ubuntu-latest
steps:
Expand All @@ -15,6 +15,9 @@ jobs:
opam-local-packages: |
*.opam
!ocaml-solo5-cross-aarch64.opam
- name: Create an overlay for ocaml-src
run: |
OPAMEDITOR="cp ocaml-src.xpam" opam pin add -eyn ocaml-src - < /dev/null
- name: Install ocaml-solo5 and dune
run: opam install ocaml-solo5 conf-libseccomp dune
- name: Compile example with hvt
Expand All @@ -23,6 +26,11 @@ jobs:
run: MODE=spt opam exec -- dune build --root example
- name: Run example with spt
run: opam exec -- solo5-spt example/_build/solo5/main.exe
- name: Compile a failing example with spt
run: MODE=spt SOLO5TEST=sysfail opam exec -- dune build --root example
- name: Run a failing example with spt
run: |
! opam exec -- solo5-spt example/_build/solo5/main.exe
- name: Compile example with virtio
run: MODE=virtio opam exec -- dune build --root example
- name: Compile example with muen
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ nolibc/*.a
nolibc/test-include/
ocaml/
_build/
/ocaml-src.tar.gz
/*.install
32 changes: 32 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,38 @@ SUCH DAMAGE.

----------------------------------------------------------------------

The file errlist.c in the nolibc/ directory is derived from OpenBSD,
licensed under the following BSD license:

Copyright (c) 1982, 1985, 1993
The Regents of the University of California. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the University nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.

----------------------------------------------------------------------

The file dtoa.c in the nolibc/ directory is licensed under the following
MIT license:

Expand Down
275 changes: 161 additions & 114 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,138 +1,185 @@
.PHONY: all clean install uninstall distclean ocaml

include Makeconf

all: openlibm/libopenlibm.a nolibc/libnolibc.a ocaml solo5.conf
# The `all` target is moved to the end to use variables in its dependencies
.PHONY: default
default: all

TOP=$(abspath .)

# CFLAGS used to build nolibc / openlibm / ocaml runtime
LOCAL_CFLAGS=$(MAKECONF_CFLAGS) -I$(TOP)/nolibc/include -include _solo5/overrides.h
# CFLAGS used by the OCaml compiler to build C stubs
GLOBAL_CFLAGS=$(MAKECONF_CFLAGS) -I$(MAKECONF_PREFIX)/solo5-sysroot/include/nolibc/ -include _solo5/overrides.h
# LIBS used by the OCaml compiler to link executables
GLOBAL_LIBS=-L$(MAKECONF_PREFIX)/solo5-sysroot/lib/nolibc/ -lnolibc -lopenlibm $(MAKECONF_EXTRA_LIBS)
# Most parts (OCaml, nolibc, openlibm) currently build their result in-tree but
# we reuse dune's `_build` dir, as familiar and already usable for `example`,
# etc., for some generated files
_build:
mkdir -p $@

LIBS := openlibm/libopenlibm.a nolibc/libnolibc.a

# CFLAGS used to build the nolibc and openlibm libraries
LIB_CFLAGS=-I$(TOP)/nolibc/include -include _solo5/overrides.h

# NOLIBC
NOLIBC_CFLAGS=$(LOCAL_CFLAGS) -I$(TOP)/openlibm/src -I$(TOP)/openlibm/include
nolibc/libnolibc.a:
$(MAKE) -C nolibc \
"CC=$(MAKECONF_CC)" \
"FREESTANDING_CFLAGS=$(NOLIBC_CFLAGS)" \
"SYSDEP_OBJS=$(MAKECONF_NOLIBC_SYSDEP_OBJS)"
# Use a phony target indirection, so that nolibc/Makefile is always checked to
# see whether the library should be rebuilt while avoiding useless rebuild if
# nolibc/libnolibc.a was up-to-date
NOLIBC_CFLAGS=$(LIB_CFLAGS) -I$(TOP)/openlibm/src -I$(TOP)/openlibm/include
nolibc/libnolibc.a: phony-nolibc

.PHONY: phony-nolibc
phony-nolibc:
$(MAKE) -C nolibc libnolibc.a \
"CC=$(MAKECONF_TOOLCHAIN)-cc" \
"FREESTANDING_CFLAGS=$(NOLIBC_CFLAGS)"

# OPENLIBM
openlibm/libopenlibm.a:
$(MAKE) -C openlibm "CC=$(MAKECONF_CC)" "CPPFLAGS=$(LOCAL_CFLAGS)" libopenlibm.a
# See NOLIBC for explanations of the phony target
openlibm/libopenlibm.a: phony-openlibm

.PHONY: phony-openlibm
phony-openlibm:
$(MAKE) -C openlibm libopenlibm.a \
"CC=$(MAKECONF_TOOLCHAIN)-cc" \
"CPPFLAGS=$(LIB_CFLAGS)"

# TOOLCHAIN
# We create prefix-gcc even when the actual compiler will be Clang because
# autoconf toolchain detection will pick the first compiler that exists in the
# list: prefix-gcc, gcc, prefix-cc, cc...
# Anyway, configure scripts always explicitly test whether the compiler defines
# Clang-specific macros when they want to distinguish GCC and Clang
ALLTOOLS := gcc cc ar as ld nm objcopy objdump ranlib readelf strip
ALLTOOLS := $(foreach tool,$(ALLTOOLS), \
$(MAKECONF_TARGET_ARCH)-solo5-ocaml-$(tool))

TOOLDIR_FOR_BUILD := _build/build-toolchain
TOOLCHAIN_FOR_BUILD := $(addprefix $(TOOLDIR_FOR_BUILD)/,$(ALLTOOLS))
TOOLDIR_FINAL := _build/toolchain
TOOLCHAIN_FINAL := $(addprefix $(TOOLDIR_FINAL)/,$(ALLTOOLS))

# Options for the build version of the tools
TOOLCHAIN_BUILD_CFLAGS := -I$(TOP)/nolibc/include \
-I$(TOP)/openlibm/include -I$(TOP)/openlibm/src
TOOLCHAIN_BUILD_LDFLAGS := -L$(TOP)/nolibc -L$(TOP)/openlibm

# Options for the installed version of the tools
TOOLCHAIN_FINAL_CFLAGS := -I$(MAKECONF_SYSROOT)/include
TOOLCHAIN_FINAL_LDFLAGS := -L$(MAKECONF_SYSROOT)/lib

$(TOOLDIR_FOR_BUILD) $(TOOLDIR_FINAL):
mkdir -p $@

$(TOOLDIR_FOR_BUILD)/$(MAKECONF_TARGET_ARCH)-solo5-ocaml-%: \
gen_toolchain_tool.sh | $(TOOLDIR_FOR_BUILD)
ARCH="$(MAKECONF_TARGET_ARCH)" \
SOLO5_TOOLCHAIN="$(MAKECONF_TOOLCHAIN)" \
OTHERTOOLPREFIX="$(MAKECONF_TOOLPREFIX)" \
TOOL_CFLAGS="$(TOOLCHAIN_BUILD_CFLAGS)" \
TOOL_LDFLAGS="$(TOOLCHAIN_BUILD_LDFLAGS)" \
sh $< $* > $@
chmod +x $@

$(TOOLDIR_FINAL)/$(MAKECONF_TARGET_ARCH)-solo5-ocaml-%: \
gen_toolchain_tool.sh | $(TOOLDIR_FINAL)
ARCH="$(MAKECONF_TARGET_ARCH)" \
SOLO5_TOOLCHAIN="$(MAKECONF_TOOLCHAIN)" \
OTHERTOOLPREFIX="$(MAKECONF_TOOLPREFIX)" \
TOOL_CFLAGS="$(TOOLCHAIN_FINAL_CFLAGS)" \
TOOL_LDFLAGS="$(TOOLCHAIN_FINAL_LDFLAGS)" \
sh $< $* > $@
chmod +x $@

.PHONY: toolchains
toolchains: $(TOOLCHAIN_FOR_BUILD) $(TOOLCHAIN_FINAL)

# OCAML
ocaml/Makefile:
cp -r `opam var prefix`/lib/ocaml-src ./ocaml

# OCaml >= 4.08.0 uses an autotools-based build system. In this case we
# convince it to think it's using the Solo5 compiler as a cross compiler, and
# let the build system do its work with as little additional changes on our
# side as possible.
#
# Notes:
#
# - CPPFLAGS must be set for configure as well as CC, otherwise it complains
# about headers due to differences of opinion between the preprocessor and
# compiler.
# - ARCH must be overridden manually in Makefile.config due to the use of
# hardcoded combinations in the OCaml configure.
# - We use LIBS with a stubbed out solo5 implementation to override the OCaml
# configure link test
# - We override OCAML_OS_TYPE since configure just hardcodes it to "Unix".
OC_CFLAGS=$(LOCAL_CFLAGS) -I$(TOP)/openlibm/include -I$(TOP)/openlibm/src -nostdlib
OC_LIBS=-L$(TOP)/nolibc -lnolibc -L$(TOP)/openlibm -lopenlibm -nostdlib $(MAKECONF_EXTRA_LIBS)
ocaml/Makefile.config: ocaml/Makefile openlibm/libopenlibm.a nolibc/libnolibc.a
# configure: Do not build dynlink
sed -i -e 's/otherlibraries="dynlink"/otherlibraries=""/g' ocaml/configure
# configure: Allow precise input of flags and libs
sed -i -e 's/oc_cflags="/oc_cflags="$$OC_CFLAGS /g' ocaml/configure
sed -i -e 's/ocamlc_cflags="/ocamlc_cflags="$$OCAMLC_CFLAGS /g' ocaml/configure
sed -i -e 's/nativecclibs="$$cclibs $$DLLIBS"/nativecclibs="$$GLOBAL_LIBS"/g' ocaml/configure
# runtime/Makefile: Runtime rules: don't build libcamlrun.a and import ocamlrun from the system
sed -i -e 's/^all: $$(BYTECODE_STATIC_LIBRARIES) $$(BYTECODE_SHARED_LIBRARIES)/all: primitives ld.conf/' ocaml/runtime/Makefile
sed -i -e 's/^ocamlrun$$(EXE):.*/dummy:/g' ocaml/runtime/Makefile
sed -i -e 's/^ocamlruni$$(EXE):.*/dummyi:/g' ocaml/runtime/Makefile
sed -i -e 's/^ocamlrund$$(EXE):.*/dummyd:/g' ocaml/runtime/Makefile
echo -e "ocamlrun:\n\tcp $(shell which ocamlrun) .\n" >> ocaml/runtime/Makefile
echo -e "ocamlrund:\n\tcp $(shell which ocamlrund) .\n" >> ocaml/runtime/Makefile
echo -e "ocamlruni:\n\tcp $(shell which ocamlruni) .\n" >> ocaml/runtime/Makefile
touch ocaml/runtime/libcamlrun.a ocaml/runtime/libcamlrund.a ocaml/runtime/libcamlruni.a
# yacc/Makefile: import ocamlyacc from the system
sed -i -e 's/^ocamlyacc$$(EXE):.*/dummy:/g' ocaml/yacc/Makefile
echo -e "ocamlyacc:\n\tcp $(shell which ocamlyacc) .\n" >> ocaml/yacc/Makefile
# tools/Makefile: stub out objinfo_helper
echo -e "objinfo_helper:\n\ttouch objinfo_helper\n" >> ocaml/tools/Makefile
# av_cv_libm_cos=no is passed to configure to prevent -lm being used (which
# would use the host system libm instead of the freestanding openlibm, see
# https://github.com/mirage/ocaml-solo5/issues/101
# Extract sources from the ocaml-src package and apply patches if there any in
# `patches/<OCaml version>/`
ocaml:
# First make sure the ocaml directory doesn't exist, otherwise the cp would
# create an ocaml-src subdirectory
test ! -d $@
cp -r "$$(ocamlfind query ocaml-src)" $@
VERSION="$$(head -n1 ocaml/VERSION)" ; \
if test -d "patches/$$VERSION" ; then \
git apply --directory=$@ "patches/$$VERSION"/*; \
fi

ocaml/Makefile.config: $(LIBS) $(TOOLCHAIN_FOR_BUILD) | ocaml
PATH="$$PWD/$(TOOLDIR_FOR_BUILD):$$PATH" ; \
cd ocaml && \
CC="$(MAKECONF_CC)" \
OC_CFLAGS="$(OC_CFLAGS)" \
OCAMLC_CFLAGS="$(GLOBAL_CFLAGS)" \
AS="$(MAKECONF_AS)" \
ASPP="$(MAKECONF_CC) $(OC_CFLAGS) -c" \
CPPFLAGS="$(OC_CFLAGS)" \
LIBS="$(OC_LIBS)"\
GLOBAL_LIBS="$(GLOBAL_LIBS)"\
LD="$(MAKECONF_LD)" \
ac_cv_prog_DIRECT_LD="$(MAKECONF_LD)" \
ac_cv_lib_m_cos="no" \
./configure \
-host=$(MAKECONF_ARCH)-unknown-none \
-target=$(MAKECONF_BUILD_ARCH)-solo5-none \
-prefix $(MAKECONF_PREFIX)/solo5-sysroot \
-disable-shared\
-disable-systhreads\
-disable-unix-lib\
-disable-instrumented-runtime\
-disable-ocamltest\
-disable-ocamldoc\
--target="$(MAKECONF_TARGET_ARCH)-solo5-ocaml" \
--prefix="$(MAKECONF_SYSROOT)" \
--disable-shared \
--disable-systhreads \
--disable-unix-lib \
--disable-instrumented-runtime \
--disable-debug-runtime \
--disable-ocamltest \
--disable-ocamldoc \
--without-zstd \
$(MAKECONF_OCAML_CONFIGURE_OPTIONS)
echo "ARCH=$(MAKECONF_OCAML_BUILD_ARCH)" >> ocaml/Makefile.config
echo 'SAK_CC=cc' >> ocaml/Makefile.config
echo 'SAK_CFLAGS=' >> ocaml/Makefile.config
echo 'SAK_LINK=cc $(SAK_CFLAGS) $$(OUTPUTEXE)$$(1) $$(2)' >> ocaml/Makefile.config
echo '#undef OCAML_OS_TYPE' >> ocaml/runtime/caml/s.h
echo '#define OCAML_OS_TYPE "None"' >> ocaml/runtime/caml/s.h

# NOTE: ocaml/tools/make-version-header.sh is integrated into OCaml's ./configure script starting from OCaml 4.14
ifneq (,$(wildcard ocaml/tools/make-version-header.sh))
ocaml/runtime/caml/version.h: ocaml/Makefile.config
ocaml/tools/make-version-header.sh > $@
else
ocaml/runtime/caml/version.h: ocaml/Makefile.config
@
endif

ocaml: ocaml/Makefile.config ocaml/runtime/caml/version.h
$(MAKE) -C ocaml world
$(MAKE) -C ocaml opt

OCAML_IS_BUILT := _build/ocaml_is_built
$(OCAML_IS_BUILT): ocaml/Makefile.config | _build
PATH="$$PWD/$(TOOLDIR_FOR_BUILD):$$PATH" $(MAKE) -C ocaml cross.opt
cd ocaml && ocamlrun tools/stripdebug ocamlc ocamlc.tmp
cd ocaml && ocamlrun tools/stripdebug ocamlopt ocamlopt.tmp
touch $@

DOT_INSTALL_PREFIX_FOR_OCAML := _build/ocaml.install
DOT_INSTALL_CHUNKS_FOR_OCAML := $(addprefix $(DOT_INSTALL_PREFIX_FOR_OCAML),\
.lib .libexec)
$(DOT_INSTALL_CHUNKS_FOR_OCAML): | ocaml/Makefile.config
MAKE="$(MAKE)" ./gen_ocaml_install.sh \
$(DOT_INSTALL_PREFIX_FOR_OCAML) ocaml $(MAKECONF_SYSROOT)

# CONFIGURATION FILES
solo5.conf: solo5.conf.in
sed -e 's!@@PREFIX@@!$(MAKECONF_PREFIX)!' \
solo5.conf.in > $@
_build/solo5.conf: gen_solo5_conf.sh $(OCAML_IS_BUILT)
SYSROOT="$(MAKECONF_SYSROOT)" ./gen_solo5_conf.sh > $@

_build/empty-META: | _build
touch $@

# INSTALL
PACKAGES := $(basename $(wildcard *.opam))
INSTALL_FILES := $(foreach pkg,$(PACKAGES),$(pkg).install)

$(INSTALL_FILES): $(TOOLCHAIN_FINAL) $(DOT_INSTALL_CHUNKS_FOR_OCAML)
./gen_dot_install.sh $(DOT_INSTALL_PREFIX_FOR_OCAML) $(TOOLCHAIN_FINAL)\
> $@

# COMMANDS
install: all
MAKE=$(MAKE) PREFIX=$(MAKECONF_PREFIX) ./install.sh
PACKAGE := ocaml-solo5
.PHONY: install
install: $(PACKAGE).install
opam-installer --prefix=$(MAKECONF_PREFIX) $<

uninstall:
./uninstall.sh
.PHONY: uninstall
uninstall: $(PACKAGE).install
opam-installer --prefix=$(MAKECONF_PREFIX) --uninstall $<

.PHONY: clean
clean:
$(RM) -r ocaml/
$(RM) solo5.conf
$(RM) -rf _build
$(MAKE) -C openlibm clean
$(MAKE) -C nolibc \
"FREESTANDING_CFLAGS=$(NOLIBC_CFLAGS)" \
"SYSDEP_OBJS=$(MAKECONF_NOLIBC_SYSDEP_OBJS)" \
clean
$(MAKE) -C nolibc clean FREESTANDING_CFLAGS=_
if [ -d ocaml ] ; then $(MAKE) -C ocaml clean ; fi
shym marked this conversation as resolved.
Show resolved Hide resolved
$(RM) -f $(INSTALL_FILES)

.PHONY: distclean
distclean: clean
rm Makeconf
$(RM) -f Makeconf
# Don't remove the ocaml directory itself, to play nicer with
# development in there
if [ -d ocaml ] ; then $(MAKE) -C ocaml distclean ; fi
shym marked this conversation as resolved.
Show resolved Hide resolved

.PHONY: all
all: $(LIBS) $(OCAML_IS_BUILT) \
_build/solo5.conf _build/empty-META \
$(TOOLCHAIN_FINAL)

.PHONY: test
test:
$(MAKE) -C nolibc test-headers \
"CC=$(MAKECONF_TOOLCHAIN)-cc" \
"FREESTANDING_CFLAGS=$(NOLIBC_CFLAGS)"
Loading