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