Skip to content

Commit

Permalink
Add script to create amalgamated build
Browse files Browse the repository at this point in the history
Fixes: #688
  • Loading branch information
bnoordhuis committed Feb 27, 2025
1 parent 9a902ba commit ef3cd55
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
46 changes: 46 additions & 0 deletions amalgam.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import {loadFile, writeFile} from "qjs:std"

const cutils_c = loadFile("cutils.c")
const cutils_h = loadFile("cutils.h")
const libbf_c = loadFile("libbf.c")
const libbf_h = loadFile("libbf.h")
const libregexp_c = loadFile("libregexp.c")
const libregexp_h = loadFile("libregexp.h")
const libregexp_opcode_h = loadFile("libregexp-opcode.h")
const libunicode_c = loadFile("libunicode.c")
const libunicode_h = loadFile("libunicode.h")
const libunicode_table_h = loadFile("libunicode-table.h")
const list_h = loadFile("list.h")
const quickjs_atom_h = loadFile("quickjs-atom.h")
const quickjs_c = loadFile("quickjs.c")
const quickjs_c_atomics_h = loadFile("quickjs-c-atomics.h")
const quickjs_h = loadFile("quickjs.h")
const quickjs_libc_c = loadFile("quickjs-libc.c")
const quickjs_libc_h = loadFile("quickjs-libc.h")
const quickjs_opcode_h = loadFile("quickjs-opcode.h")

let source = "#if defined(CONFIG_QUICKJS_LIBC) && defined(__linux__) && !defined(_GNU_SOURCE)\n"
+ "#define _GNU_SOURCE\n"
+ "#endif\n"
+ quickjs_c_atomics_h
+ cutils_h
+ list_h
+ libbf_h
+ libunicode_h // exports lre_is_id_start, used by libregexp.h
+ libregexp_h
+ libunicode_table_h
+ quickjs_h
+ quickjs_c
+ cutils_c
+ libbf_c
+ libregexp_c
+ libunicode_c
+ "#ifdef CONFIG_QUICKJS_LIBC\n"
+ quickjs_libc_h
+ quickjs_libc_c
+ "#endif // CONFIG_QUICKJS_LIBC\n"
source = source.replace(/#include "quickjs-atom.h"/g, quickjs_atom_h)
source = source.replace(/#include "quickjs-opcode.h"/g, quickjs_opcode_h)
source = source.replace(/#include "libregexp-opcode.h"/g, libregexp_opcode_h)
source = source.replace(/#include "[^"]+"/g, "")
writeFile("quickjs-amalgam.c", source)
2 changes: 2 additions & 0 deletions quickjs-libc.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ extern char **environ;
#include "list.h"
#include "quickjs-libc.h"

#ifndef MAX_SAFE_INTEGER // already defined in amalgamation builds
#define MAX_SAFE_INTEGER (((int64_t) 1 << 53) - 1)
#endif

#ifndef QJS_NATIVE_MODULE_SUFFIX
#ifdef _WIN32
Expand Down

0 comments on commit ef3cd55

Please sign in to comment.