build.sh 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. #!/bin/sh
  2. # Build the vendored QuickJS interpreter (`qjs`) for the JS test harness
  3. # (tests/markdown/run.sh). Only the 8 C files the interpreter needs are
  4. # vendored, so we compile them directly rather than driving upstream's
  5. # Makefile (whose default target also builds qjsc, run-test262, examples
  6. # and a qjsc-generated repl.c rule we have no sources for).
  7. #
  8. # The build is skipped when a system `qjs` is already available; set
  9. # FORCE_BUILD_QJS=1 to build anyway.
  10. set -e
  11. cd "$(dirname "$0")"
  12. if command -v qjs >/dev/null 2>&1 && [ -z "$FORCE_BUILD_QJS" ]; then
  13. echo "[qjs] using system qjs: $(command -v qjs)"
  14. exit 0
  15. fi
  16. VERSION=$(cat VERSION)
  17. # The quotes are consumed by the shell: gcc ends up seeing the macro value
  18. # wrapped in literal double quotes, i.e. a valid C string literal.
  19. VERDEF='-DCONFIG_VERSION="'"$VERSION"'"'
  20. CFLAGS="-g -Wall -Wno-array-bounds -Wno-format-truncation -Wno-infinite-recursion -fwrapv -D_GNU_SOURCE $VERDEF -DHAVE_CLOSEFROM -O2"
  21. OBJS="quickjs dtoa libregexp libunicode cutils quickjs-libc qjs repl"
  22. rm -rf .obj
  23. mkdir -p .obj
  24. for base in $OBJS; do
  25. echo "[qjs] CC $base.c"
  26. gcc $CFLAGS -c -o ".obj/$base.o" "$base.c"
  27. done
  28. echo "[qjs] LD qjs"
  29. gcc -rdynamic -o qjs $(for base in $OBJS; do echo ".obj/$base.o"; done) -lm -lpthread -ldl
  30. echo "[qjs] built $(pwd)/qjs"