From ae8472d0c889c4da7aa92132a55df05bb695bdb5 Mon Sep 17 00:00:00 2001 From: q66 Date: Thu, 28 Jan 2021 12:10:26 +0100 Subject: [PATCH] ghdl: add llvm backend and enable for all archs --- srcpkgs/ghdl-llvm | 1 + srcpkgs/ghdl-mcode | 1 + srcpkgs/ghdl/files/ghdl | 21 +++ srcpkgs/ghdl/patches/curdir.patch | 11 ++ srcpkgs/ghdl/patches/install-paths.patch | 164 +++++++++++++++++++++ srcpkgs/ghdl/patches/llvm11.patch | 10 ++ srcpkgs/ghdl/patches/musl.patch | 4 +- srcpkgs/ghdl/patches/respect-ldflags.patch | 34 +++++ srcpkgs/ghdl/template | 128 +++++++++++++++- 9 files changed, 369 insertions(+), 5 deletions(-) create mode 120000 srcpkgs/ghdl-llvm create mode 120000 srcpkgs/ghdl-mcode create mode 100755 srcpkgs/ghdl/files/ghdl create mode 100644 srcpkgs/ghdl/patches/curdir.patch create mode 100644 srcpkgs/ghdl/patches/install-paths.patch create mode 100644 srcpkgs/ghdl/patches/llvm11.patch create mode 100644 srcpkgs/ghdl/patches/respect-ldflags.patch diff --git a/srcpkgs/ghdl-llvm b/srcpkgs/ghdl-llvm new file mode 120000 index 00000000000..397362bd8e2 --- /dev/null +++ b/srcpkgs/ghdl-llvm @@ -0,0 +1 @@ +ghdl \ No newline at end of file diff --git a/srcpkgs/ghdl-mcode b/srcpkgs/ghdl-mcode new file mode 120000 index 00000000000..397362bd8e2 --- /dev/null +++ b/srcpkgs/ghdl-mcode @@ -0,0 +1 @@ +ghdl \ No newline at end of file diff --git a/srcpkgs/ghdl/files/ghdl b/srcpkgs/ghdl/files/ghdl new file mode 100755 index 00000000000..4a48ef91251 --- /dev/null +++ b/srcpkgs/ghdl/files/ghdl @@ -0,0 +1,21 @@ +#!/bin/sh +# Source: Debian +set -e + +backend="$GHDL_BACKEND" +bindir=$(dirname $0) + +if [ ! -x "${bindir}/ghdl-$backend" ]; then + if [ -x ${bindir}/ghdl-mcode ]; then + backend=mcode + elif [ -x ${bindir}/ghdl-gcc ]; then + backend=gcc + elif [ -x ${bindir}/ghdl-llvm ]; then + backend=llvm + else + echo >&2 "Error: No installed ghdl backend found. Terminating!" + exit 2 + fi +fi + +exec "${bindir}/ghdl-$backend" "$@" diff --git a/srcpkgs/ghdl/patches/curdir.patch b/srcpkgs/ghdl/patches/curdir.patch new file mode 100644 index 00000000000..12e7648e7d4 --- /dev/null +++ b/srcpkgs/ghdl/patches/curdir.patch @@ -0,0 +1,11 @@ +--- a/Makefile.in ++++ b/Makefile.in +@@ -44,7 +44,7 @@ + + INSTALL_PROGRAM=install -m 755 + INSTALL_DATA=install -m 644 +-PWD?=$(shell pwd) ++PWD=$(CURDIR) + DESTDIR= + bindir=$(prefix)/bin + libdir=$(prefix)/lib diff --git a/srcpkgs/ghdl/patches/install-paths.patch b/srcpkgs/ghdl/patches/install-paths.patch new file mode 100644 index 00000000000..f23b2f15102 --- /dev/null +++ b/srcpkgs/ghdl/patches/install-paths.patch @@ -0,0 +1,164 @@ +This is needed so that llvm and mcode backends can coexist. +Taken and adapted from Debian (simplified). + +Description: Patch installation paths for Debian packaging +Author: Andreas Bombe +Last-Update: 2020-03-28 +--- +This patch header follows DEP-3: http://dep.debian.net/deps/dep3/ +diff --git a/Makefile.in b/Makefile.in +index 9a6b1731..3aba6532 100644 +--- a/Makefile.in ++++ b/Makefile.in +@@ -26,6 +26,7 @@ prefix=@prefix@ + backend=@backend@ + libdirsuffix=@libdirsuffix@ + libdirreverse=@libdirreverse@ ++incdirsuffix=@incdirsuffix@ + EXEEXT=@EXEEXT@ + SOEXT=@SOEXT@ + PIC_FLAGS=@PIC_FLAGS@ +@@ -48,8 +49,8 @@ INSTALL_DATA=install -m 644 + PWD=$(CURDIR) + DESTDIR= + bindir=$(prefix)/bin +-libdir=$(prefix)/lib +-incdir=$(prefix)/include ++libdir=$(prefix)/$(libdirsuffix) ++incdir=$(prefix)/$(incdirsuffix) + MKDIR=mkdir + LN=ln -s + CP=cp +@@ -192,7 +193,7 @@ libs.vhdl.mcode: ghdl_mcode$(EXEEXT) + $(MAKE) -f $(srcdir)/libraries/Makefile.inc $(LIBVHDL_FLAGS_TO_PASS) GHDL=$(PWD)/ghdl_mcode$(EXEEXT) GHDL_FLAGS="" VHDL_COPY_OBJS=no vhdl.libs.all + + install.mcode.program: install.dirs ghdl_mcode$(EXEEXT) +- $(INSTALL_PROGRAM) ghdl_mcode$(EXEEXT) $(DESTDIR)$(bindir)/ghdl$(EXEEXT) ++ $(INSTALL_PROGRAM) ghdl_mcode$(EXEEXT) $(DESTDIR)$(bindir)/ghdl-mcode$(EXEEXT) + + uninstall.mcode.program: + $(RM) $(DESTDIR)$(bindir)/ghdl$(EXEEXT) +@@ -355,8 +356,8 @@ oread-llvm$(EXEEXT): force + LLVM_CONFIG="$(LLVM_CONFIG)" CXX="$(CXX)" + + install.llvm.program: install.dirs ghdl1-llvm$(EXEEXT) ghdl_llvm$(EXEEXT) +- $(INSTALL_PROGRAM) ghdl_llvm$(EXEEXT) $(DESTDIR)$(bindir)/ghdl$(EXEEXT) +- $(INSTALL_PROGRAM) ghdl1-llvm$(EXEEXT) $(DESTDIR)$(bindir)/ghdl1-llvm$(EXEEXT) ++ $(INSTALL_PROGRAM) ghdl_llvm$(EXEEXT) $(DESTDIR)$(bindir)/ghdl-llvm$(EXEEXT) ++ $(INSTALL_PROGRAM) ghdl1-llvm$(EXEEXT) $(DESTDIR)$(libdir)/ghdl1-llvm$(EXEEXT) + + uninstall.llvm.program: + $(RM) $(DESTDIR)$(bindir)/ghdl1-llvm$(EXEEXT) +diff --git a/configure b/configure +index ce052534..22e1335a 100755 +--- a/configure ++++ b/configure +@@ -34,6 +34,7 @@ MAKE=${MAKE:-make} + LDFLAGS= + prefix=/usr/local + libdirsuffix=lib/ghdl ++incdirsuffix=include + libdirreverse=../.. + gcc_src_dir= + llvm_config= +@@ -54,7 +55,7 @@ PIC_FLAGS=-fPIC + show_help=no + progname=$0 + +-subst_vars="CC CXX GNATMAKE MAKE CFLAGS LDFLAGS build srcdir abs_srcdir prefix backend libdirsuffix libdirreverse gcc_src_dir llvm_config llvm_be backtrace_lib build_mode EXEEXT SOEXT PIC_FLAGS default_pic enable_werror enable_checks enable_openieee enable_libghdl libghdl_version ghdl_version" ++subst_vars="CC CXX GNATMAKE MAKE CFLAGS LDFLAGS build srcdir abs_srcdir prefix backend libdirsuffix libdirreverse incdirsuffix gcc_src_dir llvm_config llvm_be backtrace_lib build_mode EXEEXT SOEXT PIC_FLAGS default_pic enable_werror enable_checks enable_openieee enable_libghdl libghdl_version ghdl_version" + + # Find srcdir + srcdir=`dirname $progname` +@@ -93,6 +94,8 @@ for opt do + ;; + --prefix=*) prefix="$optarg";; + --srcdir=*) srcdir="$optarg";; ++ --libdir=*) libdirsuffix="$optarg";; ++ --incdir=*) incdirsuffix="$optarg";; + --with-gcc=*) gcc_src_dir="$optarg"; backend=gcc;; + --with-llvm=*) + echo "--with-llvm is deprecated, use --with-llvm-config" +@@ -128,6 +131,8 @@ Usage: configure [options] + Options [defaults in brackets]: + --prefix=PREFIX install in PREFIX [$prefix] + --srcdir=SRCDIR source code path [$srcdir] ++ --libdir=LIBDIR lib dir path relative to PREFIX [$libdirsuffix] ++ --incdir=INCDIR C include dir path relative to PREFIX [$incdirsuffix] + --with-gcc=DIR use gcc backend from DIR + --with-llvm-config[=LLVM-CONFIG] use llvm backend [llvm-config] + --with-backtrace-lib=LIB.a link with libbacktrace LIB.a to display a +@@ -405,10 +410,11 @@ echo "Generate default_paths.ads" + sed -e "s%@COMPILER_GCC@%ghdl1-gcc$EXEEXT%" \ + -e "s%@COMPILER_DEBUG@%ghdl1-debug$EXEEXT%" \ + -e "s%@COMPILER_MCODE@%ghdl1-mcode$EXEEXT%" \ +- -e "s%@COMPILER_LLVM@%ghdl1-llvm$EXEEXT%" \ ++ -e "s%@COMPILER_LLVM@%lib/ghdl/llvm/ghdl1-llvm$EXEEXT%" \ + -e "s%@POST_PROCESSOR@%oread-$backend%" \ + -e "s%@INSTALL_PREFIX@%$prefix%" \ + -e "s%@LIB_PREFIX@%$libdirsuffix%" \ ++ -e "s%@INC_PREFIX@%$incdirsuffix%" \ + -e "s%@SOEXT@%$SOEXT%" \ + -e "s%@default_pic@%$default_pic%" \ + < $srcdir/src/ghdldrv/default_paths.ads.in > default_paths.ads +diff --git a/dist/gcc/Make-lang.in b/dist/gcc/Make-lang.in +index cca1e4df..37d95d20 100644 +--- a/dist/gcc/Make-lang.in ++++ b/dist/gcc/Make-lang.in +@@ -104,7 +104,9 @@ vhdl/default_paths.ads: Makefile + echo " Compiler_Llvm : constant String := \"\";" >> tmp-dpaths.ads + echo " Post_Processor : constant String := \"\";" >> tmp-dpaths.ads + echo " Lib_Prefix : constant String :=">> tmp-dpaths.ads +- echo " \"lib/ghdl\";" >> tmp-dpaths.ads ++ echo " \"lib/ghdl/gcc\";" >> tmp-dpaths.ads ++ echo " Inc_Prefix : constant String :=" >> tmp-dpaths.ads ++ echo " \"lib/ghdl/include\";" >> tmp-dpaths.ads + echo " Shared_Library_Extension : constant String :=">> tmp-dpaths.ads + echo " \"$(VHDL_SOEXT)\";" >> tmp-dpaths.ads + echo " Default_Pie : constant Boolean := False;" >> tmp-dpaths.ads +@@ -159,8 +161,8 @@ vhdl.install-plugin: + # Install the driver program as ghdl. + vhdl.install-common: ghdl$(exeext) ghdl1$(exeext) + -mkdir $(DESTDIR)$(bindir) +- -$(RM) $(DESTDIR)$(bindir)/ghdl$(exeext) +- $(INSTALL_PROGRAM) ghdl$(exeext) $(DESTDIR)$(bindir)/ghdl$(exeext) ++ -$(RM) $(DESTDIR)$(bindir)/ghdl-gcc$(exeext) ++ $(INSTALL_PROGRAM) ghdl$(exeext) $(DESTDIR)$(bindir)/ghdl-gcc$(exeext) + -mkdir $(DESTDIR)$(libdir) + -mkdir $(DESTDIR)$(libdir)/ghdl + $(INSTALL_DATA) ../libbacktrace/.libs/libbacktrace.a $(DESTDIR)$(libdir)/ghdl +diff --git a/src/ghdldrv/default_paths.ads.in b/src/ghdldrv/default_paths.ads.in +index ae321011..228c0696 100644 +--- a/src/ghdldrv/default_paths.ads.in ++++ b/src/ghdldrv/default_paths.ads.in +@@ -25,6 +25,8 @@ package Default_Paths is + "@INSTALL_PREFIX@"; + Lib_Prefix : constant String := + "@LIB_PREFIX@"; ++ Inc_Prefix : constant String := ++ "@INC_PREFIX@"; + + Compiler_Gcc : constant String := + "@COMPILER_GCC@"; +diff --git a/src/ghdldrv/ghdlvpi.adb b/src/ghdldrv/ghdlvpi.adb +index 295b7300..487eb0e6 100644 +--- a/src/ghdldrv/ghdlvpi.adb ++++ b/src/ghdldrv/ghdlvpi.adb +@@ -39,7 +39,7 @@ package body Ghdlvpi is + -- Compute install path + Ghdllocal.Set_Exec_Prefix_From_Program_Name; + +- return Ghdllocal.Exec_Prefix.all & Directory_Separator & "include"; ++ return Ghdllocal.Exec_Prefix.all & Directory_Separator & Inc_Prefix; + end Get_Vpi_Include_Dir; + + -- Return the lib directory. +@@ -50,7 +50,7 @@ package body Ghdlvpi is + Ghdllocal.Set_Exec_Prefix_From_Program_Name; + end if; + +- return Ghdllocal.Exec_Prefix.all & Directory_Separator & "lib"; ++ return Ghdllocal.Exec_Prefix.all & Directory_Separator & Lib_Prefix; + end Get_Vpi_Lib_Dir; + + -- Return the lib directory, but unixify the path (for a unix shell in diff --git a/srcpkgs/ghdl/patches/llvm11.patch b/srcpkgs/ghdl/patches/llvm11.patch new file mode 100644 index 00000000000..b2637d01bff --- /dev/null +++ b/srcpkgs/ghdl/patches/llvm11.patch @@ -0,0 +1,10 @@ +--- a/configure ++++ b/configure +@@ -279,6 +279,7 @@ if test $backend = llvm; then + check_version 7.0 $llvm_version || + check_version 8.0 $llvm_version || + check_version 9.0 $llvm_version || ++ check_version 11.0 $llvm_version || + false; then + echo "Debugging is not enabled with llvm $llvm_version" + llvm_be=llvm4-nodebug diff --git a/srcpkgs/ghdl/patches/musl.patch b/srcpkgs/ghdl/patches/musl.patch index f9c721fff97..298fba36ecd 100644 --- a/srcpkgs/ghdl/patches/musl.patch +++ b/srcpkgs/ghdl/patches/musl.patch @@ -1,5 +1,5 @@ ---- src/grt/config/jumps.c 2019-03-03 09:38:19.000000000 +0100 -+++ - 2019-04-29 12:58:54.717203690 +0200 +--- a/src/grt/config/jumps.c ++++ b/src/grt/config/jumps.c @@ -29,7 +29,7 @@ #include #include diff --git a/srcpkgs/ghdl/patches/respect-ldflags.patch b/srcpkgs/ghdl/patches/respect-ldflags.patch new file mode 100644 index 00000000000..61b27c4558a --- /dev/null +++ b/srcpkgs/ghdl/patches/respect-ldflags.patch @@ -0,0 +1,34 @@ +Partially adapted from Debian. Do not ignore LDFLAGS we set. +We do not want the -g part, as that is handled by xbps-src. + +--- a/Makefile.in ++++ b/Makefile.in +@@ -99,13 +99,14 @@ + #target=x86_64-apple-darwin + #target=i386-pc-mingw32 + ++SHLIB_FLAGS=$(LDFLAGS) + ifeq ($(SOEXT),.so) +-SHLIB_FLAGS=-Wl,-soname,$@ ++SHLIB_FLAGS+=-Wl,-soname,$@ + else ifeq ($(SOEXT),.dll) +-SHLIB_FLAGS= ++SHLIB_FLAGS+= + else ifeq ($(SOEXT),.dylib) + # Allow the use of -rpath in executable +-SHLIB_FLAGS=-Wl,-install_name,@rpath/$@ ++SHLIB_FLAGS+=-Wl,-install_name,@rpath/$@ + endif + + # Flags for libraries +--- a/configure ++++ b/configure +@@ -16,7 +16,7 @@ + CFLAGS=${CFLAGS:--g} + GNATMAKE=${GNATMAKE:-gnatmake} + MAKE=${MAKE:-make} +-LDFLAGS= ++LDFLAGS=${LDFLAGS} + prefix=/usr/local + libdirsuffix=lib/ghdl + incdirsuffix=include diff --git a/srcpkgs/ghdl/template b/srcpkgs/ghdl/template index 9e4baf3b68a..3f77c821fa9 100644 --- a/srcpkgs/ghdl/template +++ b/srcpkgs/ghdl/template @@ -1,15 +1,137 @@ # Template file for 'ghdl' +# +# We could also package the gcc backend, but that requires an entire gcc +# source tree being available and looks rather complicated, so for now +# only mcode (on x86) and llvm (everywhere) is done +# pkgname=ghdl reverts="20181129_1" version=0.37 revision=2 -archs="i686* x86_64*" build_style=configure -configure_args="--prefix=/usr" +configure_args="--prefix=/usr --srcdir=.. --incdir=lib/ghdl/include" makedepends="zlib-devel" -short_desc="VHDL 2008/93/87 simulator - mcode backend" +short_desc="VHDL 2008/93/87 simulator" maintainer="m3tav3rse " license="GPL-2.0-or-later" homepage="https://github.com/ghdl/ghdl" distfiles="https://github.com/ghdl/ghdl/archive/v${version}.tar.gz" checksum=3008616201cc3b0b596872e4ad59d8bc36e6ee3ff798bdce066828fbdad041e4 +nocross=yes +patch_args="-Np1" + +build_options="llvm mcode" +build_options_default="llvm" + +desc_option_llvm="Build the portable LLVM backend" +desc_option_mcode="Build the x86-only mcode backend" + +if [ "$build_option_mcode" ]; then + depends=" ghdl-mcode>=${version}_${revision}" +elif [ "$build_option_llvm" ]; then + depends=" ghdl-llvm>=${version}_${revision}" +fi + +case "$XBPS_TARGET_MACHINE" in + i686*|x86_64*) + build_options_default+=" mcode" + ;; + *) + if [ "$build_option_mcode" ]; then + broken="mcode backend only available on x86" + fi +esac + +if [ "$build_option_mcode" ]; then + subpackages+=" ghdl-mcode" +fi + +if [ "$build_option_llvm" ]; then + subpackages+=" ghdl-llvm" + makedepends+=" llvm11" +fi + +do_configure() { + if [ "$build_option_mcode" ]; then + mkdir -p build_mcode + cd build_mcode + ../configure --libdir=lib/ghdl/mcode \ + ${configure_args} + cd .. + fi + if [ "$build_option_llvm" ]; then + mkdir -p build_llvm + cd build_llvm + ../configure --libdir=lib/ghdl/llvm --with-llvm-config \ + ${configure_args} + cd .. + fi +} + +do_build() { + if [ "$build_option_mcode" ]; then + make -C build_mcode ${makejobs} + fi + if [ "$build_option_llvm" ]; then + make -C build_llvm ${makejobs} + fi +} + +do_install() { + # must be first; make install uses it + vbin ${FILESDIR}/ghdl + # install whatever backends we have + if [ "$build_option_mcode" ]; then + make -C build_mcode DESTDIR=${DESTDIR} install + rm -rf ${DESTDIR}/usr/lib/ghdl/src + mv ${DESTDIR}/usr/lib/ghdl/mcode/src ${DESTDIR}/usr/lib/ghdl + ln -s ../src ${DESTDIR}/usr/lib/ghdl/mcode/src + fi + if [ "$build_option_llvm" ]; then + make -C build_llvm DESTDIR=${DESTDIR} install + rm -rf ${DESTDIR}/usr/lib/ghdl/src + mv ${DESTDIR}/usr/lib/ghdl/llvm/src ${DESTDIR}/usr/lib/ghdl + ln -s ../src ${DESTDIR}/usr/lib/ghdl/llvm/src + fi + # manpage is not installed by default + vman doc/ghdl.1 +} + +do_check() { + # the testsuite is broken + # after a while it fails with this: + # ghdl: unknown command '--synth', try --help + # this indicates a bug in the testsuite + : && return 0 + + # the testsuite is big and long even when it runs + [ "$XBPS_CHECK_PKGS" != full ] && return 0 + + # need a temporary installation for testsuite run so that ghdl1 is found + for variant in ${build_options_default}; do + cd ${wrksrc}/build_${variant} + mkdir -p tmp_inst/usr/bin + ln -sf ghdl-${variant} tmp_inst/usr/bin/ghdl + make DESTDIR=${wrksrc}/build_${variant}/tmp_inst install + cd ../testsuite + GHDL="${wrksrc}/build_${variant}/tmp_inst/usr/bin/ghdl" \ + ./testsuite.sh + cd ${wrksrc} + done +} + +ghdl-mcode_package() { + short_desc+=" - mcode backend" + pkg_install() { + vmove usr/bin/ghdl-mcode + vmove usr/lib/ghdl/mcode + } +} + +ghdl-llvm_package() { + short_desc+=" - LLVM backend" + pkg_install() { + vmove usr/bin/ghdl-llvm + vmove usr/lib/ghdl/llvm + } +}