From ac1927d2ccae4ce4dcce64f4693492417d4f4882 Mon Sep 17 00:00:00 2001
From: Alessio Sergi <al3hex@gmail.com>
Date: Wed, 19 Jul 2017 13:13:38 +0200
Subject: [PATCH] mozjs38: fix multiple issues

Fix malformed library name and include directory to contain the major
version (libmozjs-38.so and /usr/include/mozjs-38).

Add major version to js shell, js-config and pkg-config files.

Patches from Debian.

Fix conflict with js-1.8.5.
---
 common/shlibs                                 |   2 +-
 srcpkgs/mozjs38/patches/copy-headers.patch    |  20 +++
 .../{configure.patch => fix-icu-check.patch}  |  11 +-
 srcpkgs/mozjs38/patches/gcc-alignment.patch   | 122 ++++++++++++++++++
 srcpkgs/mozjs38/patches/js-version.patch      |  65 ++++++++++
 .../mozjs38/patches/pkg-config-version.patch  |  22 ++++
 srcpkgs/mozjs38/template                      |  29 +----
 7 files changed, 244 insertions(+), 27 deletions(-)
 create mode 100644 srcpkgs/mozjs38/patches/copy-headers.patch
 rename srcpkgs/mozjs38/patches/{configure.patch => fix-icu-check.patch} (69%)
 create mode 100644 srcpkgs/mozjs38/patches/gcc-alignment.patch
 create mode 100644 srcpkgs/mozjs38/patches/js-version.patch
 create mode 100644 srcpkgs/mozjs38/patches/pkg-config-version.patch

diff --git a/common/shlibs b/common/shlibs
index 5fba2e24428..d46ec8976f4 100644
--- a/common/shlibs
+++ b/common/shlibs
@@ -2740,7 +2740,7 @@ libmutter-clutter-0.so mutter-3.24.0_1
 libmutter-cogl-path-0.so mutter-3.24.0_1
 libmutter-cogl-0.so mutter-3.24.0_1
 libmutter-cogl-pango-0.so mutter-3.24.0_1
-libmozjs-.so mozjs38-38.8.0_1
+libmozjs-38.so mozjs38-38.8.0_4
 libostree-1.so.1 libostree-2017.3_1
 librhash.so.0 rhash-1.3.4_1
 libserialport.so.0 libserialport-0.1.1_1
diff --git a/srcpkgs/mozjs38/patches/copy-headers.patch b/srcpkgs/mozjs38/patches/copy-headers.patch
new file mode 100644
index 00000000000..7f352a795c8
--- /dev/null
+++ b/srcpkgs/mozjs38/patches/copy-headers.patch
@@ -0,0 +1,20 @@
+Description: Copy headers on install instead of symlinking
+Author: Rico Tzschichholz <ricotz@ubuntu.com>
+Forwarded: no
+Last-Update: 2014-10-29
+
+---
+
+Index: b/python/mozbuild/mozbuild/backend/recursivemake.py
+===================================================================
+--- a/python/mozbuild/mozbuild/backend/recursivemake.py
++++ b/python/mozbuild/mozbuild/backend/recursivemake.py
+@@ -796,7 +796,7 @@
+             return
+ 
+         for source, dest, _ in self._walk_hierarchy(obj, exports):
+-            self._install_manifests['dist_include'].add_symlink(source, dest)
++            self._install_manifests['dist_include'].add_copy(source, dest)
+ 
+             if not os.path.exists(source):
+                 raise Exception('File listed in EXPORTS does not exist: %s' % source)
diff --git a/srcpkgs/mozjs38/patches/configure.patch b/srcpkgs/mozjs38/patches/fix-icu-check.patch
similarity index 69%
rename from srcpkgs/mozjs38/patches/configure.patch
rename to srcpkgs/mozjs38/patches/fix-icu-check.patch
index a992af1d877..873697d18f2 100644
--- a/srcpkgs/mozjs38/patches/configure.patch
+++ b/srcpkgs/mozjs38/patches/fix-icu-check.patch
@@ -1,6 +1,11 @@
---- js/src/configure	2017-03-21 06:18:29.372463084 -0600
-+++ js/src/configure	2017-03-21 06:27:37.546371605 -0600
-@@ -15906,7 +15906,7 @@
+Add bracket for sed 4.3 compliance
+
+Based on upstream fix by Daniel Stenberg in 09 jan 2017
+See: https://hg.mozilla.org/mozilla-central/rev/ebcbf47a83e7
+
+--- a/js/src/configure	2017-02-21 16:56:42.350105741 -0300
++++ b/js/src/configure	2017-02-21 17:33:13.183493978 -0300
+@@ -15231,7 +15231,7 @@
          fi
      fi
  
