Hello List (& Bcc to GlobalGCC partners)
I now understand more what I need for MELT plugin inclusion.
I'm rephrasing my thoughts and experiments.
First, I'm recalling the general context. MELT may (see
http://gcc.gnu.org/wiki/MiddleEndLispTranslator for more) generate C
code during the compilation process cc1 itself and then dynamically link
it. More precisely, MELT contains a sort of lisp translator which works
by generating C code, compiling it appropriately to a shared object, and
then tldl_dlopenext it (file gcc/basilys.c). This Lisp translator is
itself coded in MELT (file melt/warm-basilys.bysl), but depends not much
on the details of most GCC data (for instance it uses the GGC memory
manager, but do not depend on the entire details of tree.h).
My point is that I would want MELT to be somehow usable even when GCC
source and build directories are whipped out, after a full installation.
Of course I know that every MELT generated C file depends upon the
actual exact version of GCC generating & dynamically loading it. I do
not pretend to define a generic ABI for plugins!
Every MELT generated C file has only one #include line, which is
#include "run-basilys.h"
so I factored out all the necessary includes in the single
gcc/run-basilys.h file available on the MELT branch
Now I need to copy all the GCC-specific include files (but not the
system ones) which are directly and indirectly included by run-basilys.h
in some suitable directory, probably
$(libexecsubdir)/melt-private-include/
Such indirectly included files are mostly toplevel-like, e.g.
gcc/pretty-print.h is include as #include "pretty-print.h" but the
exceptions seems to be the config/ files (included in "tm.h"), probably
the $(tm_file_list) of Makefile.in, more precisely every file starting
with $(srcdir)/config/
So I figured out the following scheme. I'm expecting that the $(CC) is
always some compiler able to understand the -MT & -MMD flags (I really
got no ideas how standard these flags are), typically some not too old
version of GCC.
So my goal is now to fill a directory melt-private-build-include in the
build directory and then copy it (at installation time) to
$(libexecsubdir)/melt-private-include/
I'm pasting the end of my modified gcc/Makefile.in below
################################################################
## definition for basilys/MELT internal compilation
compile-basilys-defs:
echo '#generated compile-basilys-defs' > $@
echo 'ALL_CFLAGS="' $(ALL_CFLAGS) '"' >> $@
echo 'ALL_CPPFLAGS="' -I$(PWD) $(ALL_CPPFLAGS) '"' >> $@
## this is the installation directory
melt_private_include_dir=$(libexecsubdir)/melt-private-include/
## this is the local build directory
melt_build_include_dir= melt-private-build-include
# we want to generate all the direct (non system) dependencies of run-basilys.h
# the following should work if $(CC) is some recent version of GCC (probably >=
4.x)
# we first generate the make-dependencies using -MMD
# this should write into run-basilys.d some stuff like
## run-basilys-deps: srcdir.../gcc/run-basilys.h config.h auto-host.h ....
# with the srcdir... replaced by the source directory
# however, there are also config/ files in the dependency list
# config/ files should be handled specially since they are the only #include-d
files
# which are not flat, ie in a subdirectory, like
srcdir.../gcc/config/i386/x86-64.h
# there is also a dependency on tm.h (in objdir) which contains stuff like #include
"config/i386/x86-64.h"
run-basilys.d: run-basilys.h \
$(CONFIG_H) $(SYSTEM_H) $(TIMEVAR_H) $(TM_H) $(TREE_H) $(GGC_H) \
tree-pass.h basilys.h gt-basilys.h
$(CC) -MT run-basilys-deps -MMD $(ALL_CFLAGS) $(ALL_CPPFLAGS) $<
.PHONY: run-basilys-deps
## the include below defines the dependencies of run-basilys-deps
## included file run-basilys.d is generated above
-include run-basilys.d
## copy all the file in the dependency of run-basilys-deps into
$(melt_private_include_dir)
## but handle the $(srcdir)/config/ files specially by copying them within a
config/ directory
run-basilys-deps:
mkdir -p $(melt_build_include_dir); \
for f in $^ ; do \
cf=$(echo $$f | sed -q
":^$(srcdir)/config/:$(melt_build_include_dir)/config:"); \
if [ -n "$$cf" ] ; then \
cp -va $$f $$cf ; \
else \
cp -va $$f $(melt_build_include_dir)/ ; \
fi; \
done
Comments are welcome.
It sems to nearly work, except of course I don't understand all the
(important) subtility of the s-* and $(STAMP) stuff in Makefile.in; I
probably need to add them.
Basile STARYNKEVITCH wrote:
I think it should be (in gcc/Makefile.in parlance)
$(DESTDIR)$(libexecsubdir)/melt-private-include/ and I should have
some Makefile.in trick to copy the relevant *.h there perhaps thru a
install-melt-includes target
The one detail I don't understand yet is the link between the -B option
to gcc and this $(DESTDIR)$(libexecsubdir)/ are they somehow equal (or
is the -B value some initial prefix of $(DESTDIR)$(libexecsubdir) ?
I have to figure out this also.
A big thanks for reading.
PS. I really think that GCC building procedure is a nightmare. It is
making me insane.
--
Basile STARYNKEVITCH http://starynkevitch.net/Basile/
email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359
8, rue de la Faiencerie, 92340 Bourg La Reine, France
*** opinions {are only mines, sont seulement les miennes} ***