diff --git a/.github/workflows/ci-xmake-wasm.yml b/.github/workflows/ci-xmake-wasm.yml new file mode 100644 index 0000000000..f0a5c7fd35 --- /dev/null +++ b/.github/workflows/ci-xmake-wasm.yml @@ -0,0 +1,68 @@ +name: Build and Test by WASM + +on: + push: + branches: [ branch-1.2 ] + paths: + - 'src/**' + - '!src/Plugins/Macos/**' + - '!src/Plugins/Windows/**' + - '!src/Plugins/Unix/**' + - 'tests/**' + - 'xmake.lua' + - '.github/workflows/ci-xmake-wasm.yml' + pull_request: + branches: [ branch-1.2 ] + paths: + - 'src/**' + - '!src/Plugins/Macos/**' + - '!src/Plugins/Windows/**' + - '!src/Plugins/Unix/**' + - 'tests/**' + - 'xmake.lua' + - '.github/workflows/ci-xmake-wasm.yml' + +jobs: + wasmbuild: + runs-on: ubuntu-22.04 + if: always() + steps: + - uses: xmake-io/github-action-setup-xmake@v1 + with: + xmake-version: branch@dev + - name: update repo + run: | + xrepo update-repo + - uses: actions/checkout@v3 + with: + fetch-depth: 1 + - name: set XMAKE_GLOBALDIR + run: echo "XMAKE_GLOBALDIR=${{ runner.workspace }}/xmake-global" >> $GITHUB_ENV + - name: cache packages from xrepo + uses: actions/cache@v2 + with: + path: | + ${{ env.XMAKE_GLOBALDIR }}/.xmake/packages + key: ${{ runner.os }}-xrepo-wasm-${{ hashFiles('**/packages.lua') }} + - name: cache xmake + uses: actions/cache@v2 + with: + path: | + ${{ github.workspace }}/build/.build_cache + key: ${{ runner.os }}-xmake-build-${{ hashFiles('**/xmake.lua') }} + - name: Install Qt wasm + uses: jurplel/install-qt-action@v3 + with: + version: 6.5.2 + arch: wasm_singlethread + host: 'linux' + target: 'desktop' + cache: 'true' + # workarounds in https://github.com/jurplel/install-qt-action/issues/181 + aqtversion: '==3.1.*' + py7zrversion: '==0.20.*' + extra: '--autodesktop' + - name: config + run: xmake config --policies=build.ccache -o ${{ runner.workspace }}/build -vD -p wasm -m releasedbg --yes + - name: build + run: xmake build libmogan diff --git a/bin/config_wasm b/bin/config_wasm index fd0535abb4..ab5f072bd7 100755 --- a/bin/config_wasm +++ b/bin/config_wasm @@ -1,9 +1,4 @@ #!/usr/bin/env elvish -xrepo install -y "emscripten 3.1.42" +xmake config -p wasm --qt=~/6.5.2/wasm_singlethread/ --yes -var pkg_info = (xrepo fetch --json emscripten | from-json) -var emsdk_path = $pkg_info[0][artifacts][installdir] -set-env EMSDK $emsdk_path - -xmake config --yes -p wasm -vD diff --git a/misc/xmake/packages.lua b/misc/xmake/packages.lua index 404a54052b..0e18b36414 100644 --- a/misc/xmake/packages.lua +++ b/misc/xmake/packages.lua @@ -45,7 +45,7 @@ package_end() function add_requires_of_mogan() - local LOLLY_VERSION = "1.2.0" + local LOLLY_VERSION = "1.2.3" local CURL_VERSION = "7.84.0" local FREETYPE_VERSION = "2.12.1" local PDFHUMMUS_VERSION = "4.5.10" diff --git a/src/Mogan/Research/research.cpp b/src/Mogan/Research/research.cpp index da729a210d..dfd5b42d97 100644 --- a/src/Mogan/Research/research.cpp +++ b/src/Mogan/Research/research.cpp @@ -208,6 +208,12 @@ TeXmacs_init_paths (int& argc, char** argv) { as_string (exedir * "/system/lib/TeXmacs/bin")); #endif +#ifdef OS_WASM + set_env ("PWD", "/"); + set_env ("HOME", "/"); + if (is_empty (current_texmacs_path)) set_env ("TEXMACS_PATH", "/TeXmacs"); +#endif + // check on the latest $TEXMACS_PATH current_texmacs_path= get_env ("TEXMACS_PATH"); if (is_empty (current_texmacs_path) || @@ -333,6 +339,10 @@ TeXmacs_main (int argc, char** argv) { retina_factor= 2; retina_zoom = 1; retina_scale = 1.4; +#elif defined(OS_WASM) + retina_factor= 2; + retina_zoom = 2; + retina_scale = (tm_style_sheet == "" ? 1.0 : 1.6666); #else retina_factor= 1; retina_zoom = 2; @@ -595,6 +605,8 @@ immediate_options (int argc, char** argv) { #elif defined(OS_HAIKU) set_env ("TEXMACS_HOME_PATH", get_env ("HOME") * "/config/settings/TeXmacs"); +#elif defined(OS_WASM) + set_env ("TEXMACS_HOME_PATH", "/.Xmacs"); #else set_env ("TEXMACS_HOME_PATH", get_env ("HOME") * "/.TeXmacs"); #endif @@ -695,10 +707,12 @@ main (int argc, char** argv) { #ifndef OS_MINGW set_env ("LC_NUMERIC", "POSIX"); #ifndef OS_MACOS +#ifndef OS_WASM set_env ("QT_QPA_PLATFORM", "xcb"); set_env ("XDG_SESSION_TYPE", "x11"); #endif #endif +#endif #ifdef MACOSX_EXTENSIONS // Reset TeXmacs if Alt is pressed during startup if (mac_alternate_startup ()) { diff --git a/src/Plugins/LaTeX_Preview/latex_preview.cpp b/src/Plugins/LaTeX_Preview/latex_preview.cpp index 8b3f5ee1b4..37f12bc407 100644 --- a/src/Plugins/LaTeX_Preview/latex_preview.cpp +++ b/src/Plugins/LaTeX_Preview/latex_preview.cpp @@ -31,6 +31,14 @@ set_latex_command (string cmd) { latex_command= cmd; } +#ifdef OS_WASM +array +latex_preview (string s, tree t) { + dbg ("LaTeX preview disabled in WASM"); + return array(); +} +#else + bool latex_present () { return exists_in_path (latex_command); @@ -235,3 +243,4 @@ latex_preview (string s, tree t) { latex_clean_tmp_directory (wdir); return r; } +#endif // OS_WASM diff --git a/src/Plugins/Qt/QTMPipeLink.cpp b/src/Plugins/Qt/QTMPipeLink.cpp index 9b1cc935b3..11ce990be7 100644 --- a/src/Plugins/Qt/QTMPipeLink.cpp +++ b/src/Plugins/Qt/QTMPipeLink.cpp @@ -94,4 +94,3 @@ QTMPipeLink::killProcess (int msecs) { if (! waitForFinished (msecs)) kill (); #endif } - diff --git a/src/Plugins/Qt/QTMPipeLink.hpp b/src/Plugins/Qt/QTMPipeLink.hpp index 25ae66f5fd..07082e5da8 100644 --- a/src/Plugins/Qt/QTMPipeLink.hpp +++ b/src/Plugins/Qt/QTMPipeLink.hpp @@ -44,4 +44,3 @@ public slots: }; #endif // QTM_PIPE_LINK - diff --git a/src/Plugins/Qt/QTMPrinterSettings.cpp b/src/Plugins/Qt/QTMPrinterSettings.cpp index f373b1b08d..edf10bb978 100644 --- a/src/Plugins/Qt/QTMPrinterSettings.cpp +++ b/src/Plugins/Qt/QTMPrinterSettings.cpp @@ -571,4 +571,3 @@ WinQTMPrinterSettings::availablePrinters() { } #endif - diff --git a/src/Plugins/Qt/qt_printer_widget.cpp b/src/Plugins/Qt/qt_printer_widget.cpp index 95fe98233c..d68e71354e 100644 --- a/src/Plugins/Qt/qt_printer_widget.cpp +++ b/src/Plugins/Qt/qt_printer_widget.cpp @@ -98,5 +98,3 @@ qt_printer_widget_rep::showDialog () { if (!is_nil (commandAfterExecution)) commandAfterExecution (); } - - diff --git a/src/Plugins/Qt/qt_printer_widget.hpp b/src/Plugins/Qt/qt_printer_widget.hpp index 44e6a80d25..0b8b461545 100644 --- a/src/Plugins/Qt/qt_printer_widget.hpp +++ b/src/Plugins/Qt/qt_printer_widget.hpp @@ -8,6 +8,7 @@ * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE * in the root directory or . ******************************************************************************/ + #ifndef QT_PRINTER_WIDGET_HPP #define QT_PRINTER_WIDGET_HPP diff --git a/src/Plugins/Qt/qt_sys_utils.cpp b/src/Plugins/Qt/qt_sys_utils.cpp index 697ce0990a..abb40ca4f7 100644 --- a/src/Plugins/Qt/qt_sys_utils.cpp +++ b/src/Plugins/Qt/qt_sys_utils.cpp @@ -28,6 +28,7 @@ string qt_get_pretty_os_name () { return from_qstring (QSysInfo::prettyProductName ()); } +#if !defined (OS_WASM) static void ReadOutputs(QProcess& p, string& o, string& e) { if (p.processChannelMode() == QProcess::MergedChannels) @@ -85,3 +86,4 @@ qt_system (string cmd, string& result) { proc.setProcessChannelMode (QProcess::MergedChannels); return qt_system (proc, cmd, result, dummy); } +#endif // !defined (OS_WASM) diff --git a/src/Plugins/Qt/qt_utilities.cpp b/src/Plugins/Qt/qt_utilities.cpp index 7af899cdb8..0006431876 100644 --- a/src/Plugins/Qt/qt_utilities.cpp +++ b/src/Plugins/Qt/qt_utilities.cpp @@ -14,7 +14,6 @@ #include #include -#include #include #include #include @@ -26,8 +25,11 @@ #include #include +#ifdef USE_QT_PRINTER #include #include +#endif + #include #include @@ -470,6 +472,7 @@ qt_convert_image (url image, url dest, int w, int h) {// w, h in pixels } } +#ifdef USE_QT_PRINTER void qt_image_to_pdf (url image, url outfile, int w_pt, int h_pt, int dpi) { // use a QPrinter to output raster images to eps or pdf @@ -531,6 +534,12 @@ qt_image_to_pdf (url image, url outfile, int w_pt, int h_pt, int dpi) { p.end(); } } +#else +void +qt_image_to_pdf (url image, url outfile, int w_pt, int h_pt, int dpi){ + if (DEBUG_CONVERT) debug_convert << "NOT SUPPORTED: qt_image_to_eps_or_pdf " << image << " -> "< (cmd, type, prompt); } + +#if !defined (USE_QT_PRINTER) +widget printer_widget (command cmd, url ps_pdf_file){ + return widget(); +} +#else widget printer_widget (command cmd, url ps_pdf_file) { if (headless_mode) return headless_widget (); return tm_new (cmd, ps_pdf_file); } +#endif + widget texmacs_widget (int mask, command quit) { if (headless_mode) return headless_widget (); if (mask) return tm_new (mask, quit); diff --git a/src/System/Boot/init_texmacs.cpp b/src/System/Boot/init_texmacs.cpp index f7a4379d3f..6d85fbf86c 100644 --- a/src/System/Boot/init_texmacs.cpp +++ b/src/System/Boot/init_texmacs.cpp @@ -293,7 +293,7 @@ init_env_vars () { static void init_misc () { // Test whether 'which' works -#ifdef OS_MINGW +#if defined(OS_MINGW) || defined(OS_WASM) use_which = false; #else use_which = (var_eval_system ("which texmacs 2> /dev/null") != ""); diff --git a/src/System/Link/pipe_link.cpp b/src/System/Link/pipe_link.cpp index 12e28cab95..bfd981e4a2 100644 --- a/src/System/Link/pipe_link.cpp +++ b/src/System/Link/pipe_link.cpp @@ -10,8 +10,9 @@ ******************************************************************************/ #include "basic.hpp" +#include "tm_link.hpp" -#if !(defined (QTTEXMACS) && (defined (OS_MINGW) || defined (QTPIPES))) +#if !(defined (QTTEXMACS) && (defined (OS_MINGW) || defined (QTPIPES) || defined(OS_WASM))) #include "tm_link.hpp" #include "socket_notifier.hpp" @@ -376,3 +377,10 @@ void pipe_callback (void *obj, void *info) { } #endif // !(defined (QTTEXMACS) && defined (OS_MINGW)) + +#ifdef OS_WASM +tm_link make_pipe_link (string cmd) { return tm_link(); } + +void close_all_pipes () {} +void process_all_pipes () {} +#endif diff --git a/src/System/Misc/tm_sys_utils.cpp b/src/System/Misc/tm_sys_utils.cpp index c800da3bf1..12ad8665a2 100644 --- a/src/System/Misc/tm_sys_utils.cpp +++ b/src/System/Misc/tm_sys_utils.cpp @@ -50,12 +50,20 @@ string get_pretty_os_name () { int system (string s, string& result, string& error) { +#ifdef OS_WASM + return -1; +#else return qt_system (s, result, error); +#endif } int system (string s, string& result) { +#ifdef OS_WASM + return -1; +#else return qt_system (s, result); +#endif } string diff --git a/src/System/config.h.xmake b/src/System/config.h.xmake index 5f4acffe07..b8b407dc10 100644 --- a/src/System/config.h.xmake +++ b/src/System/config.h.xmake @@ -1,6 +1,10 @@ /* L1 Kernel */ ${define QTTEXMACS} ${define OS_MINGW} +${define OS_GNU_LINUX} +${define OS_MACOS} +${define OS_WASM} + /* Define to 1 if the system has the type `intptr_t'. */ ${define HAVE_INTPTR_T} @@ -77,10 +81,6 @@ ${define LINKED_SQLITE3} ${define MACOSX_EXTENSIONS} -${define OS_GNU_LINUX} - -${define OS_MACOS} - ${define PDFHUMMUS_NO_TIFF} /* Disable fast memory allocator */ @@ -109,8 +109,6 @@ ${define QTPIPES} ${define USE_QT_PRINTER} -${define USE_CURL} - ${define SANITY_CHECKS} #define SIZEOF_VOID_P ${SIZEOF_VOID_P} diff --git a/src/System/config_l3.h.xmake b/src/System/config_l3.h.xmake index 8d7abadbfe..0a3fbba4d4 100644 --- a/src/System/config_l3.h.xmake +++ b/src/System/config_l3.h.xmake @@ -1,5 +1,4 @@ #define KERNEL_L3 -#define LOLLY_VERSION "@LOLLY_VERSION@" /* L1 Kernel */ ${define HAVE_INTPTR_T} @@ -9,6 +8,7 @@ ${define SANITY_CHECKS} ${define OS_MINGW} ${define OS_MACOS} ${define OS_WIN} +${define OS_WASM} /* L2 Kernel */ ${define HAVE_TIME_T} diff --git a/src/System/tm_configure_l3.hpp.xmake b/src/System/tm_configure_l3.hpp.xmake index 96b9d15805..9dcc2d1dc6 100644 --- a/src/System/tm_configure_l3.hpp.xmake +++ b/src/System/tm_configure_l3.hpp.xmake @@ -1,3 +1,4 @@ #define BUILD_USER "@CONFIG_USER@" #define BUILD_DATE "@VERSION_BUILD@" #define TEXMACS_VERSION "@VERSION@" +#define LOLLY_VERSION "@LOLLY_VERSION@" diff --git a/src/Texmacs/Server/tm_server.cpp b/src/Texmacs/Server/tm_server.cpp index c49e540c5a..a30b38ffe2 100644 --- a/src/Texmacs/Server/tm_server.cpp +++ b/src/Texmacs/Server/tm_server.cpp @@ -166,6 +166,7 @@ tm_server_rep::refresh () { void tm_server_rep::interpose_handler () { +#ifndef OS_WASM #ifdef QTTEXMACS // TeXmacs/Qt handles delayed messages and socket notification // in its own runloop @@ -177,6 +178,7 @@ tm_server_rep::interpose_handler () { perform_select (); exec_pending_commands (); #endif +#endif // not OS_WASM if (!headless_mode) { int i, j; diff --git a/xmake.lua b/xmake.lua index 121a4aef90..5920803085 100644 --- a/xmake.lua +++ b/xmake.lua @@ -15,33 +15,67 @@ includes("check_cxxincludes.lua") includes("check_cxxfuncs.lua") includes("check_cxxsnippets.lua") -configvar_check_cxxincludes("HAVE_STDLIB_H", "stdlib.h") -configvar_check_cxxincludes("HAVE_STRINGS_H", "strings.h") -configvar_check_cxxincludes("HAVE_STRING_H", "string.h") -configvar_check_cxxincludes("HAVE_UNISTD_H", "unistd.h") -configvar_check_cxxtypes("HAVE_INTPTR_T", "intptr_t", {includes = {"memory"}}) -configvar_check_cxxincludes("HAVE_INTTYPES_H", "inttypes.h") -configvar_check_cxxincludes("HAVE_MEMORY_H", "memory.h") -configvar_check_cxxincludes("HAVE_PTY_H", "pty.h") -configvar_check_cxxincludes("HAVE_STDINT_H", "stdint.h") -configvar_check_cxxincludes("HAVE_SYS_STAT_H", "sys/stat.h") -configvar_check_cxxincludes("HAVE_SYS_TYPES_H", "sys/types.h") -configvar_check_cxxtypes("HAVE_TIME_T", "time_t", {includes = {"memory"}}) -configvar_check_cxxincludes("HAVE_UTIL_H", "util.h") -configvar_check_cxxfuncs("HAVE_GETTIMEOFDAY", "gettimeofday", {includes={"sys/time.h"}}) -configvar_check_cxxsnippets( - "CONFIG_LARGE_POINTER", [[ - #include - static_assert(sizeof(void*) == 8, "");]]) +function my_configvar_check() + on_config(function (target) + print("my_configvar_check " .. target:name()) + if target:has_cxxincludes("stdlib.h") then + target:set("configvar", "HAVE_STDLIB_H", 1) + end + if target:has_cxxincludes("strings.h") then + target:set("configvar", "HAVE_STRINGS_H", 1) + end + if target:has_cxxincludes("string.h") then + target:set("configvar", "HAVE_STRING_H", 1) + end + if target:has_cxxincludes("unistd.h") then + target:set("configvar", "HAVE_UNISTD_H", 1) + end + if target:has_cxxincludes("inttypes.h") then + target:set("configvar", "HAVE_INTTYPES_H", 1) + end + if target:has_cxxincludes("memory.h") then + target:set("configvar", "HAVE_MEMORY_H", 1) + end + if target:has_cxxincludes("pty.h") then + target:set("configvar", "HAVE_PTY_H", 1) + end + if target:has_cxxincludes("stdint.h") then + target:set("configvar", "HAVE_STDINT_H", 1) + end + if target:has_cxxincludes("sys/stat.h") then + target:set("configvar", "HAVE_SYS_STAT_H", 1) + end + if target:has_cxxincludes("sys/types.h") then + target:set("configvar", "HAVE_SYS_TYPES_H", 1) + end + if target:has_cxxincludes("util.h") then + target:set("configvar", "HAVE_UTIL_H", 1) + end + if target:has_cxxtypes("intptr_t", {includes = "memory"}) then + target:set("configvar", "HAVE_INTPTR_T", 1) + end + if target:has_cxxtypes("time_t", {incldes = "memory"}) then + target:set("configvar", "HAVE_TIME_T", 1) + end + if target:has_cfuncs("gettimeofday", {includes={"sys/time.h"}}) then + target:set("configvar", "HAVE_GETTIMEOFDAY", 1) + end + if target:check_cxxsnippets({test=[[ + #include + static_assert(sizeof(void*) == 8, ""); + ]]}) then + target:set("configvar", "CONFIG_LARGE_POINTER", 1) + end + end) +end + --- --- Project: Mogan Applications --- set_project("Mogan Applications") -set_allowedplats( - "wasm", "linux", "macosx", "mingw", "windows" -) +set_allowedplats("wasm", "linux", "macosx", "mingw", "windows") if is_plat("mingw") and is_host("windows") then add_requires("mingw-w64 8.1.0") @@ -214,41 +248,37 @@ target("libkernel_l3") do add_packages("s7") add_packages("lolly") - add_configfiles( - "src/System/config_l3.h.xmake", { - filename = "L3/config.h", - variables = { - OS_MINGW = is_plat("mingw"), - OS_MACOS = is_plat("macosx"), - OS_WIN = is_plat("windows"), - QTTEXMACS = false, - } + my_configvar_check() + add_configfiles("src/System/config_l3.h.xmake", { + filename = "L3/config.h", + variables = { + OS_MINGW = is_plat("mingw"), + OS_MACOS = is_plat("macosx"), + OS_WIN = is_plat("windows"), + OS_WASM = is_plat("wasm"), + QTTEXMACS = false, } - ) - add_configfiles( - "src/System/tm_configure_l3.hpp.xmake", { - filename = "L3/tm_configure.hpp", - pattern = "@(.-)@", - variables = { - CONFIG_USER = CONFIG_USER, - CONFIG_OS = CONFIG_OS, - VERSION = TEXMACS_VERSION, - } + }) + add_configfiles("src/System/tm_configure_l3.hpp.xmake", { + filename = "L3/tm_configure.hpp", + pattern = "@(.-)@", + variables = { + CONFIG_USER = CONFIG_USER, + CONFIG_OS = CONFIG_OS, + VERSION = TEXMACS_VERSION, + LOLLY_VERSION = LOLLY_VERSION, } - ) + }) add_includedirs("$(buildir)/L3") add_includedirs("$(buildir)") add_includedirs(l3_includedirs, {public = true}) add_files(l3_files) - if is_plat("windows") then - add_cxxflags("-FI " .. path.absolute("$(buildir)\\L3\\config.h")) - add_cxxflags("-FI " .. path.absolute("$(buildir)\\L3\\tm_configure.hpp")) - else - add_cxxflags("-include $(buildir)/L3/config.h") - add_cxxflags("-include $(buildir)/L3/tm_configure.hpp") - end + before_build(function (target) + target:add("forceincludes", path.absolute("$(buildir)/L3/config.h")) + target:add("forceincludes", path.absolute("$(buildir)/L3/tm_configure.hpp")) + end) end @@ -273,18 +303,18 @@ local DEVEL_RELEASE = 1 local STABLE_VERSION = TEXMACS_VERSION local STABLE_RELEASE = 1 - -set_configvar("QTPIPES", 1) -add_defines("QTPIPES") - -set_configvar("USE_QT_PRINTER", 1) -add_defines("USE_QT_PRINTER") +if not is_plat("wasm") then + set_configvar("QTPIPES", 1) + set_configvar("USE_QT_PRINTER", 1) +end set_configvar("USE_ICONV", 1) -set_configvar("USE_CURL", 1) set_configvar("USE_FREETYPE", 1) -set_configvar("USE_GS", 1) -set_configvar("PDF_RENDERER", 1) +if is_plat("wasm") then + set_configvar("PDF_RENDERER", false) +else + set_configvar("PDF_RENDERER", true) +end set_configvar("PDFHUMMUS_NO_TIFF", true) if is_plat("mingw") then @@ -293,50 +323,61 @@ else set_configvar("GS_EXE", "/usr/bin/gs") end -if is_plat("mingw") then -else if is_plat("macosx") then - set_configvar("USE_STACK_TRACE", true) +if is_plat("macosx") then set_configvar("AQUATEXMACS", true) end - set_configvar("USE_STACK_TRACE", true) -end set_configvar("STDC_HEADERS", true) set_version(TEXMACS_VERSION, {build = "%Y-%m-%d"}) -add_configfiles( - "src/System/config.h.xmake", { - filename = "config.h", - variables = { - GS_FONTS = "../share/ghostscript/fonts:/usr/share/fonts:", - GS_LIB = "../share/ghostscript/9.06/lib:", - OS_GNU_LINUX = is_plat("linux"), - OS_MACOS = is_plat("macosx"), - MACOSX_EXTENSIONS = is_plat("macosx"), - OS_MINGW = is_plat("mingw"), - SIZEOF_VOID_P = 8, - USE_FONTCONFIG = is_plat("linux"), - USE_STACK_TRACE = not is_plat("mingw"), - USE_GS = true, - }}) - -add_configfiles( - "src/System/tm_configure.hpp.xmake", { - filename = "tm_configure.hpp", - pattern = "@(.-)@", - variables = { - XMACS_VERSION = XMACS_VERSION, - CONFIG_USER = CONFIG_USER, - CONFIG_STD_SETENV = "#define STD_SETENV", - tm_devel = "Texmacs-" .. DEVEL_VERSION, - tm_devel_release = "Texmacs-" .. DEVEL_VERSION .. "-" .. DEVEL_RELEASE, - tm_stable = "Texmacs-" .. STABLE_VERSION, - tm_stable_release = "Texmacs-" .. STABLE_VERSION .. "-" .. STABLE_RELEASE, - }}) - +add_configfiles("src/System/config.h.xmake", { + filename = "config.h", + variables = { + GS_FONTS = "../share/ghostscript/fonts:/usr/share/fonts:", + GS_LIB = "../share/ghostscript/9.06/lib:", + OS_GNU_LINUX = is_plat("linux"), + OS_MACOS = is_plat("macosx"), + OS_MINGW = is_plat("mingw"), + OS_WASM = is_plat("wasm"), + MACOSX_EXTENSIONS = is_plat("macosx"), + SIZEOF_VOID_P = 8, + USE_FONTCONFIG = is_plat("linux"), + USE_STACK_TRACE = (not is_plat("mingw")) and (not is_plat("wasm")), + USE_GS = not is_plat("wasm"), + } +}) + +add_configfiles("src/System/tm_configure.hpp.xmake", { + filename = "tm_configure.hpp", + pattern = "@(.-)@", + variables = { + XMACS_VERSION = XMACS_VERSION, + CONFIG_USER = CONFIG_USER, + CONFIG_STD_SETENV = "#define STD_SETENV", + tm_devel = "Texmacs-" .. DEVEL_VERSION, + tm_devel_release = "Texmacs-" .. DEVEL_VERSION .. "-" .. DEVEL_RELEASE, + tm_stable = "Texmacs-" .. STABLE_VERSION, + tm_stable_release = "Texmacs-" .. STABLE_VERSION .. "-" .. STABLE_RELEASE, + LOLLY_VERSION = LOLLY_VERSION, + } +}) +plugin_pdf_srcs = { + "src/Plugins/Pdf/**.cpp", +} +if is_plat("wasm") then + plugin_qt_srcs = { + "src/Plugins/Qt/*.cpp|QTMPipeLink.cpp|QTMPrintDialog.cpp|QTMPrinterSettings.cpp|qt_printer_widget.cpp", + "src/Plugins/Qt/*.hpp|QTMPipeLink.hpp|QTMPrintDialog.hpp|QTMPrinterSettings.hpp", + } +else + plugin_qt_srcs = { + "src/Plugins/Qt/**.cpp", + "src/Plugins/Qt/**.hpp" + } +end target("libmogan") do set_basename("mogan") @@ -344,6 +385,8 @@ target("libmogan") do set_languages("c++17") set_policy("check.auto_ignore_flags", false) + my_configvar_check() + if is_plat("linux") then add_rules("qt.shared") set_installdir(INSTALL_DIR) @@ -366,7 +409,6 @@ target("libmogan") do add_packages("libiconv") add_packages("freetype") add_packages("pdfhummus") - add_packages("nowide_standalone") add_packages("s7") if is_plat("mingw") then @@ -476,7 +518,6 @@ target("libmogan") do "src/Plugins/Bibtex/**.cpp", "src/Plugins/Database/**.cpp", "src/Plugins/Freetype/**.cpp", - "src/Plugins/Pdf/**.cpp", "src/Plugins/Ghostscript/**.cpp", "src/Plugins/Ispell/**.cpp", "src/Plugins/Metafont/**.cpp", @@ -485,6 +526,9 @@ target("libmogan") do "src/Plugins/Tex/**.cpp", "src/Plugins/Updater/**.cpp", "src/Plugins/Xml/**.cpp"}) + if not is_plat("wasm") then + add_files(plugin_pdf_srcs) + end if is_plat("macosx") then add_files({ @@ -494,13 +538,13 @@ target("libmogan") do "src/Plugins/MacOS/mac_app.mm"}) end - add_files({ - "src/Plugins/Qt/**.cpp", - "src/Plugins/Qt/**.hpp"}) + add_files(plugin_qt_srcs) add_mxflags("-fno-objc-arc") - add_cxxflags("-include $(buildir)/config.h") - add_cxxflags("-include $(buildir)/tm_configure.hpp") + before_build(function (target) + target:add("forceincludes", path.absolute("$(buildir)/config.h")) + target:add("forceincludes", path.absolute("$(buildir)/tm_configure.hpp")) + end) end option("libdl") do @@ -525,6 +569,7 @@ target("draw") do set_enabled(is_plat("linux") or is_plat("wasm")) set_version(XMACS_VERSION) set_installdir(INSTALL_DIR) + my_configvar_check() set_filename("mogan_draw") add_rules("qt.widgetapp") @@ -539,20 +584,16 @@ target("draw") do }) add_files("src/Mogan/Draw/draw.cpp") - - set_configdir(INSTALL_DIR) set_configvar("DEVEL_VERSION", DEVEL_VERSION) set_configvar("PACKAGE", "Mogan Draw") set_configvar("XMACS_VERSION", XMACS_VERSION) -- install man.1 manual file - add_configfiles( - "(misc/man/texmacs.1.in)",{ - filename = "texmacs.1", - pattern = "@([^\n]-)@", - } - ) + add_configfiles("(misc/man/texmacs.1.in)", { + filename = "texmacs.1", + pattern = "@([^\n]-)@", + }) -- install texmacs runtime files add_installfiles("misc/scripts/tm_gs", {prefixdir="share/Xmacs/bin"}) @@ -582,6 +623,7 @@ end target("research") do set_version(XMACS_VERSION) set_installdir(INSTALL_DIR) + my_configvar_check() if is_plat("macosx") then set_filename("Mogan") @@ -601,10 +643,12 @@ target("research") do if is_plat("macosx") then add_frameworks("QtMacExtras") end + if is_plat("wasm") then + add_frameworks("QWasmIntegrationPlugin") + end add_packages("lolly") if is_plat("mingw") then - add_packages("nowide_standalone") add_packages("qt5widgets") end @@ -633,23 +677,19 @@ target("research") do set_configvar("XMACS_VERSION", XMACS_VERSION) -- install man.1 manual file - add_configfiles( - "(misc/man/texmacs.1.in)",{ - filename = "texmacs.1", - pattern = "@([^\n]-)@", - } - ) + add_configfiles("(misc/man/texmacs.1.in)", { + filename = "texmacs.1", + pattern = "@([^\n]-)@", + }) -- package metadata if is_plat("macosx") then set_configvar("APPCAST", "") set_configvar("OSXVERMIN", "") - add_configfiles( - "(packages/macos/Info.plist.in)",{ - filename = "Info.plist", - pattern = "@(.-)@", - } - ) + add_configfiles("(packages/macos/Info.plist.in)", { + filename = "Info.plist", + pattern = "@(.-)@", + }) add_installfiles({ "packages/macos/Xmacs.icns", "packages/macos/TeXmacs-document.icns", @@ -821,6 +861,7 @@ function add_test_target (filepath, dep) add_deps(dep) set_languages("c++17") set_policy("check.auto_ignore_flags", false) + my_configvar_check() add_rules("qt.console") add_frameworks("QtGui", "QtWidgets", "QtCore", "QtPrintSupport", "QtSvg", "QtTest") add_syslinks("pthread")