new package: mercury (#8418)

This commit is contained in:
xtkoba 2022-01-06 00:14:44 +09:00 committed by GitHub
parent 9e06bda51f
commit 0613596c3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 193 additions and 0 deletions

67
packages/mercury/build.sh Normal file
View File

@ -0,0 +1,67 @@
TERMUX_PKG_HOMEPAGE=https://www.mercurylang.org/
TERMUX_PKG_DESCRIPTION="A logic/functional programming language"
TERMUX_PKG_LICENSE="GPL-2.0, LGPL-2.0"
TERMUX_PKG_MAINTAINER="@termux"
TERMUX_PKG_VERSION=20.06.1
TERMUX_PKG_SRCURL=https://dl.mercurylang.org/release-${TERMUX_PKG_VERSION:0:5}/mercury-srcdist-${TERMUX_PKG_VERSION}.tar.gz
TERMUX_PKG_SHA256=ef093ae81424c4f3fe696eff9aefb5fb66899e11bb17ae0326adfb70d09c1c1f
TERMUX_PKG_BUILD_IN_SRC=true
TERMUX_PKG_HOSTBUILD=true
TERMUX_PKG_EXTRA_CONFIGURE_ARGS="
--disable-csharp-grade
--disable-erlang-grade
--disable-java-grade
--disable-debug-grades
--disable-par-grades
--disable-prof-grades
--disable-trail-grades
mercury_cv_sigaction_field=sa_sigaction
mercury_cv_sigcontext_struct_2arg=no
mercury_cv_sigcontext_struct_3arg=no
mercury_cv_pc_access=no
mercury_cv_siginfo_t=yes
mercury_cv_is_bigender=no
mercury_cv_is_littleender=yes
mercury_cv_can_do_pending_io=yes
mercury_cv_gcc_labels=yes
mercury_cv_asm_labels=yes
mercury_cv_gcc_model_fast=no
mercury_cv_gcc_model_reg=no
mercury_cv_cannot_use_structure_assignment=no
"
TERMUX_PKG_EXTRA_MAKE_ARGS="THREAD_LIBS="
termux_step_host_build() {
find $TERMUX_PKG_SRCDIR -mindepth 1 -maxdepth 1 -exec cp -a \{\} ./ \;
./configure \
CC="gcc -m${TERMUX_ARCH_BITS}" CXX="g++ -m${TERMUX_ARCH_BITS}" \
$TERMUX_PKG_EXTRA_CONFIGURE_ARGS
make -j $TERMUX_MAKE_PROCESSES
}
termux_step_pre_configure() {
_BUILD_UTIL=$TERMUX_PKG_HOSTBUILD_DIR/util
_BUILD_COMPILER=$TERMUX_PKG_HOSTBUILD_DIR/compiler
export MERCURY_MKINIT=$_BUILD_UTIL/mkinit
export MERCURY_DEMANGLER=$_BUILD_UTIL/mdemangle
export MERCURY_COMPILER=$_BUILD_COMPILER/mercury_compile
find "$TERMUX_PKG_SRCDIR" -name '*.c' -o -name '*.m' | \
xargs -n 1 sed -i \
-e 's:"/tmp:"'$TERMUX_PREFIX'/tmp:g' \
-e 's:"/var/tmp:"'$TERMUX_PREFIX'/tmp:g'
}
termux_step_post_configure() {
cp $TERMUX_PKG_BUILDER_DIR/sys_sem.c ./
$CC $CPPFLAGS $CFLAGS -c sys_sem.c
rm -f libsys_sem.a
$AR cru libsys_sem.a sys_sem.o
local lib=$TERMUX_PREFIX/lib/mercury/lib
install -Dm600 -t $lib libsys_sem.a
sed -i -e 's:^\(LINKER_POST_FLAGS=.*\)"$:\1 '"$lib"'/libsys_sem.a":g' \
$TERMUX_PKG_SRCDIR/scripts/ml
sed -i -e 's,\([^A-Za-z0-9_]PATH=\)\.\.,\1'$_BUILD_UTIL':..,g' \
$TERMUX_PKG_SRCDIR/Mmakefile
}

View File

@ -0,0 +1,11 @@
--- a/compiler/libs.md4.c
+++ b/compiler/libs.md4.c
@@ -52,7 +52,7 @@
static void mdfour_begin(struct mdfour *md);
static void mdfour_update(struct mdfour *md, const unsigned char *in, int n);
static void mdfour_tail(struct mdfour *m, const unsigned char *in, int n);
-static void mdfour_result(const struct mdfour *md, unsigned char out[12]);
+static void mdfour_result(const struct mdfour *md, unsigned char *out);

View File

@ -0,0 +1,18 @@
--- a/compiler/make.build.c
+++ b/compiler/make.build.c
@@ -128,6 +128,15 @@
#include <pthread.h>
#define MC_HAVE_JOBCTL_IPC 1
+ #elif defined(__ANDROID__)
+ #include <linux/sem.h>
+ #define semid_ds semid64_ds
+int semctl(int, int, int, ...);
+int semget(key_t, int, int);
+int semop(int, struct sembuf *, size_t);
+
+ #define MC_USE_SYSV_SEMAPHORE 1
+ #define MC_HAVE_JOBCTL_IPC 1
#elif defined(MR_HAVE_SYS_SEM_H)
#include <sys/sem.h>

View File

@ -0,0 +1,18 @@
--- a/compiler/make.build.m
+++ b/compiler/make.build.m
@@ -612,6 +612,15 @@
#include <pthread.h>
#define MC_HAVE_JOBCTL_IPC 1
+ #elif defined(__ANDROID__)
+ #include <linux/sem.h>
+ #define semid_ds semid64_ds
+int semctl(int, int, int, ...);
+int semget(key_t, int, int);
+int semop(int, struct sembuf *, size_t);
+
+ #define MC_USE_SYSV_SEMAPHORE 1
+ #define MC_HAVE_JOBCTL_IPC 1
#elif defined(MR_HAVE_SYS_SEM_H)
#include <sys/sem.h>

View File

@ -0,0 +1,79 @@
/*
* Copyright (C) 2016 The Android Open Source Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <linux/sem.h>
#include <stdarg.h>
#include <sys/syscall.h>
#include <unistd.h>
#pragma GCC visibility push(hidden)
int semtimedop(int id, struct sembuf* ops, size_t op_count, const struct timespec* ts) {
#if defined(SYS_semtimedop)
return syscall(SYS_semtimedop, id, ops, op_count, ts);
#else
return syscall(SYS_ipc, SEMTIMEDOP, id, op_count, 0, ops, ts);
#endif
}
union semun {
int val;
struct semid_ds *buf;
unsigned short *array;
} semu;
int semctl(int id, int num, int cmd, ...) {
#if !defined(__LP64__)
// Annoyingly, the kernel requires this for 32-bit but rejects it for 64-bit.
cmd |= IPC_64;
#endif
va_list ap;
va_start(ap, cmd);
union semun arg = va_arg(ap, union semun);
va_end(ap);
#if defined(SYS_semctl)
return syscall(SYS_semctl, id, num, cmd, arg);
#else
return syscall(SYS_ipc, SEMCTL, id, num, cmd, &arg, 0);
#endif
}
int semget(key_t key, int n, int flags) {
#if defined(SYS_semget)
return syscall(SYS_semget, key, n, flags);
#else
return syscall(SYS_ipc, SEMGET, key, n, flags, 0, 0);
#endif
}
int semop(int id, struct sembuf* ops, size_t op_count) {
return semtimedop(id, ops, op_count, NULL);
}
#pragma GCC visibility pop