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