nuttx-apps/interpreters/mquickjs/Makefile
Huang Qi 73bc5cbcc6 interpreters: Add mquickjs JavaScript interpreter integration
Add complete integration for the MicroQuickJS JavaScript interpreter,
supporting both CMake and Make build systems with automatic source
acquisition.

Key features:
* FetchContent downloads mquickjs from bellard/mquickjs if local
  git repository is not available in interpreters/mquickjs/mquickjs/
* Builds mqjs_stdlib host tool to generate mqjs_stdlib.h and
  mquickjs_atom.h headers during build
* Creates libmquickjs library with proper header generation dependencies
  to prevent parallel build failures
* Provides mqjs NSH application for interactive JavaScript execution
* Configurable task priority and stack size via Kconfig options
  (INTERPRETERS_MQJS_PRIORITY, INTERPRETERS_MQJS_STACKSIZE)
* Supports both 32-bit and 64-bit architectures with appropriate build flags

Files added:
* CMakeLists.txt - CMake build configuration with FetchContent support
* Kconfig - Configuration options for interpreter features
* Make.defs - Make build definitions
* Makefile - Alternative Make-based build support
* .gitignore - Ignores generated files and local mquickjs source directory

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2026-01-07 09:44:19 +08:00

92 lines
3 KiB
Makefile

############################################################################
# apps/interpreters/mquickjs/Makefile
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
include $(APPDIR)/Make.defs
MQJS_UNPACK = mquickjs
MQJS_ARCHIVE = mquickjs-master.zip
MQJS_URL = https://github.com/bellard/mquickjs/archive/refs/heads/master.zip
# Determine target word size for header generation
ifeq ($(CONFIG_ARCH_64BIT),y)
MQJS_BUILD_FLAGS = -m64
else
MQJS_BUILD_FLAGS = -m32
endif
CSRCS = $(MQJS_UNPACK)/mquickjs.c \
$(MQJS_UNPACK)/dtoa.c \
$(MQJS_UNPACK)/libm.c \
$(MQJS_UNPACK)/cutils.c \
$(MQJS_UNPACK)/readline.c \
$(MQJS_UNPACK)/readline_tty.c
PROGNAME = mqjs
PRIORITY = $(CONFIG_INTERPRETERS_MQJS_PRIORITY)
STACKSIZE = $(CONFIG_INTERPRETERS_MQJS_STACKSIZE)
MODULE = $(CONFIG_INTERPRETERS_MQJS)
MAINSRC = $(MQJS_UNPACK)/mqjs.c
# Download archive
$(MQJS_ARCHIVE):
$(Q) echo "Downloading $(MQJS_ARCHIVE)"
$(Q) curl -L $(MQJS_URL) -o $(MQJS_ARCHIVE)
# Unpack archive
$(MQJS_UNPACK): $(MQJS_ARCHIVE)
$(Q) echo "Unpacking $(MQJS_ARCHIVE) to $(MQJS_UNPACK)"
$(Q) unzip -q -o $(MQJS_ARCHIVE)
$(Q) mv bellard-mquickjs-* $(MQJS_UNPACK)
$(Q) touch $(MQJS_UNPACK)
# Build host tool via upstream Makefile
$(MQJS_UNPACK)/mqjs_stdlib:
$(Q) echo "Building mquickjs host tool via upstream Makefile"
$(Q) rm -f $(MQJS_UNPACK)/mqjs_stdlib
$(Q) $(MAKE) -C $(MQJS_UNPACK) HOSTCC=$(HOSTCC) mqjs_stdlib
# Generate stdlib header using built host tool
$(MQJS_UNPACK)/mqjs_stdlib.h: $(MQJS_UNPACK)/mqjs_stdlib
$(Q) echo "Generating mquickjs stdlib header"
$(MQJS_UNPACK)/mqjs_stdlib $(MQJS_BUILD_FLAGS) > $@
# Generate atom header using built host tool
$(MQJS_UNPACK)/mquickjs_atom.h: $(MQJS_UNPACK)/mqjs_stdlib
$(Q) echo "Generating mquickjs atom header"
$(MQJS_UNPACK)/mqjs_stdlib -a $(MQJS_BUILD_FLAGS) > $@
# Download and unpack only if not a git repository
context:: $(MQJS_UNPACK)/mqjs_stdlib.h $(MQJS_UNPACK)/mquickjs_atom.h
# Clean up on distclean
distclean::
ifneq ($(wildcard $(MQJS_UNPACK)/.git),)
$(Q) $(MAKE) -C $(MQJS_UNPACK) clean
else
$(call DELDIR, $(MQJS_UNPACK))
endif
$(call DELFILE, $(MQJS_ARCHIVE))
# Dependencies
$(MQJS_UNPACK)/mquickjs.c: $(MQJS_UNPACK)/mquickjs_atom.h
include $(APPDIR)/Application.mk