diff --git a/srcpkgs/mozjs38/patches/gcc-alignment.patch b/srcpkgs/mozjs38/patches/gcc-alignment.patch
new file mode 100644
index 00000000000..a3a57d54479
--- /dev/null
+++ b/srcpkgs/mozjs38/patches/gcc-alignment.patch
@@ -0,0 +1,122 @@
+--- a/js/src/jit/RegisterSets.h	2017-02-10 17:33:06.210702431 -0800
++++ b/js/src/jit/RegisterSets.h	2017-02-10 17:43:52.877514146 -0800
+@@ -7,7 +7,6 @@
+ #ifndef jit_RegisterSets_h
+ #define jit_RegisterSets_h
+ 
+-#include "mozilla/Alignment.h"
+ #include "mozilla/MathAlgorithms.h"
+ 
+ #include "jit/JitAllocPolicy.h"
+@@ -26,8 +25,8 @@
+     Code code_;
+ 
+   public:
+-    AnyRegister()
+-    { }
++    AnyRegister() = default;
++
+     explicit AnyRegister(Register gpr) {
+         code_ = gpr.code();
+     }
+@@ -156,7 +155,7 @@
+     }
+ #endif
+ 
+-    ValueOperand() {}
++    ValueOperand() = default;
+ };
+ 
+ // Registers to hold either either a typed or untyped value.
+@@ -165,46 +164,25 @@
+     // Type of value being stored.
+     MIRType type_;
+ 
+-    // Space to hold either an AnyRegister or a ValueOperand.
+     union U {
+-        mozilla::AlignedStorage2<AnyRegister> typed;
+-        mozilla::AlignedStorage2<ValueOperand> value;
++        AnyRegister typed;
++        ValueOperand value;
+     } data;
+ 
+-    AnyRegister& dataTyped() {
+-        MOZ_ASSERT(hasTyped());
+-        return *data.typed.addr();
+-    }
+-    ValueOperand& dataValue() {
+-        MOZ_ASSERT(hasValue());
+-        return *data.value.addr();
+-    }
+-
+-    AnyRegister dataTyped() const {
+-        MOZ_ASSERT(hasTyped());
+-        return *data.typed.addr();
+-    }
+-    const ValueOperand& dataValue() const {
+-        MOZ_ASSERT(hasValue());
+-        return *data.value.addr();
+-    }
+-
+   public:
+ 
+-    TypedOrValueRegister()
+-      : type_(MIRType_None)
+-    {}
++    TypedOrValueRegister() = default;
+ 
+     TypedOrValueRegister(MIRType type, AnyRegister reg)
+       : type_(type)
+     {
+-        dataTyped() = reg;
++        data.typed = reg;
+     }
+ 
+     MOZ_IMPLICIT TypedOrValueRegister(ValueOperand value)
+       : type_(MIRType_Value)
+     {
+-        dataValue() = value;
++        data.value = value;
+     }
+ 
+     MIRType type() const {
+@@ -220,11 +198,13 @@
+     }
+ 
+     AnyRegister typedReg() const {
+-        return dataTyped();
++        MOZ_ASSERT(hasTyped());
++        return data.typed;
+     }
+ 
+     ValueOperand valueReg() const {
+-        return dataValue();
++        MOZ_ASSERT(hasValue());
++        return data.value;
+     }
+ 
+     AnyRegister scratchReg() {
+@@ -240,19 +220,18 @@
+     // Whether a constant value is being stored.
+     bool constant_;
+ 
+-    // Space to hold either a Value or a TypedOrValueRegister.
+     union U {
+-        mozilla::AlignedStorage2<Value> constant;
+-        mozilla::AlignedStorage2<TypedOrValueRegister> reg;
++        Value constant;
++        TypedOrValueRegister reg;
+     } data;
+ 
+     Value& dataValue() {
+         MOZ_ASSERT(constant());
+-        return *data.constant.addr();
++        return data.constant;
+     }
+     TypedOrValueRegister& dataReg() {
+         MOZ_ASSERT(!constant());
+-        return *data.reg.addr();
++        return data.reg;
+     }
+ 
+   public:
diff --git a/srcpkgs/mozjs38/patches/js-version.patch b/srcpkgs/mozjs38/patches/js-version.patch
new file mode 100644
index 00000000000..cc6b3d35b32
--- /dev/null
+++ b/srcpkgs/mozjs38/patches/js-version.patch
@@ -0,0 +1,65 @@
+# HG changeset patch
+# Parent 4732a0e5d22bc7e5c1f1ace7a182d537d9cc2c6a
+Add major version to shell and js-config filenames.
+Author: Rico Tzschichholz <ricotz@ubuntu.com>
+Forwarded: no
+Last-Update: 2014-10-29
+
+---
+diff --git a/js/src/configure b/js/src/configure
+--- a/js/src/configure
++++ b/js/src/configure
+@@ -1696,8 +1696,13 @@
+ MOZJS_PATCH_VERSION=`echo $MOZILLA_VERSION | sed "s|^[0-9]*\.[0-9]*[^0-9]*||"`
+ IS_ALPHA=`echo $MOZILLA_VERSION | grep '[ab]'`
+ 
++if test -n "$JS_STANDALONE"; then
++JS_SHELL_NAME=js$MOZJS_MAJOR_VERSION
++JS_CONFIG_NAME=js$MOZJS_MAJOR_VERSION-config
++else
+ JS_SHELL_NAME=js
+ JS_CONFIG_NAME=js-config
++fi
+ 
+ 
+ if test -n "$IS_ALPHA"; then
+
+diff --git a/js/src/configure.in b/js/src/configure.in
+--- a/js/src/configure.in
++++ b/js/src/configure.in
+@@ -234,16 +234,13 @@ MOZJS_MINOR_VERSION=`echo $MOZILLA_VERSI
+ MOZJS_PATCH_VERSION=`echo $MOZILLA_VERSION | sed "s|^[0-9]*\.[0-9]*[^0-9]*||"`
+ IS_ALPHA=`echo $MOZILLA_VERSION | grep '[ab]'`
+ 
+-dnl XXX in a temporary bid to avoid developer anger at renaming files
+-dnl XXX before "js" symlinks exist, don't change names.
+-dnl
+-dnl if test -n "$JS_STANDALONE"; then
+-dnl JS_SHELL_NAME=js$MOZJS_MAJOR_VERSION
+-dnl JS_CONFIG_NAME=js$MOZJS_MAJOR_VERSION-config
+-dnl else
++if test -n "$JS_STANDALONE"; then
++JS_SHELL_NAME=js$MOZJS_MAJOR_VERSION
++JS_CONFIG_NAME=js$MOZJS_MAJOR_VERSION-config
++else
+ JS_SHELL_NAME=js
+ JS_CONFIG_NAME=js-config
+-dnl fi
++fi
+ 
+ changequote([,])
+ if test -n "$IS_ALPHA"; then
+
+diff -r 80a9e64d75f5 js/src/Makefile.in
+--- a/js/src/Makefile.in        Wed Jun 25 15:11:42 2014 +0200
++++ b/js/src/Makefile.in        Sat Jul 05 14:08:38 2014 +0200
+@@ -273,6 +273,9 @@
+ SCRIPTS = $(JS_CONFIG_NAME)
+ SDK_BINARY = $(JS_CONFIG_NAME)
+ 
++$(JS_CONFIG_NAME): js-config
++	cp $^ $@
++
+ $(LIBRARY_NAME).pc: js.pc
+ 	cp $^ $@
+ 
diff --git a/srcpkgs/mozjs38/patches/pkg-config-version.patch b/srcpkgs/mozjs38/patches/pkg-config-version.patch
new file mode 100644
index 00000000000..34a43d1f6df
--- /dev/null
+++ b/srcpkgs/mozjs38/patches/pkg-config-version.patch
@@ -0,0 +1,22 @@
+Add major version to pkg-config filename.
+Author: Rico Tzschichholz <ricotz@ubuntu.com>
+Forwarded: no
+Last-Update: 2015-05-04
+
+Index: b/js/src/Makefile.in
+===================================================================
+--- a/js/src/Makefile.in
++++ b/js/src/Makefile.in
+@@ -214,10 +214,10 @@
+ $(JS_CONFIG_NAME): js-config
+    cp $^ $@
+ 
+-$(LIBRARY_NAME).pc: js.pc
++$(JS_LIBRARY_NAME).pc: js.pc
+ 	cp $^ $@
+ 
+-install:: $(LIBRARY_NAME).pc
++install:: $(JS_LIBRARY_NAME).pc
+ 	$(SYSINSTALL) $^ $(DESTDIR)$(libdir)/pkgconfig
+ 
+ install:: js-config.h
diff --git a/srcpkgs/mozjs38/template b/srcpkgs/mozjs38/template
index 1baa19613d5..9551d3cc6e4 100644
--- a/srcpkgs/mozjs38/template
+++ b/srcpkgs/mozjs38/template
@@ -1,7 +1,7 @@
 # Template file for 'mozjs38'
 pkgname=mozjs38
 version=38.8.0
-revision=3
+revision=4
 wrksrc="mozilla-esr${version%.*.*}"
 build_wrksrc="js/src"
 build_style=gnu-configure
@@ -13,6 +13,7 @@ license="MPL-1.1, GPL-2, LGPL-2.1"
 maintainer="Juan RP <xtraeme@voidlinux.eu>"
 distfiles="${MOZILLA_SITE}/firefox/releases/${version}esr/source/firefox-${version}esr.source.tar.bz2"
 checksum=9475adcee29d590383c4885bc5f958093791d1db4302d694a5d2766698f59982
+patch_args="-Np1"
 nopie=yes
 
 # Flags for gcc6.3 conceived by Arch Linux developers
@@ -30,34 +31,16 @@ do_configure() {
 		_args+=" --target=$XBPS_CROSS_TRIPLET"
 	fi
 
-	SHELL=/bin/bash ./configure --prefix=/usr --enable-threadsafe \
-		--enable-system-ffi --with-system-icu --with-system-nspr \
-		${_args}
-}
-
-post_install() {
-
-	# Rename pkgconfig
-	mv ${PKGDESTDIR}/usr/lib/pkgconfig/js.pc ${PKGDESTDIR}/usr/lib/pkgconfig/mozjs-${version%.*.*}.pc
-
-	# Remove links
-	mv ${PKGDESTDIR}/usr/include/mozjs-/js-config.h ${PKGDESTDIR}/usr/include/
-	rm -rf ${PKGDESTDIR}/usr/include/mozjs-/*
-	mv ${PKGDESTDIR}/usr/include/js-config.h ${PKGDESTDIR}/usr/include/mozjs-/
-	cp -p ${wrksrc}/js/src/js.msg ${PKGDESTDIR}/usr/include/mozjs-/
-	cp -p ${wrksrc}/js/src/*.h ${PKGDESTDIR}/usr/include/mozjs-/
-	mkdir ${PKGDESTDIR}/usr/include/mozjs-/js/
-	cp -p ${wrksrc}/js/public/*.h ${PKGDESTDIR}/usr/include/mozjs-/js/
-	mkdir ${PKGDESTDIR}/usr/include/mozjs-/mozilla/
-	cp -p ${wrksrc}/mfbt/*.h ${PKGDESTDIR}/usr/include/mozjs-/mozilla/
+	SHELL=/bin/bash PYTHON=/usr/bin/python2 ./configure --prefix=/usr \
+		--enable-threadsafe --enable-system-ffi --with-system-zlib \
+		--with-system-icu --with-system-nspr ${_args}
 }
 
 mozjs38-devel_package() {
 	depends="nspr-devel ${sourcepkg}>=${version}_${revision}"
 	short_desc+=" - development files"
-	conflicts="js-devel>0" # /usr/bin/js-config
 	pkg_install() {
-		vmove usr/bin/js-config
+		vmove usr/bin/js38-config
 		vmove usr/include
 		vmove usr/lib/pkgconfig
 	}