1# Top level -*- makefile -*- fragment for GNU C++.
2#   Copyright (C) 1994-2013 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
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
54g++spec.o: $(srcdir)/cp/g++spec.c $(SYSTEM_H) coretypes.h $(TM_H) $(GCC_H) \
55    $(CONFIG_H) $(OPTS_H)
56	(SHLIB='$(SHLIB)'; \
57	$(COMPILER) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(DRIVER_DEFINES) \
58		$(INCLUDES) $(srcdir)/cp/g++spec.c)
59
60# Create the compiler driver for g++.
61GXX_OBJS = $(GCC_OBJS) g++spec.o
62xg++$(exeext): $(GXX_OBJS) $(EXTRA_GCC_OBJS) libcommon-target.a $(LIBDEPS)
63	+$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \
64	  $(GXX_OBJS) $(EXTRA_GCC_OBJS) libcommon-target.a \
65	  $(EXTRA_GCC_LIBS) $(LIBS)
66
67# Create a version of the g++ driver which calls the cross-compiler.
68g++-cross$(exeext): xg++$(exeext)
69	-rm -f g++-cross$(exeext)
70	cp xg++$(exeext) g++-cross$(exeext)
71
72# The compiler itself.
73# Shared with C front end:
74CXX_C_OBJS = attribs.o incpath.o \
75	$(C_COMMON_OBJS) $(CXX_TARGET_OBJS)
76
77# Language-specific object files for C++ and Objective C++.
78CXX_AND_OBJCXX_OBJS = cp/call.o cp/decl.o cp/expr.o cp/pt.o cp/typeck2.o \
79 cp/class.o cp/decl2.o cp/error.o cp/lex.o cp/parser.o cp/ptree.o cp/rtti.o \
80 cp/typeck.o cp/cvt.o cp/except.o cp/friend.o cp/init.o cp/method.o \
81 cp/search.o cp/semantics.o cp/tree.o cp/repo.o cp/dump.o cp/optimize.o \
82 cp/mangle.o cp/cp-objcp-common.o cp/name-lookup.o cp/cxx-pretty-print.o \
83 cp/cp-gimplify.o $(CXX_C_OBJS)
84
85# Language-specific object files for C++.
86CXX_OBJS = cp/cp-lang.o c-family/stub-objc.o $(CXX_AND_OBJCXX_OBJS)
87
88c++_OBJS = $(CXX_OBJS) cc1plus-checksum.o cp/g++spec.o
89
90# Use strict warnings for this front end.
91cp-warn = $(STRICT_WARN)
92
93# compute checksum over all object files and the options
94cc1plus-checksum.c : build/genchecksum$(build_exeext) checksum-options \
95	$(CXX_OBJS) $(BACKEND) $(LIBDEPS)
96	build/genchecksum$(build_exeext) $(CXX_OBJS) $(BACKEND) $(LIBDEPS) \
97                     checksum-options > cc1plus-checksum.c.tmp &&	   \
98	$(srcdir)/../move-if-change cc1plus-checksum.c.tmp cc1plus-checksum.c
99
100cc1plus-checksum.o : cc1plus-checksum.c $(CONFIG_H) $(SYSTEM_H)
101
102cc1plus$(exeext): $(CXX_OBJS) cc1plus-checksum.o $(BACKEND) $(LIBDEPS)
103	+$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \
104	      $(CXX_OBJS) cc1plus-checksum.o $(BACKEND) $(LIBS) $(BACKENDLIBS)
105
106ifeq ($(ENABLE_MAINTAINER_RULES), true)
107# Special build rule.  This is a maintainer rule, that is only
108# available when GCC is configured with --enable-maintainer-mode.  In
109# other cases, it is not available to avoid triggering rebuilds if a
110# user has the source checked out with unusual timestamps.
111$(srcdir)/cp/cfns.h: $(srcdir)/cp/cfns.gperf
112else
113# We keep the rule so that you can still force a rebuild, even if you
114# didn't configure GCC with --enable-maintainer-mode, by manually
115# deleting the $(srcdir)/cp/cfns.h file.
116$(srcdir)/cp/cfns.h:
117endif
118	gperf -o -C -E -k '1-6,$$' -j1 -D -N 'libc_name_p' -L ANSI-C \
119		$(srcdir)/cp/cfns.gperf --output-file $(srcdir)/cp/cfns.h
120
121#
122# Build hooks:
123
124c++.all.cross: g++-cross$(exeext)
125c++.start.encap: xg++$(exeext)
126c++.rest.encap:
127c++.info:
128c++.install-info:
129c++.dvi:
130c++.pdf:
131c++.install-pdf:
132c++.install-html:
133c++.html:
134c++.srcinfo:
135c++.srcextra:
136
137c++.tags: force
138	cd $(srcdir)/cp; etags -o TAGS.sub *.c *.h --language=none \
139	  --regex='/DEFTREECODE [(]\([A-Z_]+\)/\1/' cp-tree.def; \
140	etags --include TAGS.sub --include ../TAGS.sub
141
142c++.man: doc/g++.1
143
144c++.srcman: doc/g++.1
145	-cp -p $^ $(srcdir)/doc
146
147# 'make check' in gcc/ looks for check-c++, as do all toplevel C++-related
148# check targets.  However, our DejaGNU framework requires 'check-g++' as its
149# entry point.  We feed the former to the latter here.
150check-c++ : check-g++
151# Run the testsute in C++0x mode.
152check-c++0x:
153	@echo Normal 'make check' now runs the testsuite in C++11 mode as well as C++98.
154# Run the testsuite with garbage collection at every opportunity.
155check-g++-strict-gc:
156	$(MAKE) RUNTESTFLAGS="$(RUNTESTFLAGS) --extra_opts,--param,ggc-min-heapsize=0,--param,ggc-min-expand=0" \
157	  TESTSUITEDIR="$(TESTSUITEDIR).gc" check-g++
158check-c++-subtargets : check-g++-subtargets
159# List of targets that can use the generic check- rule and its // variant.
160lang_checks += check-g++
161lang_checks_parallelized += check-g++
162# For description see comment above check_gcc_parallelize in gcc/Makefile.in.
163check_g++_parallelize = old-deja.exp dg.exp dg-torture.exp
164
165#
166# Install hooks:
167# cc1plus is installed elsewhere as part of $(COMPILERS).
168
169# Install the driver program as $(target)-g++
170# and also as either g++ (if native) or $(tooldir)/bin/g++.
171c++.install-common: installdirs
172	-rm -f $(DESTDIR)$(bindir)/$(GXX_INSTALL_NAME)$(exeext)
173	-$(INSTALL_PROGRAM) xg++$(exeext) $(DESTDIR)$(bindir)/$(GXX_INSTALL_NAME)$(exeext)
174	-chmod a+x $(DESTDIR)$(bindir)/$(GXX_INSTALL_NAME)$(exeext)
175	-rm -f $(DESTDIR)$(bindir)/$(CXX_INSTALL_NAME)$(exeext)
176	-( cd $(DESTDIR)$(bindir) && \
177	      $(LN) $(GXX_INSTALL_NAME)$(exeext) $(CXX_INSTALL_NAME)$(exeext) )
178	-if [ -f cc1plus$(exeext) ] ; then \
179	  if [ -f g++-cross$(exeext) ] ; then \
180	    if [ -d $(DESTDIR)$(gcc_tooldir)/bin/. ] ; then \
181	      rm -f $(DESTDIR)$(gcc_tooldir)/bin/g++$(exeext); \
182	      $(INSTALL_PROGRAM) g++-cross$(exeext) $(DESTDIR)$(gcc_tooldir)/bin/g++$(exeext); \
183	      rm -f $(DESTDIR)$(gcc_tooldir)/bin/c++$(exeext); \
184	      ( cd $(DESTDIR)$(gcc_tooldir)/bin && \
185		$(LN) g++$(exeext) c++$(exeext) ); \
186	    else true; fi; \
187	  else \
188	    rm -f $(DESTDIR)$(bindir)/$(GXX_TARGET_INSTALL_NAME)$(exeext); \
189	    ( cd $(DESTDIR)$(bindir) && \
190	      $(LN) $(GXX_INSTALL_NAME)$(exeext) $(GXX_TARGET_INSTALL_NAME)$(exeext) ); \
191	    rm -f $(DESTDIR)$(bindir)/$(CXX_TARGET_INSTALL_NAME)$(exeext); \
192	    ( cd $(DESTDIR)$(bindir) && \
193	      $(LN) $(CXX_INSTALL_NAME)$(exeext) $(CXX_TARGET_INSTALL_NAME)$(exeext) ); \
194	  fi ; \
195	fi
196
197# We can't use links because not everyone supports them.  So just copy the
198# manpage.
199doc/g++.1: doc/gcc.1
200	cp $< doc/g++.1
201
202c++.install-man: $(DESTDIR)$(man1dir)/$(GXX_INSTALL_NAME)$(man1ext)
203
204$(DESTDIR)$(man1dir)/$(GXX_INSTALL_NAME)$(man1ext): doc/g++.1 installdirs
205	-rm -f $@
206	-$(INSTALL_DATA) $< $@
207	-chmod a-x $@
208
209c++.install-plugin: installdirs
210# We keep the directory structure for files in config and .def files. All
211# other files are flattened to a single directory.
212	headers="$(CP_PLUGIN_HEADERS)"; \
213	for file in $$headers; do \
214	  path=$(srcdir)/cp/$$file; \
215	  dest=$(plugin_includedir)/cp/$$file; \
216	  echo $(INSTALL_DATA) $$path $(DESTDIR)$$dest; \
217	  dir=`dirname $$dest`; \
218	  $(mkinstalldirs) $(DESTDIR)$$dir; \
219	  $(INSTALL_DATA) $$path $(DESTDIR)$$dest; \
220	done
221
222c++.uninstall:
223	-rm -rf $(DESTDIR)$(bindir)/$(CXX_INSTALL_NAME)$(exeext)
224	-rm -rf $(DESTDIR)$(bindir)/$(GXX_INSTALL_NAME)$(exeext)
225	-rm -rf $(DESTDIR)$(man1dir)/$(GXX_INSTALL_NAME)$(man1ext)
226#
227# Clean hooks:
228# A lot of the ancillary files are deleted by the main makefile.
229# We just have to delete files specific to us.
230
231c++.mostlyclean:
232	-rm -f doc/g++.1
233	-rm -f cp/*$(objext)
234	-rm -f cp/*$(coverageexts)
235c++.clean:
236c++.distclean:
237	-rm -f cp/config.status cp/Makefile
238	-rm -f cxxmain.c
239c++.maintainer-clean:
240#
241# Stage hooks:
242# The main makefile has already created stage?/cp.
243
244c++.stage1: stage1-start
245	-mv cp/*$(objext) stage1/cp
246c++.stage2: stage2-start
247	-mv cp/*$(objext) stage2/cp
248c++.stage3: stage3-start
249	-mv cp/*$(objext) stage3/cp
250c++.stage4: stage4-start
251	-mv cp/*$(objext) stage4/cp
252c++.stageprofile: stageprofile-start
253	-mv cp/*$(objext) stageprofile/cp
254c++.stagefeedback: stagefeedback-start
255	-mv cp/*$(objext) stagefeedback/cp
256
257#
258# .o: .h dependencies.
259CXX_TREE_H = $(TREE_H) cp/name-lookup.h cp/cp-tree.h $(C_COMMON_H) \
260	$(FUNCTION_H) \
261	$(SYSTEM_H) coretypes.h $(CONFIG_H) $(TARGET_H) $(GGC_H) \
262	$(srcdir)/../include/hashtab.h
263CXX_PARSER_H = tree.h c-family/c-pragma.h cp/parser.h
264CXX_PRETTY_PRINT_H = cp/cxx-pretty-print.h $(C_PRETTY_PRINT_H)
265
266cp/lex.o: cp/lex.c $(CXX_TREE_H) $(TM_H) $(FLAGS_H) \
267  $(C_PRAGMA_H) input.h cp/operators.def $(TM_P_H) \
268  c-family/c-objc.h
269cp/cp-lang.o: cp/cp-lang.c $(CXX_TREE_H) $(TM_H) debug.h langhooks.h \
270  $(LANGHOOKS_DEF_H) $(C_COMMON_H) gtype-cp.h gt-cp-cp-lang.h \
271  cp/cp-objcp-common.h $(EXPR_H) $(TARGET_H) $(CXX_PARSER_H)
272cp/decl.o: cp/decl.c $(CXX_TREE_H) $(TM_H) $(FLAGS_H) cp/decl.h \
273  output.h toplev.h $(HASHTAB_H) $(RTL_H) \
274  cp/operators.def $(TM_P_H) $(TREE_INLINE_H) $(DIAGNOSTIC_H) $(C_PRAGMA_H) \
275  debug.h gt-cp-decl.h $(TIMEVAR_H) $(TARGET_H) $(PLUGIN_H) \
276  intl.h tree-iterator.h pointer-set.h $(SPLAY_TREE_H) \
277  c-family/c-objc.h
278cp/decl2.o: cp/decl2.c $(CXX_TREE_H) $(TM_H) $(FLAGS_H) cp/decl.h \
279  toplev.h $(C_COMMON_H) gt-cp-decl2.h $(CGRAPH_H) \
280  $(C_PRAGMA_H) dumpfile.h intl.h $(TARGET_H) $(GIMPLE_H) pointer-set.h \
281  $(SPLAY_TREE_H) c-family/c-ada-spec.h \
282  c-family/c-objc.h
283cp/cp-objcp-common.o : cp/cp-objcp-common.c $(CONFIG_H) $(SYSTEM_H) \
284  coretypes.h $(TM_H) $(TREE_H) $(CXX_TREE_H) $(C_COMMON_H) \
285  langhooks.h $(LANGHOOKS_DEF_H) $(DIAGNOSTIC_H) debug.h \
286  $(CXX_PRETTY_PRINT_H) cp/cp-objcp-common.h gt-cp-cp-objcp-common.h
287cp/typeck2.o: cp/typeck2.c $(CXX_TREE_H) $(TM_H) $(FLAGS_H) \
288  $(TM_P_H) $(DIAGNOSTIC_CORE_H) gt-cp-typeck2.h $(REAL_H) intl.h
289cp/typeck.o: cp/typeck.c $(CXX_TREE_H) $(TM_H) $(FLAGS_H) $(PARAMS_H) \
290  toplev.h $(DIAGNOSTIC_H) convert.h $(C_COMMON_H) $(TARGET_H) \
291  c-family/c-objc.h
292cp/class.o: cp/class.c $(CXX_TREE_H) $(TM_H) $(FLAGS_H) toplev.h \
293  $(TARGET_H) convert.h $(CGRAPH_H) dumpfile.h gt-cp-class.h \
294  $(SPLAY_TREE_H) pointer-set.h $(HASH_TABLE_H)
295cp/call.o: cp/call.c $(CXX_TREE_H) $(TM_H) $(FLAGS_H) toplev.h \
296  $(DIAGNOSTIC_CORE_H) intl.h gt-cp-call.h convert.h $(TARGET_H) langhooks.h \
297  $(TIMEVAR_H) c-family/c-objc.h
298cp/friend.o: cp/friend.c $(CXX_TREE_H) $(TM_H) $(FLAGS_H)
299cp/init.o: cp/init.c $(CXX_TREE_H) $(TM_H) $(FLAGS_H) \
300  $(EXCEPT_H) $(TARGET_H)
301cp/method.o: cp/method.c $(CXX_TREE_H) $(TM_H) toplev.h \
302  $(TM_P_H) $(TARGET_H) $(DIAGNOSTIC_H) gt-cp-method.h $(GIMPLE_H) \
303  $(COMMON_TARGET_H)
304cp/cvt.o: cp/cvt.c $(CXX_TREE_H) $(TM_H) cp/decl.h $(FLAGS_H) \
305  convert.h $(TARGET_H) intl.h
306cp/search.o: cp/search.c $(CXX_TREE_H) $(TM_H) $(FLAGS_H) toplev.h \
307  intl.h
308cp/tree.o: cp/tree.c $(CXX_TREE_H) $(TM_H) $(FLAGS_H) \
309  $(TREE_INLINE_H) $(REAL_H) gt-cp-tree.h \
310  $(TARGET_H) debug.h $(CGRAPH_H) $(SPLAY_TREE_H) $(GIMPLE_H) $(HASH_TABLE_H)
311cp/ptree.o: cp/ptree.c $(CXX_TREE_H) $(TM_H)
312cp/rtti.o: cp/rtti.c $(CXX_TREE_H) $(TM_H) $(FLAGS_H) convert.h \
313  $(TARGET_H) $(C_PRAGMA_H) gt-cp-rtti.h intl.h
314cp/except.o: cp/except.c $(CXX_TREE_H) $(TM_H) $(FLAGS_H) \
315  cp/cfns.h $(TREE_INLINE_H) $(TARGET_H) gt-cp-except.h
316cp/expr.o: cp/expr.c $(CXX_TREE_H) $(TM_H) $(FLAGS_H) $(TM_P_H)
317cp/pt.o: cp/pt.c $(CXX_TREE_H) $(TM_H) cp/decl.h cp/cp-objcp-common.h \
318  toplev.h $(TREE_INLINE_H) pointer-set.h gt-cp-pt.h intl.h \
319  c-family/c-objc.h
320cp/error.o: cp/error.c $(CXX_TREE_H) $(TM_H) $(DIAGNOSTIC_H) \
321  $(FLAGS_H) $(REAL_H) $(LANGHOOKS_DEF_H) $(CXX_PRETTY_PRINT_H) \
322  tree-diagnostic.h tree-pretty-print.h pointer-set.h c-family/c-objc.h
323cp/repo.o: cp/repo.c $(CXX_TREE_H) $(TM_H) toplev.h $(DIAGNOSTIC_CORE_H) \
324  gt-cp-repo.h
325cp/semantics.o: cp/semantics.c $(CXX_TREE_H) $(TM_H) toplev.h \
326  $(FLAGS_H) $(RTL_H) $(TIMEVAR_H) \
327  $(TREE_INLINE_H) $(CGRAPH_H) $(TARGET_H) $(C_COMMON_H) $(GIMPLE_H) \
328  bitmap.h gt-cp-semantics.h c-family/c-objc.h $(HASH_TABLE_H)
329cp/dump.o: cp/dump.c $(CXX_TREE_H) $(TM_H) $(TREE_DUMP_H)
330cp/optimize.o: cp/optimize.c $(CXX_TREE_H) $(TM_H) \
331  input.h $(PARAMS_H) debug.h $(TREE_INLINE_H) $(GIMPLE_H) \
332  $(TARGET_H) tree-iterator.h $(CGRAPH_H) $(DIAGNOSTIC_CORE_H) \
333  dumpfile.h
334cp/mangle.o: cp/mangle.c $(CXX_TREE_H) $(TM_H) $(REAL_H) \
335  gt-cp-mangle.h $(TARGET_H) $(TM_P_H) $(CGRAPH_H)
336cp/parser.o: cp/parser.c $(CXX_TREE_H) $(TM_H) $(DIAGNOSTIC_CORE_H) \
337  gt-cp-parser.h $(TARGET_H) $(PLUGIN_H) intl.h cp/decl.h \
338  c-family/c-objc.h tree-pretty-print.h $(CXX_PARSER_H) $(TIMEVAR_H)
339cp/cp-gimplify.o: cp/cp-gimplify.c $(CXX_TREE_H) $(C_COMMON_H) \
340	$(TM_H) coretypes.h pointer-set.h tree-iterator.h $(SPLAY_TREE_H)
341
342cp/name-lookup.o: cp/name-lookup.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \
343	$(TM_H) $(CXX_TREE_H) $(TIMEVAR_H) gt-cp-name-lookup.h $(PARAMS_H) \
344	$(DIAGNOSTIC_CORE_H) $(FLAGS_H) debug.h pointer-set.h
345
346cp/cxx-pretty-print.o: cp/cxx-pretty-print.c $(CXX_PRETTY_PRINT_H) \
347  $(CONFIG_H) $(SYSTEM_H) $(TM_H) coretypes.h $(CXX_TREE_H) tree-pretty-print.h
348