Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions .depend
Original file line number Diff line number Diff line change
Expand Up @@ -4189,6 +4189,7 @@ middle_end/closure/closure.cmo : \
typing/env.cmi \
lambda/debuginfo.cmi \
middle_end/convert_primitives.cmi \
utils/config.cmi \
middle_end/compilenv.cmi \
utils/clflags.cmi \
middle_end/clambda_primitives.cmi \
Expand All @@ -4211,6 +4212,7 @@ middle_end/closure/closure.cmx : \
typing/env.cmx \
lambda/debuginfo.cmx \
middle_end/convert_primitives.cmx \
utils/config.cmx \
middle_end/compilenv.cmx \
utils/clflags.cmx \
middle_end/clambda_primitives.cmx \
Expand Down
14 changes: 9 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1284,11 +1284,10 @@ runtime/caml/jumptbl.h : runtime/caml/instruct.h
sed -n -e '/^ /s/ \([A-Z]\)/ \&\&lbl_\1/gp' \
-e '/^}/q' > $@

# These are provided as a temporary shim to allow cross-compilation systems
# to supply a host C compiler and different flags and a linking macro.
SAK_CC ?= $(CC)
SAK_CFLAGS ?= $(OC_CFLAGS) $(CFLAGS) $(OC_CPPFLAGS) $(CPPFLAGS)
SAK_LINK ?= $(MKEXE_VIA_CC)
SAK_CC ?= $(CC_FOR_BUILD)
SAK_CFLAGS ?=\
$(OC_CFLAGS) $(CFLAGS_FOR_BUILD) $(OC_CPPFLAGS) $(CPPFLAGS_FOR_BUILD)
SAK_LINK ?= $(SAK_CC) $(SAK_CFLAGS) $(OUTPUTEXE)$(1) $(2)

$(SAK): runtime/sak.$(O)
$(V_MKEXE)$(call SAK_LINK,$@,$^)
Expand Down Expand Up @@ -2733,6 +2732,11 @@ endif

include .depend

# Include the cross-compiler recipes only when relevant
ifneq "$(HOST)" "$(TARGET)"
include Makefile.cross
endif

Makefile.config Makefile.build_config: config.status
config.status:
@echo "Please refer to the installation instructions:"
Expand Down
5 changes: 5 additions & 0 deletions Makefile.config.in
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,13 @@ LIBTOOL = $(TOP_BUILDDIR)/libtool
### Which C compiler to use
TOOLPREF=@ac_tool_prefix@
CC=@CC@
CC_FOR_BUILD=@CC_FOR_BUILD@

CC_HAS_DEBUG_PREFIX_MAP=@cc_has_debug_prefix_map@
AS_HAS_DEBUG_PREFIX_MAP=@as_has_debug_prefix_map@

LDFLAGS?=@LDFLAGS@
LDFLAGS_FOR_BUILD=@LDFLAGS_FOR_BUILD@

### How to invoke the C preprocessor through the C compiler
CPP=@CPP@
Expand Down Expand Up @@ -160,7 +162,9 @@ UNIX_OR_WIN32=@unix_or_win32@
INSTALL_SOURCE_ARTIFACTS=@install_source_artifacts@

CFLAGS=@CFLAGS@
CFLAGS_FOR_BUILD=@CFLAGS_FOR_BUILD@
CPPFLAGS=@CPPFLAGS@
CPPFLAGS_FOR_BUILD=@CPPFLAGS_FOR_BUILD@
OCAMLC_CFLAGS=@ocamlc_cflags@

