Message ID | 20141112125512.GA26644@ovh.starynkevitch.net |
---|---|
State | New |
Headers | show |
On Wed, Nov 12, 2014 at 01:55:12PM +0100, Basile Starynkevitch wrote: > Hello All, > > Some plugins (including MELT, see http://gcc-melt.org/ for more) > are made of several C++ source files which all include "plugin-version.h" > because they have some C++ code which depends upon the particular version > of GCC. > > So they typically code > > #if GCCPLUGIN_VERSION >= 4009 > /* code for GCC 4.9 or newer. */ > #else > /* code for GCC 4.8 */ > #endif /*GCCPLUGIN_VERSION*/ Can't you just remember that version in configure of your plugin? Jakub
On Wed, Nov 12, 2014 at 02:12:07PM +0100, Jakub Jelinek wrote: > On Wed, Nov 12, 2014 at 01:55:12PM +0100, Basile Starynkevitch wrote: > > Hello All, > > > > Some plugins (including MELT, see http://gcc-melt.org/ for more) > > are made of several C++ source files which all include "plugin-version.h" > > because they have some C++ code which depends upon the particular version > > of GCC. > > > > So they typically code > > > > #if GCCPLUGIN_VERSION >= 4009 > > /* code for GCC 4.9 or newer. */ > > #else > > /* code for GCC 4.8 */ > > #endif /*GCCPLUGIN_VERSION*/ > > Can't you just remember that version in configure of your plugin? Most plugin don't need any configure, because they are installed in a version specific directory (like /usr/lib/gcc/x86_64-linux-gnu/4.9/plugin for example). I don't think it is wise to require plugin to be autoconf-configurable. Their Makefile simply uses $(shell gcc -print-file-name=plugin), there is no need to complex autoconf machinery. And even a plugin for a particular version of GCC is usually made of several files, all of them with #include "plugin-version.h"; there is no need to define several times gcc_version. (another possibility might be to make gcc_version an external symbol with public visibility inside the cc1 or cc1plus executable) Thanks for your comment. Cheers. -- Basile Starynkevitch http://starynkevitch.net/Basile/
On Wed, Nov 12, 2014 at 02:20:22PM +0100, Basile Starynkevitch wrote: > Most plugin don't need any configure, because they are installed in > a version specific directory (like /usr/lib/gcc/x86_64-linux-gnu/4.9/plugin > for example). I don't think it is wise to require plugin to be > autoconf-configurable. Their Makefile simply uses > $(shell gcc -print-file-name=plugin), there is no need to complex > autoconf machinery. If you use $(shell gcc -print-file-name=plugin), there is no point to include plugin-version.h, just use __GNUC__/__GNUC_MINOR__ ? Jakub
On Wed, Nov 12, 2014 at 02:29:13PM +0100, Jakub Jelinek wrote: > On Wed, Nov 12, 2014 at 02:20:22PM +0100, Basile Starynkevitch wrote: > > Most plugin don't need any configure, because they are installed in > > a version specific directory (like /usr/lib/gcc/x86_64-linux-gnu/4.9/plugin > > for example). I don't think it is wise to require plugin to be > > autoconf-configurable. Their Makefile simply uses > > $(shell gcc -print-file-name=plugin), there is no need to complex > > autoconf machinery. > > If you use $(shell gcc -print-file-name=plugin), there is no point > to include plugin-version.h, just use __GNUC__/__GNUC_MINOR__ ? I could compile a plugin (notably for a GCC cross-compiler) with a GCC version different of the GCC targetting the plugin. I could also compile a plugin with Clang or some other non-GCC compiler. In both cases plugin-version.h is needed with its GCCPLUGIN_VERSION. Cheers. -- Basile Starynkevitch http://starynkevitch.net/Basile/
On Wed, Nov 12, 2014 at 2:12 PM, Jakub Jelinek <jakub@redhat.com> wrote: > On Wed, Nov 12, 2014 at 01:55:12PM +0100, Basile Starynkevitch wrote: >> Hello All, >> >> Some plugins (including MELT, see http://gcc-melt.org/ for more) >> are made of several C++ source files which all include "plugin-version.h" >> because they have some C++ code which depends upon the particular version >> of GCC. >> >> So they typically code >> >> #if GCCPLUGIN_VERSION >= 4009 >> /* code for GCC 4.9 or newer. */ >> #else >> /* code for GCC 4.8 */ >> #endif /*GCCPLUGIN_VERSION*/ > > Can't you just remember that version in configure of your plugin? Or fix it properly by also generating a plugin-version.c file with the definitions and just provide declarations in plugin-version.h. Richard. > Jakub
On Wed, Nov 12, 2014 at 3:35 PM, Richard Biener <richard.guenther@gmail.com> wrote: > On Wed, Nov 12, 2014 at 2:12 PM, Jakub Jelinek <jakub@redhat.com> wrote: >> On Wed, Nov 12, 2014 at 01:55:12PM +0100, Basile Starynkevitch wrote: >>> Hello All, >>> >>> Some plugins (including MELT, see http://gcc-melt.org/ for more) >>> are made of several C++ source files which all include "plugin-version.h" >>> because they have some C++ code which depends upon the particular version >>> of GCC. >>> >>> So they typically code >>> >>> #if GCCPLUGIN_VERSION >= 4009 >>> /* code for GCC 4.9 or newer. */ >>> #else >>> /* code for GCC 4.8 */ >>> #endif /*GCCPLUGIN_VERSION*/ >> >> Can't you just remember that version in configure of your plugin? > > Or fix it properly by also generating a plugin-version.c file with > the definitions and just provide declarations in plugin-version.h. And of course not export the too unspecific symbols 'basever' 'datestamp' 'devphase' and 'revision'. Only export gcc_version. Which is already available from 'version_string' in version.[ch](!?). So what's the point of the extra stuff in plugin-version.h?? Richard. > Richard. > >> Jakub
Index: gcc/configure.ac =================================================================== --- gcc/configure.ac (revision 217404) +++ gcc/configure.ac (working copy) @@ -1664,6 +1664,10 @@ #define GCCPLUGIN_VERSION_PATCHLEVEL `echo $gcc_BASEVER | sed -e 's/^[0-9]*\.[0-9]*\.\([0-9]*\)$/\1/'` #define GCCPLUGIN_VERSION (GCCPLUGIN_VERSION_MAJOR*1000 + GCCPLUGIN_VERSION_MINOR) +/* Some plugins might not want the data below, they would define + GCCPLUGIN_SKIP_VERSION_DATA as 1 before including this. */ + +#if !GCCPLUGIN_SKIP_VERSION_DATA static char basever[] = "$gcc_BASEVER"; static char datestamp[] = "$gcc_DATESTAMP"; static char devphase[] = "$gcc_DEVPHASE"; @@ -1675,6 +1679,7 @@ static struct plugin_gcc_version gcc_version = {basever, datestamp, devphase, revision, configuration_arguments}; +#endif /* GCCPLUGIN_SKIP_VERSION_DATA */ EOF changequote([,])dnl Index: gcc/doc/plugins.texi =================================================================== --- gcc/doc/plugins.texi (revision 217404) +++ gcc/doc/plugins.texi (working copy) @@ -157,6 +157,16 @@ but you can also check the individual fields if you want a less strict check. +A plugin might want to include in some of its source files the +@file{plugin-version.h} header for preprocessor constants +@code{GCCPLUGIN_VERSION} without defining the static symbol +@code{gcc_version}. In that case it should define the preprocessor +symbol @code{GCCPLUGIN_SKIP_VERSION_DATA} to @code{1} before including +that header. +@findex GCCPLUGIN_VERSION +@findex GCCPLUGIN_SKIP_VERSION_DATA +@findex gcc_version + @subsection Plugin callbacks Callback functions have the following prototype: @@ -488,6 +498,10 @@ #error this GCC plugin is for GCC 4.7 #endif @end smallexample +@findex GCCPLUGIN_VERSION_MAJOR +@findex GCCPLUGIN_VERSION_MINOR +@findex GCCPLUGIN_VERSION_PATCHLEVEL +@findex GCCPLUGIN_VERSION The following GNU Makefile excerpt shows how to build a simple plugin: