From f6083876fd93c163f284768428f28ef1a3bbf448 Mon Sep 17 00:00:00 2001 From: Marius Gerbershagen Date: Mon, 1 Jan 2024 19:40:42 +0100 Subject: [PATCH 1/3] support shared libraries for the emscripten target --- INSTALL | 10 +++------- msvc/Makefile | 2 ++ src/aclocal.m4 | 4 ++++ src/cmp/cmpbackend-cxx/cmpbackend-cxx.lsp | 8 ++++++-- src/cmp/cmpdefs.lsp | 1 + src/compile.lsp.in | 6 ++++-- src/configure | 15 ++++++++++----- src/configure.ac | 1 + 8 files changed, 31 insertions(+), 16 deletions(-) diff --git a/INSTALL b/INSTALL index 1b399c0c2..961fc9241 100644 --- a/INSTALL +++ b/INSTALL @@ -127,9 +127,6 @@ Emscripten target is a little fickle so keep in mind that: - to build emscripten you need to use their SDK that provides the toolchain, and set the environment variable EMSDK_PATH -- the optimization level -O0 is forced because otherwsise binaryen miscompiles - ECL - 1. Build the host ECL #+begin_src shell-script @@ -166,7 +163,6 @@ After that activate the toolchain and configure build flags: --build=x86_64-pc-linux-gnu \ --with-cross-config=`pwd`/src/util/wasm32-unknown-emscripten.cross_config \ --prefix=`pwd`/ecl-emscripten \ - --disable-shared \ --with-tcp=no \ --with-cmp=no @@ -190,12 +186,12 @@ After that activate the toolchain and configure build flags: If the output does not show on the webpage then open the javascript console. This is a default html website produced by emscripten. -5. Build an external program linked against libecl.a +5. Build an external program linked against libecl.so The default stack size proposed by emscripten is 64KB. This is too little for -ECL, so when you build a program that is linked against libecl.a, then it is +ECL, so when you build a program that is linked against libecl.so, then it is imoprtant to specify a different size. For example: #+begin_src shell-script - emcc program.c -sSTACK_SIZE=1048576 lib/*.a -I./include -o program.o + emcc program.c -sSTACK_SIZE=1048576 lib/libecl.so -I./include -o program.o #+end_src diff --git a/msvc/Makefile b/msvc/Makefile index 6137d76c8..376c6af25 100755 --- a/msvc/Makefile +++ b/msvc/Makefile @@ -274,6 +274,7 @@ compile.lsp: bare.lsp $(srcdir)/compile.lsp.in Makefile "@LDFLAGS@" "$(LDFLAGS)" \ "@SHARED_LDFLAGS@" "$(SHARED_LDFLAGS)" \ "@BUNDLE_LDFLAGS@" "$(SHARED_LDFLAGS)" \ + "@PROGRAM_LDFLAGS@" "" \ "@CLIBS@" "$(CLIBS)" \ "@STATICLIBS@" "$(STATICLIBS)" \ "@LIBS@" "$(LIBS)" \ @@ -316,6 +317,7 @@ cmp/cmpdefs.lsp: $(srcdir)/cmp/cmpdefs.lsp Makefile "@LDFLAGS@" "$(LDFLAGS)" \ "@SHARED_LDFLAGS@" "$(SHARED_LDFLAGS)" \ "@BUNDLE_LDFLAGS@" "$(SHARED_LDFLAGS)" \ + "@PROGRAM_LDFLAGS@" "" \ "@CLIBS@" "$(CLIBS)" \ "@STATICLIBS@" "$(STATICLIBS)" \ "@OBJEXT@" "obj" \ diff --git a/src/aclocal.m4 b/src/aclocal.m4 index 2e562c426..39fbe47a9 100644 --- a/src/aclocal.m4 +++ b/src/aclocal.m4 @@ -533,6 +533,10 @@ case "${host}" in enable_threads='no' enable_libffi='no' enable_gmp='portable' + with_c_gmp=yes + SHARED_LDFLAGS="-shared -sSIDE_MODULE ${LDFLAGS}" + BUNDLE_LDFLAGS="-shared -sSIDE_MODULE ${LDFLAGS}" + PROGRAM_LDFLAGS="-sMAIN_MODULE -sERROR_ON_UNDEFINED_SYMBOLS=0 ${LDFLAGS}" ;; esac diff --git a/src/cmp/cmpbackend-cxx/cmpbackend-cxx.lsp b/src/cmp/cmpbackend-cxx/cmpbackend-cxx.lsp index 778cb59fe..c32da866e 100644 --- a/src/cmp/cmpbackend-cxx/cmpbackend-cxx.lsp +++ b/src/cmp/cmpbackend-cxx/cmpbackend-cxx.lsp @@ -103,7 +103,9 @@ the environment variable TMPDIR to a different value." template)) #+msvc (defun linker-cc (o-pathname object-files &key (type :program) - (ld-flags (split-program-options *ld-flags*)) + (ld-flags (split-program-options (if (eq type :program) + *ld-program-flags* + *ld-flags*))) (ld-libs (split-program-options *ld-libs*))) (safe-run-program *ld* @@ -126,7 +128,9 @@ the environment variable TMPDIR to a different value." template)) #-msvc (defun linker-cc (o-pathname object-files &key (type :program) - (ld-flags (split-program-options *ld-flags*)) + (ld-flags (split-program-options (if (eq type :program) + *ld-program-flags* + *ld-flags*))) (ld-libs (split-program-options *ld-libs*))) (declare (ignore type)) (safe-run-program diff --git a/src/cmp/cmpdefs.lsp b/src/cmp/cmpdefs.lsp index 217223109..c3d873f8a 100644 --- a/src/cmp/cmpdefs.lsp +++ b/src/cmp/cmpdefs.lsp @@ -57,6 +57,7 @@ coprocessor).") (defvar *ld-shared-flags* "@SHARED_LDFLAGS@ @LDFLAGS@") #+dlopen (defvar *ld-bundle-flags* "@BUNDLE_LDFLAGS@ @LDFLAGS@") +(defvar *ld-program-flags* "@PROGRAM_LDFLAGS@ @LDFLAGS@") (defvar +shared-library-prefix+ "@SHAREDPREFIX@") (defvar +shared-library-extension+ "@SHAREDEXT@") diff --git a/src/compile.lsp.in b/src/compile.lsp.in index bf52484b7..d2c6d0b2b 100755 --- a/src/compile.lsp.in +++ b/src/compile.lsp.in @@ -95,7 +95,9 @@ c::*ld-shared-flags* "@SHARED_LDFLAGS@ @LDFLAGS@" c::*ld-bundle-flags* - "@BUNDLE_LDFLAGS@ @LDFLAGS@") + "@BUNDLE_LDFLAGS@ @LDFLAGS@" + c::*ld-program-flags* + "@PROGRAM_LDFLAGS@ @LDFLAGS@") ;;; FIXME: The nonstop platform does not support soname #+(and :wants-dlopen nonstop) (setf c::*ld-libs* @@ -182,7 +184,7 @@ (push "@LIBPREFIX@eclgmp.@LIBEXT@" extra-args))) (print extra-args) (c::shared-cc (compile-file-pathname "ecl" :type :dll) - (list* "c/main.@OBJEXT@" + (list* #-emscripten "c/main.@OBJEXT@" "c/all_symbols2.@OBJEXT@" "@LIBPREFIX@lsp.@LIBEXT@" "@LIBPREFIX@eclmin.@LIBEXT@" diff --git a/src/configure b/src/configure index 089a4afec..77b5fa357 100755 --- a/src/configure +++ b/src/configure @@ -739,6 +739,7 @@ LIBRARIES SUBDIRS TARGETS EXTRA_OBJS +PROGRAM_LDFLAGS BUNDLE_LDFLAGS SHARED_LDFLAGS CORE_LIBS @@ -3692,7 +3693,7 @@ test -z "${ecldir}" && ecldir="${libdir}/ecl-${PACKAGE_VERSION}" boehm_configure_flags="" - TARGETS='bin/ecl$(EXE)' + TARGETS='bin/ecl$(EXE)' SUBDIRS='c doc' LSP_FEATURES='*features*' @@ -5052,11 +5053,11 @@ if test x$ac_prog_cxx_stdcxx = xno then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CXX option to enable C++11 features" >&5 printf %s "checking for $CXX option to enable C++11 features... " >&6; } -if test ${ac_cv_prog_cxx_11+y} +if test ${ac_cv_prog_cxx_cxx11+y} then : printf %s "(cached) " >&6 else $as_nop - ac_cv_prog_cxx_11=no + ac_cv_prog_cxx_cxx11=no ac_save_CXX=$CXX cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -5098,11 +5099,11 @@ if test x$ac_prog_cxx_stdcxx = xno then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CXX option to enable C++98 features" >&5 printf %s "checking for $CXX option to enable C++98 features... " >&6; } -if test ${ac_cv_prog_cxx_98+y} +if test ${ac_cv_prog_cxx_cxx98+y} then : printf %s "(cached) " >&6 else $as_nop - ac_cv_prog_cxx_98=no + ac_cv_prog_cxx_cxx98=no ac_save_CXX=$CXX cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -6233,6 +6234,10 @@ LSP_FEATURES="(cons :android ${LSP_FEATURES})" enable_threads='no' enable_libffi='no' enable_gmp='portable' + with_c_gmp=yes + SHARED_LDFLAGS="-shared -sSIDE_MODULE ${LDFLAGS}" + BUNDLE_LDFLAGS="-shared -sSIDE_MODULE ${LDFLAGS}" + PROGRAM_LDFLAGS="-sMAIN_MODULE -sERROR_ON_UNDEFINED_SYMBOLS=0 ${LDFLAGS}" ;; esac diff --git a/src/configure.ac b/src/configure.ac index 5a2bcd4b6..ae3da8b0e 100644 --- a/src/configure.ac +++ b/src/configure.ac @@ -317,6 +317,7 @@ AC_SUBST(CORE_LIBS, []) dnl Locally compiled libs to link into dnl ecl/ecl_min/libecl.so and nowhere else. AC_SUBST(SHARED_LDFLAGS) dnl Flags for shared libraries linker AC_SUBST(BUNDLE_LDFLAGS) dnl Flags for FASL files linker +AC_SUBST(PROGRAM_LDFLAGS) dnl Flags for executable program linker AC_SUBST(EXTRA_OBJS) dnl Extra *.o files to be compiled into libecl.a AC_SUBST(TARGETS, ['bin/ecl$(EXE)'])dnl Versions of ECL to be built AC_SUBST(SUBDIRS, ['c doc']) dnl Subdirectories that make should process From 7bde88e813d36e96376111578dd1d71dfbd42a47 Mon Sep 17 00:00:00 2001 From: Marius Gerbershagen Date: Sat, 27 Jan 2024 11:30:23 +0100 Subject: [PATCH 2/3] Makefile: allow both install and flatinstall targets --- Makefile.in | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile.in b/Makefile.in index 961a4d45a..ef55a07be 100644 --- a/Makefile.in +++ b/Makefile.in @@ -77,6 +77,8 @@ INSTALL_TARGET = @INSTALL_TARGET@ install: build/Makefile cd build; $(MAKE) $(INSTALL_TARGET) +flatinstall: build/Makefile + cd build; $(MAKE) flatinstall uninstall: cd build; $(MAKE) uninstall From 6c7f8be6a92fb6b0ea32c6d6e06159bc882a2cee Mon Sep 17 00:00:00 2001 From: Marius Gerbershagen Date: Sat, 27 Jan 2024 11:32:14 +0100 Subject: [PATCH 3/3] use flatinstall as install target for emscripten --- INSTALL | 6 +++--- src/aclocal.m4 | 1 + src/configure | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/INSTALL b/INSTALL index 961fc9241..b3c471537 100644 --- a/INSTALL +++ b/INSTALL @@ -169,14 +169,14 @@ After that activate the toolchain and configure build flags: emmake make && emmake make install # some files need to be copied manually - cp build/bin/ecl.js build/bin/ecl.wasm ecl-emscripten/bin + cp build/bin/ecl.js build/bin/ecl.wasm ecl-emscripten/ #+end_src 4. ECL may be hosted on a web page. Assuming that you have quicklisp installed: #+begin_src shell-script export WEBSERVER=`pwd`/src/util/webserver.lisp - pushd ecl-emscripten/bin + pushd ecl-emscripten/ lisp --load $WEBSERVER # After the server is loaded run: # firefox localhost:8888/ecl.html @@ -193,5 +193,5 @@ ECL, so when you build a program that is linked against libecl.so, then it is imoprtant to specify a different size. For example: #+begin_src shell-script - emcc program.c -sSTACK_SIZE=1048576 lib/libecl.so -I./include -o program.o + emcc program.c -sSTACK_SIZE=1048576 libecl.so -I./ -o program.o #+end_src diff --git a/src/aclocal.m4 b/src/aclocal.m4 index 39fbe47a9..c55b51839 100644 --- a/src/aclocal.m4 +++ b/src/aclocal.m4 @@ -537,6 +537,7 @@ case "${host}" in SHARED_LDFLAGS="-shared -sSIDE_MODULE ${LDFLAGS}" BUNDLE_LDFLAGS="-shared -sSIDE_MODULE ${LDFLAGS}" PROGRAM_LDFLAGS="-sMAIN_MODULE -sERROR_ON_UNDEFINED_SYMBOLS=0 ${LDFLAGS}" + INSTALL_TARGET='flatinstall' ;; esac diff --git a/src/configure b/src/configure index 77b5fa357..4cf037291 100755 --- a/src/configure +++ b/src/configure @@ -6238,6 +6238,7 @@ LSP_FEATURES="(cons :android ${LSP_FEATURES})" SHARED_LDFLAGS="-shared -sSIDE_MODULE ${LDFLAGS}" BUNDLE_LDFLAGS="-shared -sSIDE_MODULE ${LDFLAGS}" PROGRAM_LDFLAGS="-sMAIN_MODULE -sERROR_ON_UNDEFINED_SYMBOLS=0 ${LDFLAGS}" + INSTALL_TARGET='flatinstall' ;; esac