1# Top level -*- makefile -*- fragment for GNU C++.
2#   Copyright (C) 1994-2019 Free Software Foundation, Inc.
3
4#This file is part of GCC.
5
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.
10
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.
15
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/>.
19
20# This file provides the language dependent support in the main Makefile.
21# Each language makefile fragment must provide the following targets:
22#
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
28#
29# where `foo' is the name of the language.
30#
31# It should also provide rules for:
32#
33# - making any compiler driver (eg: g++)
34# - the compiler proper (eg: cc1plus)
35# - define the names for selecting the language in LANGUAGES.
36
37# Actual names to use when installing a native compiler.
38CXX_INSTALL_NAME := $(shell echo c++|sed '$(program_transform_name)')
39GXX_INSTALL_NAME := $(shell echo g++|sed '$(program_transform_name)')
40CXX_TARGET_INSTALL_NAME := $(target_noncanonical)-$(shell echo c++|sed '$(program_transform_name)')
41GXX_TARGET_INSTALL_NAME := $(target_noncanonical)-$(shell echo g++|sed '$(program_transform_name)')
42CP_PLUGIN_HEADERS := cp-tree.h cxx-pretty-print.h name-lookup.h type-utils.h operators.def
43
44#
45# Define the names for selecting c++ in LANGUAGES.
46# Note that it would be nice to move the dependency on g++
47# into the C++ rule, but that needs a little bit of work
48# to do the right thing within all.cross.
49c++: cc1plus$(exeext)
50
51# Tell GNU make to ignore these if they exist.
52.PHONY: c++
53
54CFLAGS-cp/g++spec.o += $(DRIVER_DEFINES)
55
56# Create the compiler driver for g++.
57GXX_OBJS = $(GCC_OBJS) cp/g++spec.o
58xg++$(exeext): $(GXX_OBJS) $(EXTRA_GCC_OBJS) libcommon-target.a $(LIBDEPS)
59	+$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \
60	  $(GXX_OBJS) $(EXTRA_GCC_OBJS) libcommon-target.a \
61	  $(EXTRA_GCC_LIBS) $(LIBS)
62
63# Create a version of the g++ driver which calls the cross-compiler.
64g++-cross$(exeext): xg++$(exeext)
65	-rm -f g++-cross$(exeext)
66	cp xg++$(exeext) g++-cross$(exeext)
67
68# The compiler itself.
69# Shared with C front end:
70CXX_C_OBJS = attribs.o incpath.o \
71	$(C_COMMON_OBJS) $(CXX_TARGET_OBJS)
72
73# Language-specific object files for C++ and Objective C++.
74CXX_AND_OBJCXX_OBJS = \
75	cp/call.o cp/class.o cp/constexpr.o cp/constraint.o \
76	cp/cp-gimplify.o \
77	cp/cp-objcp-common.o cp/cp-ubsan.o \
78	cp/cvt.o cp/cxx-pretty-print.o \
79	cp/decl.o cp/decl2.o cp/dump.o \
80	cp/error.o cp/except.o cp/expr.o \
81	cp/friend.o cp/init.o \
82	cp/lambda.o cp/lex.o cp/logic.o \
83	cp/mangle.o cp/method.o \
84	cp/name-lookup.o cp/optimize.o \
85	cp/parser.o cp/pt.o cp/ptree.o \
86	cp/repo.o cp/rtti.o \
87	cp/search.o cp/semantics.o \
88	cp/tree.o cp/typeck.o cp/typeck2.o \
89	cp/vtable-class-hierarchy.o $(CXX_C_OBJS)
90
91ifeq ($(if $(wildcard ../stage_current),$(shell cat \
92  ../stage_current)),stageautofeedback)
93$(CXX_AND_OBJCXX_OBJS): CFLAGS += -fauto-profile=cc1plus.fda
94$(CXX_AND_OBJCXX_OBJS): cc1plus.fda
95endif
96
97# Language-specific object files for C++.
98CXX_OBJS = cp/cp-lang.o c-family/stub-objc.o $(CXX_AND_OBJCXX_OBJS)
99
100c++_OBJS = $(CXX_OBJS) cc1plus-checksum.o cp/g++spec.o
101
102# Use strict warnings for this front end.
103cp-warn = $(STRICT_WARN)
104
105# compute checksum over all object files and the options
106# re-use the checksum from the prev-final stage so it passes
107# the bootstrap comparison and allows comparing of the cc1 binary
108cc1plus-checksum.c : build/genchecksum$(build_exeext) checksum-options \
109	$(CXX_OBJS) $(BACKEND) $(LIBDEPS)
110	if [ -f ../stage_final ] \
111	   && cmp -s ../stage_current ../stage_final; then \
112	   cp ../prev-gcc/cc1plus-checksum.c cc1plus-checksum.c; \
113	else \
114	  build/genchecksum$(build_exeext) $(CXX_OBJS) $(BACKEND) $(LIBDEPS) \
115                     checksum-options > cc1plus-checksum.c.tmp &&	   \
116	  $(srcdir)/../move-if-change cc1plus-checksum.c.tmp cc1plus-checksum.c; \
117	fi
118
119cc1plus$(exeext): $(CXX_OBJS) cc1plus-checksum.o $(BACKEND) $(LIBDEPS)
120	+$(LLINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \
121	      $(CXX_OBJS) cc1plus-checksum.o $(BACKEND) $(LIBS) $(BACKENDLIBS)
122
123ifeq ($(ENABLE_MAINTAINER_RULES), true)
124# Special build rule.  This is a maintainer rule, that is only
125# available when GCC is configured with --enable-maintainer-mode.  In
126# other cases, it is not available to avoid triggering rebuilds if a
127# user has the source checked out with unusual timestamps.
128$(srcdir)/cp/cfns.h: $(srcdir)/cp/cfns.gperf
129else
130# We keep the rule so that you can still force a rebuild, even if you
131# didn't configure GCC with --enable-maintainer-mode, by manually
132# deleting the $(srcdir)/cp/cfns.h file.
133$(srcdir)/cp/cfns.h:
134endif
135	gperf -o -C -E -k '1-6,$$' -j1 -D -N 'libc_name_p' -L C++ \
136		$(srcdir)/cp/cfns.gperf --output-file $(srcdir)/cp/cfns.h
137
138cc1plus.fda: ../stage1-gcc/cc1plus$(exeext) ../prev-gcc/$(PERF_DATA)
139	$(CREATE_GCOV) -binary ../stage1-gcc/cc1plus$(exeext) -gcov cc1plus.fda -profile ../prev-gcc/$(PERF_DATA) -gcov_version 1
140
141#
142# Build hooks:
143
144c++.all.cross: g++-cross$(exeext)
145c++.start.encap: xg++$(exeext)
146c++.rest.encap:
147c++.info:
148c++.install-info:
149c++.dvi:
150c++.pdf:
151c++.install-pdf:
152c++.install-html:
153c++.html:
154c++.srcinfo:
155c++.srcextra:
156
157c++.tags: force
158	cd $(srcdir)/cp; etags -o TAGS.sub *.c *.cc *.h --language=none \
159	  --regex='/DEFTREECODE [(]\([A-Z_]+\)/\1/' cp-tree.def; \
160	etags --include TAGS.sub --include ../TAGS.sub
161
162c++.man: doc/g++.1
163
164c++.srcman: doc/g++.1
165	-cp -p $^ $(srcdir)/doc
166
167# C++ selftests
168
169# If C++ is enabled, require the selftests to be run for it
170# at each stage of the build:
171selftest-c++: s-selftest-c++
172
173CPP_SELFTEST_DEPS = cc1plus$(exeext) $(SELFTEST_DEPS)
174CPP_SELFTEST_FLAGS = -xc++ $(SELFTEST_FLAGS)
175
176# Run the C++ selftests
177s-selftest-c++: $(CPP_SELFTEST_DEPS)
178	$(GCC_FOR_TARGET) $(CPP_SELFTEST_FLAGS)
179	$(STAMP) $@
180
181# Convenience method for running C++ selftests under gdb:
182.PHONY: selftest-c++-gdb
183selftest-c++-gdb: $(CPP_SELFTEST_DEPS)
184	$(GCC_FOR_TARGET) $(CPP_SELFTEST_FLAGS) \
185	  -wrapper gdb,--args
186
187# Convenience method for running C++ selftests under valgrind:
188.PHONY: selftest-c++-valgrind
189selftest-c++-valgrind: $(CPP_SELFTEST_DEPS)
190	$(GCC_FOR_TARGET) $(CPP_SELFTEST_FLAGS) \
191	  -wrapper valgrind,--leak-check=full
192
193# 'make check' in gcc/ looks for check-c++, as do all toplevel C++-related
194# check targets.  However, our DejaGNU framework requires 'check-g++' as its
195# entry point.  We feed the former to the latter here.
196check-c++ : check-g++
197
198# Run the testsuite in C++17 mode.
199check-c++1z: check-c++17
200check-c++17:
201	$(MAKE) RUNTESTFLAGS="$(RUNTESTFLAGS)" GXX_TESTSUITE_STDS=17 check-g++
202
203# Run the testsuite in all standard conformance levels.
204check-c++-all:
205	$(MAKE) RUNTESTFLAGS="$(RUNTESTFLAGS) --stds=98,11,14,17,2a,concepts" check-g++
206
207# Run the testsuite with garbage collection at every opportunity.
208check-g++-strict-gc:
209	$(MAKE) RUNTESTFLAGS="$(RUNTESTFLAGS) --extra_opts,--param,ggc-min-heapsize=0,--param,ggc-min-expand=0" \
210	  TESTSUITEDIR="$(TESTSUITEDIR).gc" check-g++
211check-c++-subtargets : check-g++-subtargets
212# List of targets that can use the generic check- rule and its // variant.
213lang_checks += check-g++
214lang_checks_parallelized += check-g++
215# For description see the check_$lang_parallelize comment in gcc/Makefile.in.
216check_g++_parallelize = 10000
217#
218# Install hooks:
219# cc1plus is installed elsewhere as part of $(COMPILERS).
220
221# Install the driver program as $(target)-g++ and $(target)-c++, and
222# also as g++ and c++ if native.
223c++.install-common: installdirs
224	-if test "$(enable_as_accelerator)" != "yes" ; then \
225	  rm -f $(DESTDIR)$(bindir)/$(GXX_INSTALL_NAME)$(exeext); \
226	  $(INSTALL_PROGRAM) xg++$(exeext) $(DESTDIR)$(bindir)/$(GXX_INSTALL_NAME)$(exeext); \
227	  chmod a+x $(DESTDIR)$(bindir)/$(GXX_INSTALL_NAME)$(exeext); \
228	  rm -f $(DESTDIR)$(bindir)/$(CXX_INSTALL_NAME)$(exeext); \
229	  ( cd $(DESTDIR)$(bindir) && \
230	    $(LN) $(GXX_INSTALL_NAME)$(exeext) $(CXX_INSTALL_NAME)$(exeext) ); \
231	  if [ -f cc1plus$(exeext) ] ; then \
232	    if [ ! -f g++-cross$(exeext) ] ; then \
233	      rm -f $(DESTDIR)$(bindir)/$(GXX_TARGET_INSTALL_NAME)$(exeext); \
234	      ( cd $(DESTDIR)$(bindir) && \
235		$(LN) $(GXX_INSTALL_NAME)$(exeext) $(GXX_TARGET_INSTALL_NAME)$(exeext) ); \
236	      rm -f $(DESTDIR)$(bindir)/$(CXX_TARGET_INSTALL_NAME)$(exeext); \
237	      ( cd $(DESTDIR)$(bindir) && \
238		$(LN) $(CXX_INSTALL_NAME)$(exeext) $(CXX_TARGET_INSTALL_NAME)$(exeext) ); \
239	    fi ; \
240	  fi; \
241	fi
242
243# We can't use links because not everyone supports them.  So just copy the
244# manpage.
245doc/g++.1: doc/gcc.1
246	cp $< doc/g++.1
247
248c++.install-man: $(DESTDIR)$(man1dir)/$(GXX_INSTALL_NAME)$(man1ext)
249
250$(DESTDIR)$(man1dir)/$(GXX_INSTALL_NAME)$(man1ext): doc/g++.1 installdirs
251	-rm -f $@
252	-$(INSTALL_DATA) $< $@
253	-chmod a-x $@
254
255c++.install-plugin: installdirs
256# We keep the directory structure for files in config and .def files. All
257# other files are flattened to a single directory.
258	headers="$(CP_PLUGIN_HEADERS)"; \
259	for file in $$headers; do \
260	  path=$(srcdir)/cp/$$file; \
261	  dest=$(plugin_includedir)/cp/$$file; \
262	  echo $(INSTALL_DATA) $$path $(DESTDIR)$$dest; \
263	  dir=`dirname $$dest`; \
264	  $(mkinstalldirs) $(DESTDIR)$$dir; \
265	  $(INSTALL_DATA) $$path $(DESTDIR)$$dest; \
266	done
267# Install import library.
268ifeq ($(plugin_implib),yes)
269	$(mkinstalldirs) $(DESTDIR)$(plugin_resourcesdir)
270	$(INSTALL_DATA) cc1plus$(exeext).a $(DESTDIR)/$(plugin_resourcesdir)/cc1plus$(exeext).a
271endif
272
273c++.uninstall:
274	-rm -rf $(DESTDIR)$(bindir)/$(CXX_INSTALL_NAME)$(exeext)
275	-rm -rf $(DESTDIR)$(bindir)/$(GXX_INSTALL_NAME)$(exeext)
276	-rm -rf $(DESTDIR)$(man1dir)/$(GXX_INSTALL_NAME)$(man1ext)
277#
278# Clean hooks:
279# A lot of the ancillary files are deleted by the main makefile.
280# We just have to delete files specific to us.
281
282c++.mostlyclean:
283	-rm -f doc/g++.1
284	-rm -f cp/*$(objext)
285	-rm -f cp/*$(coverageexts)
286	-rm -f xg++$(exeext) g++-cross$(exeext) cc1plus$(exeext) cc1plus.fda
287c++.clean:
288c++.distclean:
289	-rm -f cp/config.status cp/Makefile
290	-rm -f cxxmain.c
291c++.maintainer-clean:
292#
293# Stage hooks:
294# The main makefile has already created stage?/cp.
295
296c++.stage1: stage1-start
297	-mv cp/*$(objext) stage1/cp
298c++.stage2: stage2-start
299	-mv cp/*$(objext) stage2/cp
300c++.stage3: stage3-start
301	-mv cp/*$(objext) stage3/cp
302c++.stage4: stage4-start
303	-mv cp/*$(objext) stage4/cp
304c++.stageprofile: stageprofile-start
305	-mv cp/*$(objext) stageprofile/cp
306c++.stagefeedback: stagefeedback-start
307	-mv cp/*$(objext) stagefeedback/cp
308c++.autostageprofile: stageprofile-start
309	-mv cp/*$(objext) autostageprofile/cp
310c++.autostagefeedback: stagefeedback-start
311	-mv cp/*$(objext) autostagefeedback/cp
312