OCAMLC_CPPFLAGS=@ocamlc_cppflags@
Expand All @@ -181,6 +185,7 @@ OCAMLOPT_CFLAGS=@ocamlc_cflags@
OCAMLOPT_CPPFLAGS=@ocamlc_cppflags@
NATIVECCLIBS=@cclibs@
SYSTHREAD_SUPPORT=@systhread_support@
STRIP=@STRIP@
PACKLD=@PACKLD@$(EMPTY)
CCOMPTYPE=@ccomptype@
TOOLCHAIN=@toolchain@
Expand Down
83 changes: 83 additions & 0 deletions Makefile.cross
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#**************************************************************************
#* *
#* OCaml *
#* *
#* Samuel Hym, Tarides *
#* *
#* Copyright 2024 Tarides *
#* *
#* All rights reserved. This file is distributed under the terms of *
#* the GNU Lesser General Public License version 2.1, with the *
#* special exception on linking described in the file LICENSE. *
#* *
#**************************************************************************

# Recipes to build a cross-compiler (_not_ cross-compiling the compiler), aka
# generating code that will run on `target`, assuming that a non-cross OCaml
# compiler (so targetting our build machine) of the same version is available in
# $PATH

# We assume no zstd for the cross-compiler (ie no requirement on zstd for the
# target)
# Still the cross-compiler will run on host, not target. And as a consequence of
# the rules linking it, the cross-compilers will be linked with the _build_
# version of libcomprmarsh, so we still must discover the flags to link with
# libzstd if it was set up in the non-cross compiler, so we rely on the
# pkg-config command to get the linking flags for zstd
PKG_CONFIG := pkg-config
# This is used only once, so it doesn't have to be much lazier
NATIVE_ZSTD_LIBS=ZSTD_LIBS="$(shell $(PKG_CONFIG) --libs libzstd)"
# As the libcomprmarsh built by the C cross compiler will not be linked in, we
# can build an empty one
NO_ZSTD=libcomprmarsh_OBJECTS=

CROSS_OVERRIDES=OCAMLRUN=ocamlrun NEW_OCAMLRUN=ocamlrun \
BOOT_OCAMLLEX=ocamllex OCAMLYACC=ocamlyacc
CROSS_COMPILER_OVERRIDES=$(CROSS_OVERRIDES) CAMLC=ocamlc CAMLOPT=ocamlopt \
BEST_OCAMLC=ocamlc BEST_OCAMLOPT=ocamlopt BEST_OCAMLLEX=ocamllex

INSTALL_OVERRIDES=build_ocamldoc=false WITH_DEBUGGER=

# Freestanding target custom options
ifeq "$(SYSTEM)" "none"
RUNTIME_BUILD_OVERRIDES=runtime_PROGRAMS=
INSTALL_OVERRIDES += runtime_PROGRAMS=`which ocamlrun` \
runtime_BYTECODE_STATIC_LIBRARIES=runtime/ld.conf
else
RUNTIME_BUILD_OVERRIDES=
endif

cross.opt:
$(MAKE) runtime-all $(NO_ZSTD) $(RUNTIME_BUILD_OVERRIDES)
$(MAKE) ocamlc ocamlopt $(TOOLS_BYTECODE_TARGETS) expunge \
$(CROSS_COMPILER_OVERRIDES)
$(MAKE) library $(CROSS_OVERRIDES)
ifneq "$(SYSTEM)" "none"
$(MAKE) ocamlyacc $(CROSS_OVERRIDES)
$(MAKE) ocamllex $(CROSS_COMPILER_OVERRIDES)
endif
$(MAKE) ocaml $(CROSS_COMPILER_OVERRIDES)
$(MAKE) -C otherlibs all $(CROSS_OVERRIDES)
# Opt
$(MAKE) runtimeopt $(NO_ZSTD)
$(MAKE) ocamlc.opt ocamlopt.opt $(TOOLS_NATIVE_TARGETS) \
$(NO_ZSTD) $(CROSS_COMPILER_OVERRIDES) $(NATIVE_ZSTD_LIBS)
$(MAKE) libraryopt $(NO_ZSTD) $(CROSS_OVERRIDES)
$(MAKE) otherlibrariesopt ocamltoolsopt $(NO_ZSTD) $(CROSS_OVERRIDES)
$(MAKE) tools-allopt.opt $(NO_ZSTD) $(CROSS_COMPILER_OVERRIDES)

