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

Merged
merged 92 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
f4889ff
Add -Wl,--start-group & -Wl,--end-group
dinosaure Jan 9, 2023
1cc70f5
Delete the usage of `sed -i` (and replace it by `sed && mv`)
dinosaure Jan 9, 2023
8362154
Specify the architecture into the OCaml's `./configure` script
dinosaure Jan 9, 2023
1b2c843
Add $$PTHREAD_LIB into our pattern to modify nativecclibs
dinosaure Jan 9, 2023
ce907ab
Add runtime/primitives as a dependency for the coldstart rule
dinosaure Jan 9, 2023
6608b71
ocamlrun{,d,i} are located into the runtime directory
dinosaure Jan 9, 2023
ed0de9c
Delete fake libcamlrun{,d,i}.a from the Makefile
dinosaure Jan 9, 2023
9c2f41c
/runtime/Makefile was deleted (OCaml 5.0) and everything is into /Mak…
dinosaure Jan 11, 2023
de5d463
Replace ocamlyacc by $$(ocamlyacc_PROGRAM)
dinosaure Jan 9, 2023
56b290c
Replace the number of domains into our OCaml runtime
dinosaure Jan 9, 2023
4da6450
Disable debug runtime
dinosaure Jan 9, 2023
538f85d
Delete unecessary tweak Makefile rule about objinfo_helper
dinosaure Jan 11, 2023
1b0805c
Add a missing / into our nolibc's test-include/%.c rule
dinosaure Jan 9, 2023
10e754d
Add the -p option when we use mkdir (nolibc's Makefile)
dinosaure Jan 9, 2023
c43b971
Set NATIVE_COMPILER to true into the OCaml's Makefile.config
dinosaure Jan 9, 2023
4789bb5
Add test-include/sys/ as a dependency for test-headers (nolibc's Make…
dinosaure Jan 9, 2023
f144077
Define EBUSY
dinosaure Jan 9, 2023
1043ac4
Define O_RDWR
dinosaure Jan 9, 2023
32be082
Define SIG_BLOCK/SIG_SETMASK
dinosaure Jan 9, 2023
8fdcbe4
Define S_{IR,IW}USR
dinosaure Jan 11, 2023
2988ad0
Stub pthread
dinosaure Jan 9, 2023
073292a
Stub sigfillset
dinosaure Jan 9, 2023
7ee377e
Stub fputs, fopen and fclose and implement puts and putchar
dinosaure Jan 13, 2023
cc4f678
Stub strerror_r
dinosaure Jan 11, 2023
d3375f1
Stub ftruncate
dinosaure Jan 11, 2023
951c515
Stub usleep
dinosaure Jan 11, 2023
1fe160e
Export stdrup & strcpy
dinosaure Jan 11, 2023
9016f67
Export qsort and mktemp
dinosaure Jan 9, 2023
5f85f2d
Export fstat
dinosaure Jan 11, 2023
1963e91
Export islanum and tolower
dinosaure Jan 9, 2023
ed00538
Add longjmp & setjmp
dinosaure Jan 9, 2023
68db347
Add the sched.h interface (and the CPU_ZERO value)
dinosaure Jan 9, 2023
e2211c8
Add the stdatomic.h
dinosaure Jan 11, 2023
a1da187
Add sysconf.c (to let OCaml to know the _SC_PAGE{,_}SIZE)
dinosaure Jan 13, 2023
2f1a148
Add the mmap() function
dinosaure Jan 13, 2023
2747702
Initialise the Thread Local Store
dinosaure Jan 11, 2023
64ca6ae
Upgrade ocaml-solo5 with OCaml 5.0
dinosaure Jan 11, 2023
d4ba60e
Upgrade GitHub workflow and Cirrus CI with OCaml 5.0
dinosaure Jan 11, 2023
ee81a3b
Use __c11 atomic macros when they are available (and fix the LLVM sup…
dinosaure Jan 19, 2023
573a10f
Update to the new Solo5 API.
palainp Feb 7, 2023
eac32c7
minor change to trigger CI
hannesm May 19, 2023
c8824a0
use linux defines constants
palainp Oct 18, 2023
d3225a7
bump solo5 version
palainp Oct 18, 2023
8d8acc3
explicit conversion from size_t to int
palainp Oct 18, 2023
cf39fcd
add munmap
palainp Oct 18, 2023
2b447f1
bump ocaml version
palainp Oct 18, 2023
3910f94
fix mmap and munmap
palainp Oct 18, 2023
b352cce
add CHAR_BIT
palainp Oct 18, 2023
9815146
relax alignment with mmap when addr is not NULL
palainp Nov 20, 2023
ca9424c
Stub `sigwait`
shym Feb 26, 2024
673bc45
Stub `execv`
shym Feb 28, 2024
b77517a
Define `static_assert`
shym Feb 27, 2024
1f2181c
Define `strnlen`
shym Feb 27, 2024
03d8517
Define some extra `errno` values
shym Feb 27, 2024
9469b19
Use the compiler-provided `stdatomic.h`
shym Feb 27, 2024
295bf17
Do not rebuild `nolibc.a` when nothing changed
shym Mar 28, 2024
7bce94a
Trim down `configure.sh` and adapt Makefiles
shym Mar 26, 2024
5b97aa7
Clean up typos in `configure.sh`
shym Apr 4, 2024
f63f9cd
Add a `sysroot` configuration option
shym Apr 5, 2024
5b830b3
Create a OCaml/Solo5-specific cross toolchain
shym Apr 4, 2024
0990c75
Define __BSD_VISIBLE and __XSI_VISIBLE when compiling C files
shym Apr 4, 2024
3180b5d
Disable a Clang warning
shym Apr 16, 2024
27cd5f0
Clean up options to build libraries
shym Apr 4, 2024
060a037
Use OCaml's cross-compiler-aware configure and make
shym Apr 4, 2024
02af862
Remove workaround for #101
shym Apr 4, 2024
a68c856
Generate `solo5.conf` with available .opt programs
shym Mar 28, 2024
dbcf5b4
Update {,dist}clean targets
shym Apr 4, 2024
19a53b9
Update the dependencies of the `all` target
shym Apr 4, 2024
8138dbe
Add a `test` rule
shym Apr 4, 2024
1eb5f34
Split up the declaration of phoniness of targets
shym Apr 5, 2024
73169a7
Add a rule to build an empty file to use as `META`
shym Apr 4, 2024
3f9e11d
Generate an OPAM .install file
shym Apr 4, 2024
039aa27
Use opam-installer for the install target
shym Mar 29, 2024
87cfda7
Drop ocaml-option-nnp, not available in OCaml 5+, from .opam
shym Mar 26, 2024
4c5a2f1
Update the rules and dependencies of the OPAM packages
shym Apr 5, 2024
e12bfe9
OPAM package: Depend on the 5.2.1 OCaml compiler
shym Apr 5, 2024
5d6265f
Add patches for OCaml 5.2.1
shym Nov 26, 2024
d4bd77f
Update the compiler version in CI to 5.2.1
shym Apr 5, 2024
9d3546e
Use an order-only dependency for nolibc test directory
shym Apr 9, 2024
f556216
Update comments in nolibc' `signal.h`
shym Apr 9, 2024
3386f83
Ignore `sigfillset`
shym Apr 12, 2024
a8e1f38
Change pthread_create stub to report a failure to create
shym Apr 16, 2024
c799c92
Ensure that library dependencies work across Makefiles
shym Apr 16, 2024
7e11c3f
Handle `mmap(addr..., MAP_FIXED, ...)` uses
shym May 6, 2024
19735eb
Reformulate two comments in `mmap`
shym May 6, 2024
030a379
specify the source for constants macros
palainp Nov 22, 2024
a47d306
Define `strerror_r` using OpenBSD `sys_errlist`
shym Nov 25, 2024
856dade
Drop `strdup`
shym Nov 25, 2024
e5071c3
Add a SOLO5TEST variable to have multiple examples
shym Nov 25, 2024
33f75cc
Add an example test that intentionnally fails
shym Nov 25, 2024
6ed3901
Run the sysfail example in CI
shym Nov 25, 2024
75631e1
Update the supported compiler version to 5.2.1 in README
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
4 changes: 1 addition & 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 Down
7 changes: 6 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 @@ -23,6 +23,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
270 changes: 158 additions & 112 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,135 +1,181 @@
.PHONY: all clean install 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 `ocamlfind query 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) $<

.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)"
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ Run: `solo5-hvt _build/solo5/main.exe`

## Supported compiler versions

Tested against OCaml 4.12.1 through 4.14.1. Other versions may require
changing `configure.sh`.
Tested against OCaml 5.2.1. Other versions would require specific patches (see
the `patches` directory).

## Porting to a different (uni)kernel base layer

Expand Down
Loading