From cf0b0a6dd1772c95de08caf8baa6c892fd042648 Mon Sep 17 00:00:00 2001 From: Gabriele Baldassarre Date: Tue, 26 May 2020 15:39:22 +0200 Subject: [PATCH] new recipe: sidreloc (#5027) --- .../sidreloc/additional-files/Makefile.am | 15 +++ .../ax_check_compile_flag.m4-dist | 53 ++++++++ .../sidreloc/additional-files/configure.ac | 52 ++++++++ .../sidreloc/patches/sidreloc-1.0.patchset | 126 ++++++++++++++++++ dev-util/sidreloc/sidreloc-1.0.recipe | 68 ++++++++++ 5 files changed, 314 insertions(+) create mode 100644 dev-util/sidreloc/additional-files/Makefile.am create mode 100644 dev-util/sidreloc/additional-files/ax_check_compile_flag.m4-dist create mode 100644 dev-util/sidreloc/additional-files/configure.ac create mode 100644 dev-util/sidreloc/patches/sidreloc-1.0.patchset create mode 100644 dev-util/sidreloc/sidreloc-1.0.recipe diff --git a/dev-util/sidreloc/additional-files/Makefile.am b/dev-util/sidreloc/additional-files/Makefile.am new file mode 100644 index 000000000..63677cf4e --- /dev/null +++ b/dev-util/sidreloc/additional-files/Makefile.am @@ -0,0 +1,15 @@ +bin_PROGRAMS = sidreloc +dist_sidreloc_SOURCES = sidreloc.c solver.c cpu.c reloc.h +notrans_dist_man1_MANS = sidreloc.1 + +sidreloc_CFLAGS=-Wall -std=c99 -O3 -DNDEBUG $(ENABLE_BSD) + +check_SCRIPTS = greptest.sh + +TESTS = $(check_SCRIPTS) + +greptest.sh: + @echo './sidreloc --version | grep "sidreloc @PACKAGE_VERSION@"' > greptest.sh + @chmod +x greptest.sh + +CLEANFILES = greptest.sh \ No newline at end of file diff --git a/dev-util/sidreloc/additional-files/ax_check_compile_flag.m4-dist b/dev-util/sidreloc/additional-files/ax_check_compile_flag.m4-dist new file mode 100644 index 000000000..bd753b34d --- /dev/null +++ b/dev-util/sidreloc/additional-files/ax_check_compile_flag.m4-dist @@ -0,0 +1,53 @@ +# =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_CHECK_COMPILE_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT]) +# +# DESCRIPTION +# +# Check whether the given FLAG works with the current language's compiler +# or gives an error. (Warnings, however, are ignored) +# +# ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on +# success/failure. +# +# If EXTRA-FLAGS is defined, it is added to the current language's default +# flags (e.g. CFLAGS) when the check is done. The check is thus made with +# the flags: "CFLAGS EXTRA-FLAGS FLAG". This can for example be used to +# force the compiler to issue an error when a bad flag is given. +# +# INPUT gives an alternative input source to AC_COMPILE_IFELSE. +# +# NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this +# macro in sync with AX_CHECK_{PREPROC,LINK}_FLAG. +# +# LICENSE +# +# Copyright (c) 2008 Guido U. Draheim +# Copyright (c) 2011 Maarten Bosmans +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 6 + +AC_DEFUN([AX_CHECK_COMPILE_FLAG], +[AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF +AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl +AC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR, [ + ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS + _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1" + AC_COMPILE_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])], + [AS_VAR_SET(CACHEVAR,[yes])], + [AS_VAR_SET(CACHEVAR,[no])]) + _AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags]) +AS_VAR_IF(CACHEVAR,yes, + [m4_default([$2], :)], + [m4_default([$3], :)]) +AS_VAR_POPDEF([CACHEVAR])dnl +])dnl AX_CHECK_COMPILE_FLAGS diff --git a/dev-util/sidreloc/additional-files/configure.ac b/dev-util/sidreloc/additional-files/configure.ac new file mode 100644 index 000000000..403a8b079 --- /dev/null +++ b/dev-util/sidreloc/additional-files/configure.ac @@ -0,0 +1,52 @@ +AC_PREREQ([2.69]) +AC_INIT([sidreloc], [1.0], [linus@linusakesson.net], , [http://www.linusakesson.net/software/sidreloc]) + +AC_CONFIG_MACRO_DIRS([m4]) + +AM_INIT_AUTOMAKE([foreign]) + +AC_CONFIG_SRCDIR([./cpu.c]) +AC_CONFIG_HEADERS([config.h]) + +# Checks for programs. +AC_PROG_CC +AC_PROG_INSTALL + +# Checks for header files. +AC_CHECK_HEADERS([stdint.h stdlib.h string.h stdarg.h err.h errno.h]) + +AC_SEARCH_LIBS([err], [bsd]) +AC_SEARCH_LIBS([errx], [bsd]) + +# Enable BSD extensions +AX_CHECK_COMPILE_FLAG([-D_DEFAULT_SOURCE], AC_SUBST([ENABLE_BSD], [-D_DEFAULT_SOURCE])) + +AC_DEFINE_UNQUOTED([RELEASE], ["$PACKAGE_VERSION"], [convenience define used for release number]) + +# Checks for typedefs, structures, and compiler characteristics. +AC_C_INLINE +AC_TYPE_INT8_T +AC_TYPE_UINT16_T +AC_TYPE_UINT8_T + +# Checks for library functions. +AC_FUNC_MALLOC +AC_CHECK_FUNCS([memset err errx]) + +AC_CONFIG_FILES([Makefile]) +AC_OUTPUT + +echo \ +"------------------------------------------------- + +${PACKAGE_NAME} Version ${PACKAGE_VERSION} + +Prefix: '${prefix}'. +Compiler: '${CC} ${CFLAGS} ${CPPFLAGS}' + +Now type 'make @<:@@:>@' + where the optional is: + all - build sidreloc binary + install - install everything + +--------------------------------------------------" \ No newline at end of file diff --git a/dev-util/sidreloc/patches/sidreloc-1.0.patchset b/dev-util/sidreloc/patches/sidreloc-1.0.patchset new file mode 100644 index 000000000..57d928eff --- /dev/null +++ b/dev-util/sidreloc/patches/sidreloc-1.0.patchset @@ -0,0 +1,126 @@ +From eebb03a681273e699f09162aa8d2b670f093a74a Mon Sep 17 00:00:00 2001 +From: Gabriele Baldassarre +Date: Tue, 26 May 2020 08:17:32 +0000 +Subject: More general error handling + + +diff --git a/reloc.h b/reloc.h +index bc18e52..ff9930c 100644 +--- a/reloc.h ++++ b/reloc.h +@@ -1,10 +1,16 @@ + #ifndef __RELOC_H + #define __RELOC_H + ++#ifdef HAVE_CONFIG_H ++# include ++#endif ++ + #include + #include + ++#ifndef HAVE_CONFIG_H + #define RELEASE "1.0" ++#endif + + /* Represent bytes as 8-bit values tagged with meta-information. */ + /* List nodes (struct source) are arena-allocated; no need to track the references. */ +diff --git a/sidreloc.c b/sidreloc.c +index 7714af5..f6d69f2 100644 +--- a/sidreloc.c ++++ b/sidreloc.c +@@ -20,15 +20,23 @@ + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + ++#include "reloc.h" ++ + #include + #include + #include + #include +-#include + #include + #include + +-#include "reloc.h" ++#ifdef HAVE_ERR_H ++#include ++#endif ++ ++#ifndef HAVE_ERRX ++#include ++#include ++#endif + + struct sidheader { + uint8_t rsid; +@@ -73,6 +81,34 @@ static int nmi_reported; + + static struct core oldcore, newcore; + ++#ifndef HAVE_ERRX ++/* Some posix haven't this error function ++ so, we define a rough equivalent */ ++static void errx(int eval, const char *fmt, ...){ ++ va_list arglist; ++ va_start(arglist, fmt); ++ fprintf(stderr,"%s: ", "sidreloc"); ++ vfprintf(stderr,fmt, arglist); ++ fprintf(stderr,"\n"); ++ va_end(arglist); ++ exit(eval); ++} ++#endif ++ ++#ifndef HAVE_ERR ++/* Some posix haven't this error function ++ so, we define a rough equivalent */ ++static void err(int eval, const char *fmt, ...){ ++ va_list arglist; ++ va_start(arglist, fmt); ++ fprintf(stderr, " %s: ", "sidreloc"); ++ vfprintf(stderr, fmt, arglist); ++ fprintf(stderr, ": %s\n", strerror(errno)); ++ va_end(arglist); ++ exit(eval); ++} ++#endif ++ + static int readheader(struct sidheader *head, uint8_t *data, int filesize) { + if(filesize <= 0x80) return 1; + if(data[0] == 'P') { +@@ -817,3 +853,4 @@ int main(int argc, char **argv) { + + return RET_SUCCESS | exitbits; + } ++ +diff --git a/solver.c b/solver.c +index 7b9fcb6..5323add 100644 +--- a/solver.c ++++ b/solver.c +@@ -20,15 +20,19 @@ + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + ++#include "reloc.h" ++ + #include + #include + #include + #include + #include ++ ++#ifdef HAVE_ERR_H + #include +-#include ++#endif + +-#include "reloc.h" ++#include + + #define HASHSIZE 8192 + +-- +2.26.0 + diff --git a/dev-util/sidreloc/sidreloc-1.0.recipe b/dev-util/sidreloc/sidreloc-1.0.recipe new file mode 100644 index 000000000..b271c1a29 --- /dev/null +++ b/dev-util/sidreloc/sidreloc-1.0.recipe @@ -0,0 +1,68 @@ +SUMMARY="Tool for relocating SID tunes" +DESCRIPTION="Sidreloc is a tool for relocating SID tunes any number of whole pages, \ +using a novel but remarkably simple algorithm. It can also relocate \ +all zero-page variables used by the tune." +HOMEPAGE="https://www.linusakesson.net/software/sidreloc/index.php" +COPYRIGHT="2012-2020 Linus Akesson + 2005-2020 Ian Piumarta" +LICENSE="MIT" +REVISION="1" +SOURCE_URI="https://hd0.linusakesson.net/files/sidreloc-$portVersion.tgz" +CHECKSUM_SHA256="8ca55fb4886bda2a499f837e2f9ffd0a4b7217ee7bb1907ceed9e87ef6157bf6" + +PATCHES="sidreloc-$portVersion.patchset" +ADDITIONAL_FILES=" + configure.ac + Makefile.am + ax_check_compile_flag.m4-dist + " + +ARCHITECTURES="!x86_gcc2 x86_64 ?arm ?ppc ?sparc" +SECONDARY_ARCHITECTURES="x86" + +commandSuffix=$secondaryArchSuffix +commandBinDir=$binDir +if [ "$targetArchitecture" = x86_gcc2 ]; then + commandSuffix= + commandBinDir=$prefix/bin +fi + +PROVIDES=" + sidreloc$secondaryArchSuffix = $portVersion + cmd:sidreloc$commandSuffix = $portVersion + " +REQUIRES=" + haiku$secondaryArchSuffix + " + +BUILD_REQUIRES=" + haiku${secondaryArchSuffix}_devel + " +BUILD_PREREQUIRES=" + cmd:aclocal + cmd:autoreconf + cmd:gcc$secondaryArchSuffix + cmd:make + " + +BUILD() +{ + cp -r "$portDir"/additional-files/configure.ac . + cp -r "$portDir"/additional-files/Makefile.am . + + mkdir -p ./m4 + cp -r "$portDir"/additional-files/ax_check_compile_flag.m4-dist ./m4/ax_check_compile_flag.m4 + + autoreconf --force --install --verbose + runConfigure --omit-dirs binDir ./configure --bindir="$commandBinDir" + make $jobArgs +} + +INSTALL() +{ + make install +} + +TEST(){ + make check +} \ No newline at end of file