.PHONY: cross-install
cross-install:
# dummy files
touch \
$(addprefix toplevel/, \
$(foreach ext,cmi cmt cmti cmx, native/nat__dummy__.$(ext)) \
all__dummy__.cmx topstart.o native/tophooks.cmi)
$(LN) `which ocamlyacc` yacc/ocamlyacc.opt$(EXE)
$(LN) `which ocamllex` lex/ocamllex.opt$(EXE)
ifeq "$(SYSTEM)" "none"
$(LN) `which ocamlyacc` yacc/ocamlyacc$(EXE)
$(LN) `which ocamllex` lex/ocamllex$(EXE)
endif
# Real installation
$(MAKE) install $(INSTALL_OVERRIDES) OCAMLRUN=ocamlrun
13 changes: 7 additions & 6 deletions aclocal.m4
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ m4_include([build-aux/ax_check_compile_flag.m4])

# Macros from the autoconf macro archive
m4_include([build-aux/ax_func_which_gethostbyname_r.m4])
m4_include([build-aux/ax_prog_cc_for_build.m4])
m4_include([build-aux/ax_pthread.m4])

# OCaml version
Expand Down Expand Up @@ -414,27 +415,27 @@ EOF
OCAML_CC_RESTORE_VARIABLES
])

AC_DEFUN([OCAML_HOST_IS_EXECUTABLE], [
AC_MSG_CHECKING([whether host executables can be run in the build])
AC_DEFUN([OCAML_TARGET_IS_EXECUTABLE], [
AC_MSG_CHECKING([whether target executables can be run in the build])
old_cross_compiling="$cross_compiling"
cross_compiling='no'
AC_RUN_IFELSE(
[AC_LANG_SOURCE([[int main (void) {return 0;}]])],
[AC_MSG_RESULT([yes])
host_runnable=true],
target_runnable=true],
[AC_MSG_RESULT([no])
host_runnable=false],
target_runnable=false],
# autoconf displays a warning if this parameter is missing, but
# cross-compilation mode was disabled above.
[assert=false])
cross_compiling="$old_cross_compiling"
])

# This is AC_RUN_IFELSE but taking $host_runnable into account (i.e. if the
# This is AC_RUN_IFELSE but taking $target_runnable into account (i.e. if the
# program can be run, then it is run)
AC_DEFUN([OCAML_RUN_IFELSE], [
old_cross_compiling="$cross_compiling"
AS_IF([test "x$host_runnable" = 'xtrue'], [cross_compiling='no'])
AS_IF([test "x$target_runnable" = 'xtrue'], [cross_compiling='no'])
AC_RUN_IFELSE([$1],[$2],[$3],[$4])
cross_compiling="$old_cross_compiling"
])
Expand Down
2 changes: 1 addition & 1 deletion asmcomp/amd64/emit.mlp
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,7 @@ let end_assembly() =
D.size frametable (ConstSub (ConstThis, ConstLabel frametable))
end;

