From ffca448651c5b7b0fc5fe6bdbbcf1e0dc13419e1 Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Wed, 21 Mar 2018 18:33:54 +0100 Subject: Set a version to libghdl, put version in configure. --- Makefile.in | 20 ++++++----- configure | 12 ++++++- dist/linux/travis-ci.sh | 2 +- dist/windows/targets.psm1 | 71 +++++++++++++++++++------------------ doc/conf.py | 16 ++++----- setup.py.in | 8 ++++- src/ghdldrv/default_paths.ads.in | 3 +- src/version.in | 2 +- src/vhdl/python/libghdl/__init__.py | 11 ++---- 9 files changed, 80 insertions(+), 65 deletions(-) diff --git a/Makefile.in b/Makefile.in index 550998656..7bcd1e157 100644 --- a/Makefile.in +++ b/Makefile.in @@ -35,6 +35,8 @@ LDFLAGS=@LDFLAGS@ LIBBACKTRACE=@backtrace_lib@ llvm_be=@llvm_be@ build_mode=@build_mode@ +ghdl_version=@ghdl_version@ +libghdl_version=@libghdl_version@ enable_werror=@enable_werror@ enable_checks=@enable_checks@ enable_openieee=@enable_openieee@ @@ -144,12 +146,12 @@ include $(srcdir)/src/grt/Makefile.inc version.tmp: $(srcdir)/src/version.in force # Create version.tmp from version.in, using git date/hash - if test -d $(srcdir)/.git \ - && desc=`cd $(srcdir); git describe --dirty`; then \ - $(SED) -e "s/[(].*[)]/($$desc)/" < $< > $@; \ - else \ - $(CP) $< $@; \ - fi + if ! test -d $(srcdir)/.git \ + || ! desc=`cd $(srcdir); git describe --dirty`; then \ + desc="tarball"; \ + fi; \ + $(SED) -e "s/[(].*[)]/($$desc)/" \ + -e "s/@VER@/$(ghdl_version)/" < $< > $@; \ version.ads: version.tmp # Change version.ads only if version.tmp has been modified to avoid @@ -337,10 +339,12 @@ install.simul: install.simul.program install.vhdllib LIBGHDL_INCFLAGS=$(GHDL_COMMON_INCFLAGS) -aI$(srcdir)/src/vhdl/python -aI$(srcdir)/src/ghdldrv -libghdl$(SOEXT): $(GRT_SRC_DEPS) version.ads force +libghdl_name=libghdl-$(libghdl_version)$(SOEXT) + +$(libghdl_name): $(GRT_SRC_DEPS) version.ads force $(GNATMAKE) -I- -aI. -D pic -z libghdl -o $@ $(GNATFLAGS) $(PIC_FLAGS) -gnat05 $(LIBGHDL_INCFLAGS) -bargs -shared -Llibghdl_ -largs -shared $(SHLIB_FLAGS) -all.libghdl.true: libghdl$(SOEXT) +all.libghdl.true: $(libghdl_name) all.libghdl.false: ################ ghdlsynth library ###################################### diff --git a/configure b/configure index fc9818201..86cba6652 100755 --- a/configure +++ b/configure @@ -3,6 +3,13 @@ # configure script for ghdl (c) 2014 Tristan Gingold # +# Current version. This is the only place where the version is written. +# Any code that needs version should read it directly or indirectly from this +# place. +# Note the absence of spaces and the quotes. +# Suffix "-dev" is used during development. +ghdl_version="0.36-dev" + backend=mcode CC=${CC:-gcc} CXX=${CXX:-clang++} @@ -30,7 +37,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_pie enable_werror enable_checks enable_openieee enable_python" +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_pie enable_werror enable_checks enable_openieee enable_python libghdl_version ghdl_version" # Find srcdir srcdir=`dirname $progname` @@ -247,6 +254,9 @@ case "$build" in *) SOEXT=".so"; EXEEXT=""; PIC_FLAGS="-fPIC";; esac +# Define libghdl_version +libghdl_version=`echo $ghdl_version | sed -e 's/[-.]/_/g'` + # Check if gcc was configured with --enable-default-pie. In that case -fPIC # should be added. if gcc -v 2>&1 | grep -q enable-default-pie; then diff --git a/dist/linux/travis-ci.sh b/dist/linux/travis-ci.sh index 5d328279a..51f7a83eb 100755 --- a/dist/linux/travis-ci.sh +++ b/dist/linux/travis-ci.sh @@ -55,7 +55,7 @@ echo "travis_fold:end:fetch" # Compute package name PKG_SHORTCOMMIT="$(printf $TRAVIS_COMMIT | cut -c1-10)" -PKG_VER=`grep Ghdl_Ver src/version.in | sed -e 's/.*"\(.*\)";/\1/'` +PKG_VER=`grep "ghdl_version=" configure | sed -e 's/.*"\(.*\)";/\1/'` if [ -z "$TRAVIS_TAG" ]; then # No tag: use date + commit id PKG_TAG="$(date -u +%Y%m%d)-$PKG_SHORTCOMMIT"; diff --git a/dist/windows/targets.psm1 b/dist/windows/targets.psm1 index 4df6f1358..7ff400172 100644 --- a/dist/windows/targets.psm1 +++ b/dist/windows/targets.psm1 @@ -1,29 +1,29 @@ # EMACS settings: -*- tab-width: 2; indent-tabs-mode: t -*- # vim: tabstop=2:shiftwidth=2:noexpandtab # kate: tab-width 2; replace-tabs off; indent-width 2; -# +# # ============================================================================== # Authors: Patrick Lehmann -# +# # PowerShell Module: The module provides build targets for GHDL. -# +# # Description: # ------------------------------------ # This PowerShell module provides build targets for GHDL. # # ============================================================================== # Copyright (C) 2016-2017 Patrick Lehmann -# +# # GHDL is free software; you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free # Software Foundation; either version 2, or (at your option) any later # version. -# +# # GHDL is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # for more details. -# +# # You should have received a copy of the GNU General Public License # along with GHDL; see the file COPYING. If not, write to the Free # Software Foundation, 59 Temple Place - Suite 330, Boston, MA @@ -67,10 +67,10 @@ function Invoke-Clean [string] $BuildDirectory, [switch] $Quiet = $false ) - + $EnableDebug = -not $Quiet -and ( $PSCmdlet.MyInvocation.BoundParameters["Debug"]) $EnableVerbose = -not $Quiet -and ($EnableDebug -or $PSCmdlet.MyInvocation.BoundParameters["Verbose"]) - + -not $Quiet -and (Write-Host "Executing build target 'Clean' ..." -ForegroundColor Yellow) | Out-Null $EnableVerbose -and (Write-Host " Removing all created files and directories..." ) | Out-Null if (Test-Path -Path $BuildDirectory) @@ -98,7 +98,7 @@ function New-BuildDirectory [string] $BuildDirectory, [switch] $Quiet = $false ) - + Write-Host "Executing build target 'BuildDirectory' ..." -ForegroundColor Yellow if (Test-Path -Path $BuildDirectory -PathType Container) { -not $Quiet -and (Write-Host " Directory '$BuildDirectory' already exists." ) | Out-Null } @@ -110,7 +110,7 @@ function New-BuildDirectory return $true } } - + return $false } # New-BuildDirectory @@ -126,19 +126,18 @@ function Get-GHDLVersion [string] $GHDLRootDir ) # construct DirectoryPaths - $SourceDirectory = $GHDLRootDir + "\" + $CommonSourceDirName - $VersionFilePath = $SourceDirectory + "\" + $VersionFileName_In - - if (-not (Test-Path -Path $VersionFilePath -PathType Leaf)) - { Write-Host "[ERROR]: Version file '$VersionFilePath' does not exists." -ForegroundColor Red + $ConfigureFilePath = $GHDLRootDir + "\configure" + + if (-not (Test-Path -Path $ConfigureFilePath -PathType Leaf)) + { Write-Host "[ERROR]: Version file '$ConfigureFilePath' does not exists." -ForegroundColor Red return $true } - $FileContent = Get-Content -Path $VersionFilePath + $FileContent = Get-Content -Path $ConfigureFilePath foreach ($Line in $FileContent) - { if ($Line -match 'Ghdl_Ver(.+?)\"(.+?)\";') + { if ($Line -match 'ghdl_version=\"(.+?)\"') { return $Matches[2] } } - Write-Host "[ERROR]: RegExp didn't match in '$VersionFilePath'." -ForegroundColor Red + Write-Host "[ERROR]: RegExp didn't match in '$ConfigureFilePath'." -ForegroundColor Red return $true } # Get-GHDLVersion @@ -169,9 +168,9 @@ function Invoke-PatchVersionFile $SourceDirectory = $GHDLRootDir + "\" + $CommonSourceDirName $VersionInputFilePath = $SourceDirectory + "\" + $VersionFileName_In $VersionFilePath = $SourceDirectory + "\" + $VersionFileName_Ads - + Write-Host "Executing build target 'PatchVersionFile' ..." -ForegroundColor Yellow - + if (-not (Test-Path -Path $VersionInputFilePath -PathType Leaf)) { Write-Host "[ERROR]: Version file '$VersionInputFilePath' does not exists." -ForegroundColor Red return $true @@ -182,14 +181,18 @@ function Invoke-PatchVersionFile { Write-Host "[ERROR]: While opening '$VersionInputFilePath'." -ForegroundColor Red return $true } + $GHDLVersion = Get-GHDLVersion $GHDLRootDir + $FileContent = $FileContent -Replace "\s@VER@\s", $GHDLVersion + $FileContent = $FileContent -Replace "\s\(tarball\)\s", " (commit: $GitCommitDataString; git branch: $GitBranchName'; hash: $GitCommitHash) " - + + $FileContent | Out-File $VersionFilePath -Encoding Ascii if ($? -eq $false) { Write-Host "[ERROR]: While writing to '$VersionFilePath'." -ForegroundColor Red return $true } - + return $false } # Invoke-PatchVersionFile @@ -224,7 +227,7 @@ function Invoke-CompileCFiles ) # construct DirectoryPaths $SourceDirectory = $GHDLRootDir + "\" + $CommonSourceDirName - + Set-Location $BuildDirectory Write-Host "Executing build target 'CompileCFiles' ..." -ForegroundColor Yellow @@ -243,10 +246,10 @@ function Invoke-CompileCFiles $Parameters += Get-CFlags # append common CFlags $Parameters += $SourceFile.CFlags $Parameters += $SourceDirectory + "\" + $SourceFile.File - + # call C compiler $InvokeExpr = "$Prog_GCC " + ($Parameters -join " ") + " 2>&1" - + Write-Host (" compiling: " + $SourceFile.File) Write-Debug " call: $InvokeExpr" $ErrorRecordFound = Invoke-Expression $InvokeExpr | Restore-NativeCommandStream | Write-ColoredGCCLine -Indent " " @@ -255,7 +258,7 @@ function Invoke-CompileCFiles return $true } } - + return $false } # Invoke-CompileCFiles @@ -280,10 +283,10 @@ function Invoke-CompileGHDLAdaFiles # construct DirectoryPaths $CommonSourceDirectory = $GHDLRootDir + "\" + $CommonSourceDirName $WinMcodeSourceDirectory = $GHDLRootDir + "\" + $WinMcodeSourceDirName - + Set-Location $BuildDirectory Write-Host "Executing build target 'CompileGHDLAdaFiles' ..." -ForegroundColor Yellow - + $Parameters = @() $Parameters += Get-CFlags # append common CFlags $Parameters += '-gnatn' @@ -298,7 +301,7 @@ function Invoke-CompileGHDLAdaFiles $Parameters += '-aI' + $CommonSourceDirectory + '\ortho\mcode' $Parameters += '-aI' + $CommonSourceDirectory + '\vhdl' $Parameters += '-aI' + $CommonSourceDirectory + '\vhdl\translate' - + # top level $Parameters += 'ghdl_jit' @@ -319,7 +322,7 @@ function Invoke-CompileGHDLAdaFiles # call Ada compiler (GNAT) $InvokeExpr = "$Prog_GNATMake " + ($Parameters -join " ") + " 2>&1" - + Write-Host " compiling with GNAT" Write-Debug " call: $InvokeExpr" $ErrorRecordFound = Invoke-Expression $InvokeExpr | Restore-NativeCommandStream | Write-ColoredGCCLine -Indent " " @@ -348,7 +351,7 @@ function Invoke-StripGHDLExecutable Set-Location $BuildDirectory Write-Host "Executing build target 'StripGHDLExecutable' ..." -ForegroundColor Yellow - + # call striping tool (strip) Write-Host " stripping '$GHDL_Mcode_Name'" Write-Debug " call: $Prog_Strip $GHDL_Mcode_Name" @@ -377,15 +380,15 @@ function Test-GHDLVersion Set-Location $BuildDirectory Write-Host "Executing build target 'GHDLVersion' ..." -ForegroundColor Yellow - + if (-not (Test-Path -Path $GHDL_Mcode_Name -PathType Leaf)) { Write-Host " GHDL executable '$GHDL_Mcode_Name' does not exists." -ForegroundColor Red return $true } - + # call ghdl $InvokeExpr = "$GHDL_Mcode_Name --version 2>&1" - + Write-Host " executing '$GHDL_Mcode_Name'" Write-Host " call: $InvokeExpr" Write-Host " ----------------------------------------" diff --git a/doc/conf.py b/doc/conf.py index 0b43acca6..31b20c948 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -77,9 +77,9 @@ author = u'Tristan Gingold and contributors' # built documents. # try: - with open('../src/version.in') as verin: + with open('../configure') as verin: for line in verin: - line = re.findall(r'Ghdl_Ver.+\"(.+)\";', line) + line = re.findall(r'ghdl_version=\"(.+)\"', line) if line: version=line[0] except Exception, e: @@ -150,12 +150,12 @@ except Exception as ex: # a list of builtin themes. #html_theme = 'alabaster' html_theme = "sphinx_rtd_theme" -# Override default css to get a larger width for ReadTheDoc build -html_context = { - 'css_files': [ - 'https://media.readthedocs.org/css/sphinx_rtd_theme.css', - 'https://media.readthedocs.org/css/readthedocs-doc-embed.css', - '_static/theme_overrides.css', +# Override default css to get a larger width for ReadTheDoc build +html_context = { + 'css_files': [ + 'https://media.readthedocs.org/css/sphinx_rtd_theme.css', + 'https://media.readthedocs.org/css/readthedocs-doc-embed.css', + '_static/theme_overrides.css', ], } diff --git a/setup.py.in b/setup.py.in index 57f997084..ef6e3daae 100644 --- a/setup.py.in +++ b/setup.py.in @@ -7,6 +7,9 @@ from distutils.command.build import build import os import os.path +so_ext = "@SOEXT@" +libghdl_version = "@libghdl_version@" + class GHDLBuild(build): def my_copy_tree(self, src, dst): """Tuned version of copy_tree: exclude .o files""" @@ -27,7 +30,10 @@ class GHDLBuild(build): # Copy VHDL libraries & shared library dstdir = os.path.join(self.build_lib, 'libghdl') - distutils.file_util.copy_file("libghdl" + "@SOEXT@", dstdir) + libghdl_filename = "libghdl-" + libghdl_version + so_ext + distutils.file_util.copy_file(libghdl_filename, dstdir) + with open(os.path.join(dstdir, "config.py"), 'w') as f: + f.write('libghdl_filename="{}"\n'.format(libghdl_filename)) self.my_copy_tree(os.path.join("lib", "ghdl"), os.path.join(dstdir, "ghdl")) diff --git a/src/ghdldrv/default_paths.ads.in b/src/ghdldrv/default_paths.ads.in index da2f7cc42..e6137789d 100644 --- a/src/ghdldrv/default_paths.ads.in +++ b/src/ghdldrv/default_paths.ads.in @@ -37,7 +37,6 @@ package Default_Paths is Post_Processor : constant String := "@POST_PROCESSOR@"; - Shared_Library_Extension : constant String := - "@SOEXT@"; + Shared_Library_Extension : constant String := "@SOEXT@"; Default_Pie : constant Boolean := "@default_pie@" = String'("yes"); end Default_Paths; diff --git a/src/version.in b/src/version.in index 32ef90cc9..b12295dab 100644 --- a/src/version.in +++ b/src/version.in @@ -1,5 +1,5 @@ package Version is - Ghdl_Ver : constant String := "0.36-dev"; + Ghdl_Ver : constant String := "@VER@"; Ghdl_Release : constant String := "(tarball) [Dunoon edition]"; end Version; diff --git a/src/vhdl/python/libghdl/__init__.py b/src/vhdl/python/libghdl/__init__.py index 457d6f2bd..8ca7a977b 100644 --- a/src/vhdl/python/libghdl/__init__.py +++ b/src/vhdl/python/libghdl/__init__.py @@ -1,17 +1,10 @@ import ctypes -import sys import os.path - -_ext = {'linux': '.so', - 'linux2': '.so', - 'darwin': '.dylib', - 'win32': '.dll', - 'cygwin': '.dll'} +from libghdl.config import libghdl_filename # Load the DLL. _basedir = os.path.dirname(__file__) -libghdl = ctypes.CDLL(os.path.join( - _basedir, 'libghdl' + _ext.get(sys.platform, '.so'))) +libghdl = ctypes.CDLL(os.path.join(_basedir, libghdl_filename)) # Low-level initialization (elaboration). libghdl.libghdl_init() -- cgit v1.2.3