Add a debug counter for late-combine
[official-gcc.git] / gcc / jit / Make-lang.in
blob99b3d549d5d45b680ffb20d4a0817dfc7e1261a9
1 # Top level -*- makefile -*- fragment for libgccjit.so.
2 #   Copyright (C) 2013-2024 Free Software Foundation, Inc.
4 #This file is part of GCC.
6 #GCC is free software; you can redistribute it and/or modify
7 #it under the terms of the GNU General Public License as published by
8 #the Free Software Foundation; either version 3, or (at your option)
9 #any later version.
11 #GCC is distributed in the hope that it will be useful,
12 #but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 #GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with GCC; see the file COPYING3.  If not see
18 # <http://www.gnu.org/licenses/>.
20 # This file provides the language dependent support in the main Makefile.
21 # Each language makefile fragment must provide the following targets:
23 # foo.all.cross, foo.start.encap, foo.rest.encap,
24 # foo.install-common, foo.install-man, foo.install-info, foo.install-pdf,
25 # foo.install-html, foo.info, foo.dvi, foo.pdf, foo.html, foo.uninstall,
26 # foo.mostlyclean, foo.clean, foo.distclean,
27 # foo.maintainer-clean, foo.stage1, foo.stage2, foo.stage3, foo.stage4
29 # where `foo' is the name of the language.
31 # It should also provide rules for:
33 # - making any compiler driver (eg: g++)
34 # - the compiler proper (eg: cc1plus)
35 # - define the names for selecting the language in LANGUAGES.
37 #\f
38 # Define the names for selecting jit in LANGUAGES.
39 # Note that it would be nice to move the dependency on g++
40 # into the jit rule, but that needs a little bit of work
41 # to do the right thing within all.cross.
43 LIBGCCJIT_VERSION_NUM = 0
44 LIBGCCJIT_MINOR_NUM = 0
45 LIBGCCJIT_RELEASE_NUM = 1
47 ifneq (,$(findstring mingw,$(target)))
48 LIBGCCJIT_FILENAME = libgccjit-$(LIBGCCJIT_VERSION_NUM).dll
49 LIBGCCJIT_IMPORT_LIB = libgccjit.dll.a
51 jit: $(LIBGCCJIT_FILENAME) \
52         $(FULL_DRIVER_NAME)
54 else
56 ifneq (,$(findstring darwin,$(host)))
58 # NOTE that we are building here for the host, and so tests for target-
59 # specific functionality will only work when host == target.  This causes
60 # fails when building cross-compilers with different object formats (at
61 # least when the respective linkers do not accept the same command line
62 # options).  Fortunately, for Darwin we can safely hard-code the relevant
63 # host options, since all usable linkers support them).
65 LIBGCCJIT_CURRENT = 26
66 LIBGCCJIT_REVISION = 0
67 LIBGCCJIT_AGE = 26
68 LIBGCCJIT_COMPAT = 0
69 LIBGCCJIT_BASENAME = libgccjit
71 LIBGCCJIT_SONAME = \
72   $(DARWIN_RPATH)/$(LIBGCCJIT_BASENAME).$(LIBGCCJIT_VERSION_NUM).dylib
73 LIBGCCJIT_FILENAME = $(LIBGCCJIT_BASENAME).$(LIBGCCJIT_VERSION_NUM).dylib
74 LIBGCCJIT_LINKER_NAME = $(LIBGCCJIT_BASENAME).dylib
76 # Darwin does not have a version script option. Exported symbols are controlled
77 # by the following, and library versioning is done using libtool.
78 # We have to define a COMMA here, otherwise the commas are treated as
79 # separators.
80 COMMA := ,
81 LIBGCCJIT_VERSION_SCRIPT_OPTION = \
82   -Wl$(COMMA)-exported_symbols_list$(COMMA)$(srcdir)/jit/libgccjit.exports
84 # For Darwin host, we need a l64 or ld64-compatible linker, that uses
85 # -install_name to introduce this.
86 LIBGCCJIT_SONAME_OPTION = \
87   -Wl$(COMMA)-install_name$(COMMA)$(LIBGCCJIT_SONAME)
89 LIBGCCJIT_SONAME_SYMLINK = $(LIBGCCJIT_FILENAME)
90 LIBGCCJIT_LINKER_NAME_SYMLINK = $(LIBGCCJIT_LINKER_NAME)
92 jit: $(LIBGCCJIT_FILENAME) \
93         $(LIBGCCJIT_SYMLINK) \
94         $(LIBGCCJIT_LINKER_NAME_SYMLINK) \
95         $(FULL_DRIVER_NAME)
97 else
99 LIBGCCJIT_LINKER_NAME = libgccjit.so
100 LIBGCCJIT_SONAME = $(LIBGCCJIT_LINKER_NAME).$(LIBGCCJIT_VERSION_NUM)
101 LIBGCCJIT_FILENAME = \
102   $(LIBGCCJIT_SONAME).$(LIBGCCJIT_MINOR_NUM).$(LIBGCCJIT_RELEASE_NUM)
104 LIBGCCJIT_LINKER_NAME_SYMLINK = $(LIBGCCJIT_LINKER_NAME)
105 LIBGCCJIT_SONAME_SYMLINK = $(LIBGCCJIT_SONAME)
107 # Conditionalize the use of the LD_VERSION_SCRIPT_OPTION and
108 # LD_SONAME_OPTION depending if configure found them, using $(if)
109 # We have to define a COMMA here, otherwise the commas in the "true"
110 # result are treated as separators by the $(if).
111 COMMA := ,
112 LIBGCCJIT_VERSION_SCRIPT_OPTION = \
113         $(if $(LD_VERSION_SCRIPT_OPTION),\
114           -Wl$(COMMA)$(LD_VERSION_SCRIPT_OPTION)$(COMMA)$(srcdir)/jit/libgccjit.map)
116 LIBGCCJIT_SONAME_OPTION = \
117         $(if $(LD_SONAME_OPTION), \
118              -Wl$(COMMA)$(LD_SONAME_OPTION)$(COMMA)$(LIBGCCJIT_SONAME))
120 jit: $(LIBGCCJIT_FILENAME) \
121         $(LIBGCCJIT_SYMLINK) \
122         $(LIBGCCJIT_LINKER_NAME_SYMLINK) \
123         $(FULL_DRIVER_NAME)
125 endif
126 endif
128 jit.serial = $(LIBGCCJIT_FILENAME)
130 # Tell GNU make to ignore these if they exist.
131 .PHONY: jit
133 jit_OBJS = attribs.o \
134         jit/dummy-frontend.o \
135         jit/libgccjit.o \
136         jit/jit-logging.o \
137         jit/jit-recording.o \
138         jit/jit-playback.o \
139         jit/jit-result.o \
140         jit/jit-tempdir.o \
141         jit/jit-builtins.o \
142         jit/jit-spec.o \
143         gcc.o
145 ifneq (,$(findstring mingw,$(target)))
146 jit_OBJS += jit/jit-w32.o
147 endif
149 # Use strict warnings for this front end.
150 jit-warn = $(STRICT_WARN)
152 ifneq (,$(findstring mingw,$(target)))
153 # Create import library
154 LIBGCCJIT_EXTRA_OPTS = -Wl,--out-implib,$(LIBGCCJIT_IMPORT_LIB)
155 else
156 ifneq (,$(findstring darwin,$(host)))
157 LIBGCCJIT_VERS = $(LIBGCCJIT_CURRENT).$(LIBGCCJIT_REVISION).$(LIBGCCJIT_AGE)
158 LIBGCCJIT_EXTRA_OPTS = -Wl,-current_version,$(LIBGCCJIT_VERS) \
159  -Wl,-compatibility_version,$(LIBGCCJIT_COMPAT) \
160   $(LIBGCCJIT_VERSION_SCRIPT_OPTION) $(LIBGCCJIT_SONAME_OPTION)
161 # Use the default (shared) libgcc.
162 JIT_LDFLAGS = $(filter-out -static-libgcc, $(LDFLAGS))
163 ifeq (,$(findstring darwin8,$(host)))
164 JIT_LDFLAGS += -Wl,-rpath,@loader_path
165 endif
166 else
167 JIT_LDFLAGS = $(LDFLAGS)
168 LIBGCCJIT_EXTRA_OPTS = $(LIBGCCJIT_VERSION_SCRIPT_OPTION) \
169         $(LIBGCCJIT_SONAME_OPTION)
170 endif
171 endif
173 # Only link objects from $(EXTRA_GCC_OBJS) that's not already
174 # included in libbackend.a ($(EXTRA_OBJS)).
175 EXTRA_GCC_OBJS_EXCLUSIVE = $(foreach _obj1, $(EXTRA_GCC_OBJS), \
176         $(if $(filter $(_obj1), $(EXTRA_OBJS)),, $(_obj1)))
178 # We avoid using $(BACKEND) from Makefile.in in order to avoid pulling
179 # in main.o
180 $(LIBGCCJIT_FILENAME): $(jit_OBJS) \
181         libbackend.a libcommon-target.a libcommon.a \
182         $(CPPLIB) $(LIBDECNUMBER) \
183         $(LIBDEPS) $(srcdir)/jit/libgccjit.map \
184         $(EXTRA_GCC_OBJS_EXCLUSIVE) $(jit.prev)
185         @$(call LINK_PROGRESS,$(INDEX.jit),start)
186         +$(LLINKER) $(ALL_LINKERFLAGS) $(JIT_LDFLAGS) -o $@ -shared \
187              $(jit_OBJS) libbackend.a libcommon-target.a libcommon.a \
188              $(CPPLIB) $(LIBDECNUMBER) $(EXTRA_GCC_LIBS) $(LIBS) $(BACKENDLIBS) \
189              $(EXTRA_GCC_OBJS_EXCLUSIVE) \
190              $(LIBGCCJIT_EXTRA_OPTS)
191         @$(call LINK_PROGRESS,$(INDEX.jit),end)
193 # Create symlinks when not building for Windows
194 ifeq (,$(findstring mingw,$(target)))
196 ifeq (,$(findstring darwin,$(host)))
197 # but only one level for Darwin, version info is embedded.
198 $(LIBGCCJIT_SONAME_SYMLINK): $(LIBGCCJIT_FILENAME)
199         ln -sf $(LIBGCCJIT_FILENAME) $(LIBGCCJIT_SONAME_SYMLINK)
200 endif
202 $(LIBGCCJIT_LINKER_NAME_SYMLINK): $(LIBGCCJIT_SONAME_SYMLINK)
203         ln -sf $(LIBGCCJIT_SONAME_SYMLINK) $(LIBGCCJIT_LINKER_NAME_SYMLINK)
204 endif
207 # Build hooks:
209 jit.all.cross:
210 jit.start.encap:
211 jit.rest.encap:
213 # Documentation build hooks.
215 # The documentation can be built using the texinfo toolchain, or
216 # the sphinx toolchain
218 # The jit documentation is authored using Sphinx, which has numerous
219 # advantages over Texinfo, including:
221 #   * much faster
223 #   * use of CSS and JS to provide less of a 1990s feel in the generated
224 #     HTML.
226 #   * sane, stable HTML page and anchor names
228 #   * sane HTML navigation: ability to move forward and back in the HTML
229 #     at every node to read the HTML like a book
231 #   * syntax-coloring of examples
233 #   * the ability to "include" fragments of code inline.  This is used
234 #     heavily by the jit docs, so that the example code is shared by both
235 #     the test suite and the documentation to ensure that the examples
236 #     appearing in the docs actually compile and work
238 # Sphinx is not a "blessed" dependency, and so a prebuilt libgccjit.texinfo
239 # file built by Sphinx is checked into the source tree to avoid requiring
240 # everyone to have Sphinx installed.
242 # This prebuilt libgccjit.texinfo has the "include" fragments "baked in",
243 # and so contains the content from the sphinx toolchain, but lacks the
244 # syntax-coloring, and the generated HTML is (IMHO) greatly inferior to
245 # that generated by Sphinx.
247 # These targets redirect HTML creation and installation to either
248 # jit.sphinx.(install-)html or jit.texinfo.(install-)html.
249 jit.html: jit.$(doc_build_sys).html
250 jit.install-html: jit.$(doc_build_sys).install-html
252 # For now, use texinfo for pdf, since the sphinx latex toolchain currently
253 # fails for me deep inside pdflatex (see notes below)
254 jit.pdf: jit.texinfo.pdf
255 jit.install-pdf: jit.texinfo.install-pdf
257 # Hooks for building docs using texinfo
258 JIT_TEXI_FILES = $(srcdir)/jit/docs/_build/texinfo/libgccjit.texi
260 jit.info: doc/libgccjit.info
261 doc/libgccjit.info: $(JIT_TEXI_FILES)
262         if test "x$(BUILD_INFO)" = xinfo; then \
263           rm -f doc/libgccjit.info*; \
264           $(MAKEINFO) $(MAKEINFOFLAGS) -I $(gcc_docdir) \
265                 -I $(gcc_docdir)/include -o $@ $<; \
266         else true; fi
268 jit.install-info: $(DESTDIR)$(infodir)/libgccjit.info
270 jit.dvi: doc/libgccjit.dvi
271 doc/libgccjit.dvi: $(JIT_TEXI_FILES)
272         $(TEXI2DVI) -I $(abs_docdir) -I $(abs_docdir)/include -o $@ $<
274 jit.texinfo.html: $(build_htmldir)/jit/index.html
276 $(build_htmldir)/jit/index.html: $(srcdir)/jit/docs/_build/texinfo/libgccjit.texi
277         $(mkinstalldirs) $(@D)
278         rm -f $(@D)/*
279         $(TEXI2HTML) -I $(gcc_docdir)/include -I $(srcdir)/jit -o $(@D) $<
281 jit.texinfo.install-html: jit.texinfo.html
282         @$(NORMAL_INSTALL)
283         test -z "$(htmldir)" || $(mkinstalldirs) "$(DESTDIR)$(htmldir)"
284         @for p in $(build_htmldir)/jit; do \
285           if test -f "$$p" || test -d "$$p"; then d=""; else d="$(srcdir)/"; fi; \
286           f=$(html__strip_dir) \
287           if test -d "$$d$$p"; then \
288             echo " $(mkinstalldirs) '$(DESTDIR)$(htmldir)/$$f'"; \
289             $(mkinstalldirs) "$(DESTDIR)$(htmldir)/$$f" || exit 1; \
290             echo " $(INSTALL_DATA) '$$d$$p'/* '$(DESTDIR)$(htmldir)/$$f'"; \
291             $(INSTALL_DATA) "$$d$$p"/* "$(DESTDIR)$(htmldir)/$$f"; \
292           else \
293             echo " $(INSTALL_DATA) '$$d$$p' '$(DESTDIR)$(htmldir)/$$f'"; \
294             $(INSTALL_DATA) "$$d$$p" "$(DESTDIR)$(htmldir)/$$f"; \
295           fi; \
296         done
298 jit.texinfo.pdf: doc/libgccjit.pdf
300 doc/libgccjit.pdf: $(JIT_TEXI_FILES)
301         $(TEXI2PDF) -I $(abs_docdir) -I $(abs_docdir)/include -o $@ $<
303 jit.texinfo.install-pdf: doc/libgccjit.pdf
304         @$(NORMAL_INSTALL)
305         test -z "$(pdfdir)" || $(mkinstalldirs) "$(DESTDIR)$(pdfdir)/gcc"
306         @for p in doc/libgccjit.pdf; do \
307           if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
308           f=$(pdf__strip_dir) \
309           echo " $(INSTALL_DATA) '$$d$$p' '$(DESTDIR)$(pdfdir)/gcc/$$f'"; \
310           $(INSTALL_DATA) "$$d$$p" "$(DESTDIR)$(pdfdir)/gcc/$$f"; \
311         done
313 # Hooks for building docs using the Sphinx toolchain:
315 SPHINX_BUILD_DIR=jit/sphinx-build
317 jit.sphinx.html:
318         $(mkinstalldirs) $(SPHINX_BUILD_DIR)
319         (cd $(srcdir)/jit/docs && \
320           make html BUILDDIR=$(PWD)/$(SPHINX_BUILD_DIR) )
322 jit_htmldir=$(htmldir)/jit
324 jit.sphinx.install-html: jit.sphinx.html
325         @$(NORMAL_INSTALL)
326         test -z "$(jit_htmldir)" || $(mkinstalldirs) "$(DESTDIR)$(jit_htmldir)"
327         @for f in $(shell cd $(SPHINX_BUILD_DIR)/html && find) ; do \
328           if test -f $(SPHINX_BUILD_DIR)/html/"$$f"; then \
329              $(INSTALL_DATA) $(SPHINX_BUILD_DIR)/html/"$$f" $(DESTDIR)$(jit_htmldir)/"$$f"; \
330           else \
331              mkdir $(DESTDIR)$(jit_htmldir)/"$$f"; \
332           fi; \
333         done
335 # (This one is currently failing deep inside pdflatex for me;
336 # see https://bugzilla.redhat.com/show_bug.cgi?id=1148845 )
337 jit.sphinx.pdf: $(SPHINX_BUILD_DIR)/latex/libgccjit.pdf
338 $(SPHINX_BUILD_DIR)/latex/libgccjit.pdf:
339         $(mkinstalldirs) $(SPHINX_BUILD_DIR)
340         (cd $(srcdir)/jit/docs && \
341           make latexpdf BUILDDIR=$(PWD)/$(SPHINX_BUILD_DIR) )
343 jit.sphinx.install-pdf: $(SPHINX_BUILD_DIR)/latex/libgccjit.pdf
344         @$(NORMAL_INSTALL)
345         test -z "$(pdfdir)" || $(mkinstalldirs) "$(DESTDIR)$(pdfdir)/gcc"
346         @for p in $(SPHINX_BUILD_DIR)/latex/libgccjit.pdf; do \
347           if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
348           f=$(pdf__strip_dir) \
349           echo " $(INSTALL_DATA) '$$d$$p' '$(DESTDIR)$(pdfdir)/gcc/$$f'"; \
350           $(INSTALL_DATA) "$$d$$p" "$(DESTDIR)$(pdfdir)/gcc/$$f"; \
351         done
353 jit.srcinfo:
354 jit.srcextra:
356 jit.tags:
358 jit.man:
360 jit.srcman:
362 lang_checks += check-jit
363 lang_checks_parallelized += check-jit
364 # This number is somewhat arbitrary.  Two tests are much slower
365 # than all the others (test-combination.c and test-threads.c) so
366 # we want them to be placed in different "buckets".
367 check_jit_parallelize = 10
369 # No jit-specific selftests
370 selftest-jit:
373 # Install hooks:
374 jit.install-headers: installdirs
375         $(INSTALL_DATA) $(srcdir)/jit/libgccjit.h \
376           $(DESTDIR)$(includedir)/libgccjit.h
377         $(INSTALL_DATA) $(srcdir)/jit/libgccjit++.h \
378           $(DESTDIR)$(includedir)/libgccjit++.h
380 ifneq (,$(findstring mingw,$(target)))
381 jit.install-common: installdirs jit.install-headers
382 # Install import library
383         $(INSTALL_PROGRAM) $(LIBGCCJIT_IMPORT_LIB) \
384           $(DESTDIR)$(libdir)/$(LIBGCCJIT_IMPORT_LIB)
385 # Install DLL file
386         $(INSTALL_PROGRAM) $(LIBGCCJIT_FILENAME) \
387           $(DESTDIR)$(bindir)/$(LIBGCCJIT_FILENAME)
389 else
390 ifneq (,$(findstring darwin,$(host)))
391 # but only one level for Darwin
393 jit.install-common: installdirs jit.install-headers
394         $(INSTALL_PROGRAM) $(LIBGCCJIT_FILENAME) \
395           $(DESTDIR)$(libdir)/$(LIBGCCJIT_FILENAME)
396         ln -sf \
397           $(LIBGCCJIT_SONAME_SYMLINK)\
398           $(DESTDIR)$(libdir)/$(LIBGCCJIT_LINKER_NAME_SYMLINK)
400 else
401 jit.install-common: installdirs jit.install-headers
402         $(INSTALL_PROGRAM) $(LIBGCCJIT_FILENAME) \
403           $(DESTDIR)$(libdir)/$(LIBGCCJIT_FILENAME)
404         ln -sf \
405           $(LIBGCCJIT_FILENAME) \
406           $(DESTDIR)$(libdir)/$(LIBGCCJIT_SONAME_SYMLINK)
407         ln -sf \
408           $(LIBGCCJIT_SONAME_SYMLINK)\
409           $(DESTDIR)$(libdir)/$(LIBGCCJIT_LINKER_NAME_SYMLINK)
410 endif
411 endif
413 jit.install-man:
415 jit.install-plugin:
417 jit.uninstall:
420 # Clean hooks:
421 # A lot of the ancillary files are deleted by the main makefile.
422 # We just have to delete files specific to us.
424 jit.mostlyclean:
425         -rm -f $(LIBGCCJIT_FILENAME) $(LIBGCCJIT_SYMLINK)
426         -rm -f $(LIBGCCJIT_LINKER_NAME_SYMLINK) $(FULL_DRIVER_NAME)
427         -rm -f $(LIBGCCJIT_SONAME)
428         -rm -f $(jit_OBJS)
430 jit.clean:
432 jit.distclean:
434 jit.maintainer-clean:
437 # Stage hooks:
438 # The main makefile has already created stage?/jit.
440 jit.stage1: stage1-start
441         -mv jit/*$(objext) stage1/jit
442 jit.stage2: stage2-start
443         -mv jit/*$(objext) stage2/jit
444 jit.stage3: stage3-start
445         -mv jit/*$(objext) stage3/jit
446 jit.stage4: stage4-start
447         -mv jit/*$(objext) stage4/jit
448 jit.stageprofile: stageprofile-start
449         -mv jit/*$(objext) stageprofile/jit
450 jit.stagefeedback: stagefeedback-start
451         -mv jit/*$(objext) stagefeedback/jit