if system = S_linux then
if system = S_linux || system = S_unknown then
(* Mark stack as non-executable, PR#4564 *)
D.section [".note.GNU-stack"] (Some "") [ "%progbits" ];

Expand Down
2 changes: 1 addition & 1 deletion asmcomp/arm64/emit.mlp
Original file line number Diff line number Diff line change
Expand Up @@ -1217,7 +1217,7 @@ let end_assembly () =
emit_symbol_type emit_symbol lbl "object";
emit_symbol_size lbl;
begin match Config.system with
| "linux" ->
| "linux" | "none" ->
(* Mark stack as non-executable *)
` .section .note.GNU-stack,\"\",%progbits\n`
| _ -> ()
Expand Down
2 changes: 2 additions & 0 deletions asmcomp/x86_proc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type system =
| S_freebsd
| S_netbsd
| S_openbsd
| S_none

| S_unknown

Expand All @@ -43,6 +44,7 @@ let system = match Config.system with
| "freebsd" -> S_freebsd
| "netbsd" -> S_netbsd
| "openbsd" -> S_openbsd
| "none" -> S_none

| _ -> S_unknown

Expand Down
1 change: 1 addition & 0 deletions asmcomp/x86_proc.mli
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type system =
| S_freebsd
| S_netbsd
| S_openbsd
| S_none

| S_unknown

Expand Down
Binary file modified boot/ocamlc
Binary file not shown.
155 changes: 155 additions & 0 deletions build-aux/ax_prog_cc_for_build.m4
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
# ===========================================================================
# https://www.gnu.org/software/autoconf-archive/ax_prog_cc_for_build.html
# ===========================================================================
#
# SYNOPSIS
#
# AX_PROG_CC_FOR_BUILD
#
# DESCRIPTION
#
# This macro searches for a C compiler that generates native executables,
# that is a C compiler that surely is not a cross-compiler. This can be
# useful if you have to generate source code at compile-time like for
# example GCC does.
#
# The macro sets the CC_FOR_BUILD and CPP_FOR_BUILD macros to anything
# needed to compile or link (CC_FOR_BUILD) and preprocess (CPP_FOR_BUILD).
# The value of these variables can be overridden by the user by specifying
# a compiler with an environment variable (like you do for standard CC).
#
# It also sets BUILD_EXEEXT and BUILD_OBJEXT to the executable and object
# file extensions for the build platform, and GCC_FOR_BUILD to `yes' if
# the compiler we found is GCC. All these variables but GCC_FOR_BUILD are
# substituted in the Makefile.
#
# LICENSE
#
# Copyright (c) 2008 Paolo Bonzini <[email protected]>
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice
# and this notice are preserved. This file is offered as-is, without any
# warranty.

#serial 21

AU_ALIAS([AC_PROG_CC_FOR_BUILD], [AX_PROG_CC_FOR_BUILD])
AC_DEFUN([AX_PROG_CC_FOR_BUILD], [dnl
AC_REQUIRE([AC_PROG_CC])dnl
AC_REQUIRE([AC_PROG_CPP])dnl
AC_REQUIRE([AC_CANONICAL_BUILD])dnl

dnl Use the standard macros, but make them use other variable names
dnl
pushdef([ac_cv_prog_CPP], ac_cv_build_prog_CPP)dnl
pushdef([ac_cv_prog_cc_c89], ac_cv_build_prog_cc_c89)dnl
pushdef([ac_cv_prog_cc_c99], ac_cv_build_prog_cc_c99)dnl
pushdef([ac_cv_prog_cc_c11], ac_cv_build_prog_cc_c11)dnl
pushdef([ac_cv_prog_gcc], ac_cv_build_prog_gcc)dnl
pushdef([ac_cv_prog_cc_works], ac_cv_build_prog_cc_works)dnl
pushdef([ac_cv_prog_cc_cross], ac_cv_build_prog_cc_cross)dnl
pushdef([ac_cv_prog_cc_g], ac_cv_build_prog_cc_g)dnl
pushdef([ac_cv_c_compiler_gnu], ac_cv_build_c_compiler_gnu)dnl
pushdef([ac_cv_exeext], ac_cv_build_exeext)dnl
pushdef([ac_cv_objext], ac_cv_build_objext)dnl
pushdef([ac_exeext], ac_build_exeext)dnl
pushdef([ac_objext], ac_build_objext)dnl
pushdef([CC], CC_FOR_BUILD)dnl
pushdef([CPP], CPP_FOR_BUILD)dnl
pushdef([GCC], GCC_FOR_BUILD)dnl
pushdef([CFLAGS], CFLAGS_FOR_BUILD)dnl
pushdef([CPPFLAGS], CPPFLAGS_FOR_BUILD)dnl
pushdef([EXEEXT], BUILD_EXEEXT)dnl
pushdef([LDFLAGS], LDFLAGS_FOR_BUILD)dnl
pushdef([OBJEXT], BUILD_OBJEXT)dnl
pushdef([host], build)dnl
pushdef([host_alias], build_alias)dnl
pushdef([host_cpu], build_cpu)dnl
pushdef([host_vendor], build_vendor)dnl
pushdef([host_os], build_os)dnl
pushdef([ac_cv_host], ac_cv_build)dnl
pushdef([ac_cv_host_alias], ac_cv_build_alias)dnl
pushdef([ac_cv_host_cpu], ac_cv_build_cpu)dnl
pushdef([ac_cv_host_vendor], ac_cv_build_vendor)dnl
pushdef([ac_cv_host_os], ac_cv_build_os)dnl
pushdef([ac_tool_prefix], ac_build_tool_prefix)dnl
pushdef([am_cv_CC_dependencies_compiler_type], am_cv_build_CC_dependencies_compiler_type)dnl
pushdef([am_cv_prog_cc_c_o], am_cv_build_prog_cc_c_o)dnl
pushdef([cross_compiling], cross_compiling_build)dnl

cross_compiling_build=no

ac_build_tool_prefix=
AS_IF([test -n "$build"], [ac_build_tool_prefix="$build-"],
[test -n "$build_alias"],[ac_build_tool_prefix="$build_alias-"])

AC_LANG_PUSH([C])

dnl The pushdef([ac_cv_c_compiler_gnu], ...) currently does not cover
dnl the use of this variable in _AC_LANG_COMPILER_GNU called by
dnl AC_PROG_CC. Unset this cache variable temporarily as a workaround.
was_set_c_compiler_gnu=${[ac_cv_c_compiler_gnu]+y}
AS_IF([test ${was_set_c_compiler_gnu}],
[saved_c_compiler_gnu=$[ac_cv_c_compiler_gnu]
AS_UNSET([[ac_cv_c_compiler_gnu]])])

AC_PROG_CC

dnl Restore ac_cv_c_compiler_gnu
AS_IF([test ${was_set_c_compiler_gnu}],
[[ac_cv_c_compiler_gnu]=$[saved_c_compiler_gnu]])

_AC_COMPILER_EXEEXT
_AC_COMPILER_OBJEXT
AC_PROG_CPP

dnl Restore the old definitions
dnl
popdef([cross_compiling])dnl
popdef([am_cv_prog_cc_c_o])dnl
popdef([am_cv_CC_dependencies_compiler_type])dnl
popdef([ac_tool_prefix])dnl
popdef([ac_cv_host_os])dnl
popdef([ac_cv_host_vendor])dnl
popdef([ac_cv_host_cpu])dnl
popdef([ac_cv_host_alias])dnl
popdef([ac_cv_host])dnl
popdef([host_os])dnl
popdef([host_vendor])dnl
popdef([host_cpu])dnl
popdef([host_alias])dnl
popdef([host])dnl
popdef([OBJEXT])dnl
popdef([LDFLAGS])dnl
popdef([EXEEXT])dnl
popdef([CPPFLAGS])dnl
popdef([CFLAGS])dnl
popdef([GCC])dnl
popdef([CPP])dnl
popdef([CC])dnl
popdef([ac_objext])dnl
popdef([ac_exeext])dnl
popdef([ac_cv_objext])dnl
popdef([ac_cv_exeext])dnl
popdef([ac_cv_c_compiler_gnu])dnl
popdef([ac_cv_prog_cc_g])dnl
popdef([ac_cv_prog_cc_cross])dnl
popdef([ac_cv_prog_cc_works])dnl
popdef([ac_cv_prog_cc_c89])dnl
popdef([ac_cv_prog_gcc])dnl
popdef([ac_cv_prog_CPP])dnl

dnl restore global variables ac_ext, ac_cpp, ac_compile,
dnl ac_link, ac_compiler_gnu (dependant on the current
dnl language after popping):
AC_LANG_POP([C])

dnl Finally, set Makefile variables
dnl
AC_SUBST(BUILD_EXEEXT)dnl
AC_SUBST(BUILD_OBJEXT)dnl
AC_SUBST([CFLAGS_FOR_BUILD])dnl
AC_SUBST([CPPFLAGS_FOR_BUILD])dnl
AC_SUBST([LDFLAGS_FOR_BUILD])dnl
])
Loading