1SUMMARY = "SpiderMonkey is Mozilla's JavaScript engine written in C/C++"
2HOMEPAGE = "https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey"
3LICENSE = "MPL-2.0"
4LIC_FILES_CHKSUM = "file://LICENSE;md5=dc9b6ecd19a14a54a628edaaf23733bf"
5
6SRC_URI = " \
7    https://archive.mozilla.org/pub/firefox/releases/${PV}esr/source/firefox-${PV}esr.source.tar.xz \
8    file://0001-rust.configure-Skip-all-target-manipulations.patch \
9    file://0002-build-do-not-use-autoconf-s-config.sub-to-canonicali.patch \
10    file://0003-Do-not-check-binaries-after-build.patch \
11    file://0004-Cargo.toml-do-not-abort-on-panic.patch \
12    file://0005-Fixup-compatibility-of-mozbuild-with-Python-3.10.patch \
13    file://0006-use-asm-sgidefs.h.patch \
14    file://0007-fix-musl-build.patch \
15    file://0008-riscv.patch \
16    file://0009-riscv-Disable-atomic-operations.patch \
17    file://0010-riscv-Set-march-correctly.patch \
18    file://0011-replace-include-by-code-to-fix-arm-build.patch \
19    file://0012-Add-SharedArrayRawBufferRefs-to-public-API.patch \
20    file://0013-util.configure-fix-one-occasionally-reproduced-confi.patch \
21    file://0014-rewrite-cargo-host-linker-in-python3.patch \
22"
23
24SRC_URI[sha256sum] = "a4438d84d95171a6d4fea9c9f02c2edbf0475a9c614d968ebe2eedc25a672151"
25S = "${WORKDIR}/firefox-${@d.getVar("PV").replace("esr", "")}"
26
27DEPENDS = " \
28    autoconf-2.13-native \
29    icu-native \
30    icu \
31    cargo-native \
32    zlib \
33    python3-six \
34    python3-six-native \
35"
36
37inherit autotools pkgconfig rust python3native siteinfo
38
39JIT ?= ""
40JIT:mipsarch = "--disable-jit"
41
42EXTRA_OECONF = " \
43    --target=${TARGET_SYS} \
44    --host=${BUILD_SYS} \
45    --prefix=${prefix} \
46    --libdir=${libdir} \
47    --x-includes=${STAGING_INCDIR} \
48    --x-libraries=${STAGING_LIBDIR} \
49    --without-system-icu \
50    --disable-tests --disable-strip --disable-optimize \
51    --disable-jemalloc \
52    --with-system-icu \
53    ${@bb.utils.contains('DISTRO_FEATURES', 'ld-is-gold', "--enable-gold", '--disable-gold', d)} \
54    ${JIT} \
55"
56# Note: Python with mozilla build is a mess: E.g: python-six: to get an error
57# free configure we need:
58# * python3-six-native in DEPENDS
59# * python3-six in DEPENDS
60# * path to python-six shipped by mozilla in PYTHONPATH
61prepare_python_and_rust() {
62    if [ ! -f ${B}/PYTHONPATH ]; then
63        oldpath=`pwd`
64        cd ${S}
65        # Add mozjs python-modules necessary
66        PYTHONPATH="${S}/build:${S}/config"
67        PYTHONPATH="$PYTHONPATH:${S}/third_party/python/distro:${S}/third_party/python/jsmin"
68        PYTHONPATH="$PYTHONPATH:${S}/third_party/python/pytoml:${S}/third_party/python/six"
69        PYTHONPATH="$PYTHONPATH:${S}/third_party/python/pyyaml/lib3:${S}/third_party/python/which"
70        for sub_dir in python testing/mozbase; do
71            for module_dir in `ls $sub_dir -1`;do
72                [ $module_dir = "virtualenv" ] && continue
73                if [ -d "${S}/$sub_dir/$module_dir" ];then
74                    PYTHONPATH="$PYTHONPATH:${S}/$sub_dir/$module_dir"
75                fi
76            done
77        done
78        # looks odd but it's huge and we want to see what's in there
79        echo "$PYTHONPATH" > ${B}/PYTHONPATH
80        cd "$oldpath"
81    fi
82
83    export PYTHONPATH=`cat ${B}/PYTHONPATH`
84
85    export RUST_TARGET_PATH="${RUST_TARGET_PATH}"
86    export RUST_TARGET="${TARGET_SYS}"
87    export RUSTFLAGS="${RUSTFLAGS}"
88}
89
90export HOST_CC = "${BUILD_CC}"
91export HOST_CXX = "${BUILD_CXX}"
92export HOST_CFLAGS = "${BUILD_CFLAGS}"
93export HOST_CPPFLAGS = "${BUILD_CPPFLAGS}"
94export HOST_CXXFLAGS = "${BUILD_CXXFLAGS}"
95# otherwise we are asked for yasm...
96export AS = "${CC}"
97
98CPPFLAGS:append:mips:toolchain-clang = " -fpie"
99CPPFLAGS:append:mipsel:toolchain-clang = " -fpie"
100
101do_configure() {
102    prepare_python_and_rust
103
104    cd ${S}/js/src
105    autoconf213 --macrodir=${STAGING_DATADIR_NATIVE}/autoconf213 old-configure.in > old-configure
106
107    cd ${B}
108    # * use of /tmp can causes problems on heavily loaded hosts
109    # * with mozjs-78 we get without:
110    # | Path specified in LOCAL_INCLUDES (..) resolves to the topsrcdir or topobjdir (<tmpdir>/oe-core-glibc/work/cortexa72-mortsgna-linux/mozjs-78/78.15.0-r0/firefox-78.15.0/js/src), which is not allowed
111    mkdir -p "${B}/lcl_tmp"
112    TMPDIR="${B}/lcl_tmp"  CFLAGS="${CFLAGS}" CXXFLAGS="${CXXFLAGS}" ${S}/js/src/configure ${EXTRA_OECONF}
113
114    # inspired by what fedora [1] does: for big endian rebuild icu dat
115    # this avoids gjs qemu crash on mips at gir creation
116    # [1] https://src.fedoraproject.org/rpms/mozjs78/blob/rawhide/f/mozjs78.spec
117    if [ ${@oe.utils.conditional('SITEINFO_ENDIANNESS', 'le', 'little', 'big', d)} = "big" -a ! -e ${S}/config/external/icu/data/icudt67b.dat ]; then
118        echo "Do big endian icu dat-convert..."
119        icupkg -tb ${S}/config/external/icu/data/icudt67l.dat ${S}/config/external/icu/data/icudt67b.dat
120        rm -f ${S}/config/external/icu/data/icudt*l.dat
121    fi
122}
123
124do_compile:prepend() {
125    prepare_python_and_rust
126}
127
128do_install:prepend() {
129    prepare_python_and_rust
130}
131
132do_install:append() {
133    # tidy up installation
134    chmod -x ${D}${libdir}/pkgconfig/*.pc
135    sed -i 's:\x24{includedir}/mozjs-78/js/RequiredDefines.h:js/RequiredDefines.h:g' ${D}${libdir}/pkgconfig/*.pc
136
137    rm -f ${D}${libdir}/libjs_static.ajs
138}
139
140ARM_INSTRUCTION_SET:armv5 = "arm"
141ARM_INSTRUCTION_SET:armv4 = "arm"
142
143DISABLE_STATIC = ""
144
145PACKAGES =+ "lib${BPN}"
146FILES:lib${BPN} += "${libdir}/lib*"
147