1## Makefile for the C++11 sources of the GNU C++ Standard library.
2##
3## Copyright (C) 1997-2022 Free Software Foundation, Inc.
4##
5## This file is part of the libstdc++ version 3 distribution.
6## Process this file with automake to produce Makefile.in.
7
8## This file is part of the GNU ISO C++ Library.  This library is free
9## software; you can redistribute it and/or modify it under the
10## terms of the GNU General Public License as published by the
11## Free Software Foundation; either version 3, or (at your option)
12## any later version.
13
14## This library is distributed in the hope that it will be useful,
15## but WITHOUT ANY WARRANTY; without even the implied warranty of
16## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17## GNU General Public License for more details.
18
19## You should have received a copy of the GNU General Public License along
20## with this library; see the file COPYING3.  If not see
21## <http://www.gnu.org/licenses/>.
22
23include $(top_srcdir)/fragment.am
24
25if ENABLE_FILESYSTEM_TS
26filesystem_dir = filesystem
27else
28filesystem_dir =
29endif
30
31if ENABLE_BACKTRACE
32backtrace_dir = libbacktrace
33backtrace_supported_h = $(backtrace_dir)/backtrace-supported.h
34else
35backtrace_dir =
36backtrace_supported_h =
37endif
38
39## Keep this list sync'd with acinclude.m4:GLIBCXX_CONFIGURE.
40SUBDIRS = c++98 c++11 c++17 c++20 $(filesystem_dir) $(backtrace_dir)
41
42# Cross compiler support.
43if VTV_CYGMIN
44toolexeclib_LTLIBRARIES = libvtv.la libstdc++.la
45else
46toolexeclib_LTLIBRARIES = libstdc++.la
47endif
48
49if VTV_CYGMIN
50vtv_stubs.cc:
51          rm -f $@
52          $(LN_S) $(toplevel_srcdir)/libstdc++-v3/libsupc++/vtv_stubs.cc $@
53
54libvtv_la_SOURCES = vtv_stubs.cc
55libvtv_la_LDFLAGS = $(lt_host_flags)
56
57libvtv_la_AM_CXXFLAGS = \
58          $(glibcxx_compiler_pic_flag) \
59          $(XTEMPLATE_FLAGS) \
60          -Wl,-u_vtable_map_vars_start,-u_vtable_map_vars_end \
61          $(WARN_CXXFLAGS) $(OPTIMIZE_CXXFLAGS) $(CONFIG_CXXFLAGS)
62
63libvtv_la_LINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) \
64          $(LIBTOOLFLAGS) --mode=link $(CXXLD) $(libvtv_la_AM_CXXFLAGS) \
65          $(CXXFLAGS) $(libvtv_la_LDFLAGS) $(LDFLAGS) -o $@
66endif
67
68vpath % $(top_srcdir)/src/c++98
69vpath % $(top_srcdir)/src/c++11
70vpath % $(top_srcdir)/src/c++17
71vpath % $(top_srcdir)/src/c++20
72if ENABLE_FILESYSTEM_TS
73vpath % $(top_srcdir)/src/filesystem
74endif
75if ENABLE_BACKTRACE
76vpath % $(top_srcdir)/src/libbacktrace
77endif
78
79if GLIBCXX_LDBL_COMPAT
80ldbl_compat_sources = compatibility-ldbl.cc
81else
82ldbl_compat_sources =
83endif
84
85if GLIBCXX_LDBL_ALT128_COMPAT
86if ENABLE_DUAL_ABI
87ldbl_alt128_compat_cxx11_sources = \
88          compatibility-ldbl-alt128-cxx11.cc
89else
90ldbl_alt128_compat_cxx11_sources =
91endif
92ldbl_alt128_compat_sources = \
93          compatibility-ldbl-alt128.cc \
94          ${ldbl_alt128_compat_cxx11_sources}
95else
96ldbl_alt128_compat_sources =
97endif
98
99if ENABLE_SYMVERS_GNU_NAMESPACE
100cxx0x_compat_sources =
101else
102cxx0x_compat_sources = \
103          compatibility-atomic-c++0x.cc \
104          compatibility-c++0x.cc \
105          compatibility-chrono.cc \
106          compatibility-condvar.cc \
107          compatibility-thread-c++0x.cc
108endif
109
110parallel_compat_sources = \
111          compatibility-parallel_list.cc  compatibility-parallel_list-2.cc
112
113
114cxx98_sources = \
115          compatibility.cc \
116          compatibility-debug_list.cc \
117          compatibility-debug_list-2.cc \
118          ${ldbl_compat_sources}
119
120cxx11_sources = \
121          ${cxx0x_compat_sources} \
122          ${ldbl_alt128_compat_sources}
123
124libstdc___la_SOURCES = $(cxx98_sources) $(cxx11_sources)
125
126libstdc___la_LIBADD = \
127          $(GLIBCXX_LIBS) \
128          $(top_builddir)/libsupc++/libsupc++convenience.la \
129          $(top_builddir)/src/c++98/libc++98convenience.la \
130          $(top_builddir)/src/c++11/libc++11convenience.la \
131          $(top_builddir)/src/c++17/libc++17convenience.la \
132          $(top_builddir)/src/c++20/libc++20convenience.la
133
134libstdc___la_DEPENDENCIES = \
135          ${version_dep} \
136          $(top_builddir)/libsupc++/libsupc++convenience.la \
137          $(top_builddir)/src/c++98/libc++98convenience.la \
138          $(top_builddir)/src/c++11/libc++11convenience.la \
139          $(top_builddir)/src/c++17/libc++17convenience.la \
140          $(top_builddir)/src/c++20/libc++20convenience.la
141
142libstdc___la_LDFLAGS = \
143          -version-info $(libtool_VERSION) ${version_arg} -lm
144
145libstdc___la_LINK = $(CXXLINK) $(libstdc___la_LDFLAGS) $(lt_host_flags)
146
147# Use special rules for compatibility-ldbl.cc compilation, as we need to
148# pass -mlong-double-64, and not use -mabi={ieee,ibm}longdouble.
149if GLIBCXX_LDBL_COMPAT
150if GLIBCXX_LDBL_ALT128_COMPAT
151LTCXXCOMPILE64 = \
152  $(filter-out -mabi=ieeelongdouble -mabi=ibmlongdouble,$(LTCXXCOMPILE))
153CXXCOMPILE64 = \
154  $(filter-out -mabi=ieeelongdouble -mabi=ibmlongdouble,$(CXXCOMPILE))
155else
156LTCXXCOMPILE64 = $(LTCXXCOMPILE)
157CXXCOMPILE64 = $(CXXCOMPILE)
158endif
159compatibility-ldbl.lo: compatibility-ldbl.cc
160          $(LTCXXCOMPILE64) $(LONG_DOUBLE_COMPAT_FLAGS) -c $<
161compatibility-ldbl.o: compatibility-ldbl.cc
162          $(CXXCOMPILE64) $(LONG_DOUBLE_COMPAT_FLAGS) -c $<
163endif
164
165# Use special rules for compatibility-ldbl-alt128.cc compilation, as we need to
166# ensure it is compiled with the correct flag.
167if GLIBCXX_LDBL_ALT128_COMPAT
168compatibility-ldbl-alt128.lo: compatibility-ldbl-alt128.cc
169          $(LTCXXCOMPILE) $(LONG_DOUBLE_ALT128_COMPAT_FLAGS) -std=gnu++11 -c $<
170compatibility-ldbl-alt128.o: compatibility-ldbl-alt128.cc
171          $(CXXCOMPILE) $(LONG_DOUBLE_ALT128_COMPAT_FLAGS) -std=gnu++11 -c $<
172if ENABLE_DUAL_ABI
173compatibility-ldbl-alt128-cxx11.lo: compatibility-ldbl-alt128-cxx11.cc
174          $(LTCXXCOMPILE) $(LONG_DOUBLE_ALT128_COMPAT_FLAGS) -std=gnu++11 -c $<
175compatibility-ldbl-alt128-cxx11.o: compatibility-ldbl-alt128-cxx11.cc
176          $(CXXCOMPILE) $(LONG_DOUBLE_ALT128_COMPAT_FLAGS) -std=gnu++11 -c $<
177endif
178endif
179
180# Use special rules for C++11 files/objects.
181compatibility-c++0x.lo: compatibility-c++0x.cc
182          $(LTCXXCOMPILE) -std=gnu++11 -c $<
183compatibility-c++0x.o: compatibility-c++0x.cc
184          $(CXXCOMPILE) -std=gnu++11 -c $<
185
186compatibility-atomic-c++0x.lo: compatibility-atomic-c++0x.cc
187          $(LTCXXCOMPILE) -std=gnu++11 -c $<
188compatibility-atomic-c++0x.o: compatibility-atomic-c++0x.cc
189          $(CXXCOMPILE) -std=gnu++11 -c $<
190
191compatibility-thread-c++0x.lo: compatibility-thread-c++0x.cc
192          $(LTCXXCOMPILE) -std=gnu++11 -c $<
193compatibility-thread-c++0x.o: compatibility-thread-c++0x.cc
194          $(CXXCOMPILE) -std=gnu++11 -c $<
195
196compatibility-chrono.lo: compatibility-chrono.cc
197          $(LTCXXCOMPILE) -std=gnu++11 -c $<
198compatibility-chrono.o: compatibility-chrono.cc
199          $(CXXCOMPILE) -std=gnu++11 -c $<
200
201compatibility-condvar.lo: compatibility-condvar.cc
202          $(LTCXXCOMPILE) -std=gnu++11 -c $<
203compatibility-condvar.o: compatibility-condvar.cc
204          $(CXXCOMPILE) -std=gnu++11 -c $<
205
206# A note on compatibility and static libraries.
207#
208# static lib == linked against only this version, should not need compat
209# shared lib == linked against potentially all compat versions
210#
211# Thus, the shared libs have more compat symbols, which can be found
212# segregated in the sources with -D_GLIBCXX_SHARED.
213#
214# In the sub-directories of libsupc++, src/c++98, src/c++11, src/c++17,
215# src/c++20, only -prefer-pic objects are generated for the convenience
216# libraries.
217#
218# In the main src directory, make shared and static objects just for
219# the compat libraries. Shared objects are compiled with -prefer-pic
220# -D_GLIBCXX_SHARED and in the .libs sub-directory, static objects are
221# compiled with -prefer-pic (ie, -fPIC but not -D_GLIBCXX_SHARED) and
222# the main src directory.
223#
224# Why are objects destined for libstdc++.a compiled with -fPIC? First,
225# because -fPIC is not harmful to use for objects destined for static
226# libraries. In addition, using -fPIC will allow the use of static
227# libstdc++.a in the creation of other C++ shared libraries.
228
229# AM_CXXFLAGS needs to be in each sub-directory so that it can be
230# modified in a per-library or per-sub-library way.  Need to manually
231# set this option because CONFIG_CXXFLAGS has to be after
232# OPTIMIZE_CXXFLAGS on the compile line so that -O2 can be overridden
233# as the occasion calls for it.
234AM_CXXFLAGS_PRE = \
235          -std=gnu++98 \
236          $(glibcxx_compiler_pic_flag) \
237          $(XTEMPLATE_FLAGS) $(VTV_CXXFLAGS) \
238          $(WARN_CXXFLAGS) $(OPTIMIZE_CXXFLAGS) $(CONFIG_CXXFLAGS)
239
240AM_CXXFLAGS = $(filter-out -fvtable-verify=std,$(AM_CXXFLAGS_PRE))
241
242# Libtool notes
243
244# 1) In general, libtool expects an argument such as `--tag=CXX' when
245# using the C++ compiler, because that will enable the settings
246# detected when C++ support was being configured.  However, when no
247# such flag is given in the command line, libtool attempts to figure
248# it out by matching the compiler name in each configuration section
249# against a prefix of the command line.  The problem is that, if the
250# compiler name and its initial flags stored in the libtool
251# configuration file don't match those in the command line, libtool
252# can't decide which configuration to use, and it gives up.  The
253# correct solution is to add `--tag CXX' to LTCXXCOMPILE and maybe
254# CXXLINK, just after $(LIBTOOL), so that libtool doesn't have to
255# attempt to infer which configuration to use.
256#
257# The second tag argument, `--tag disable-shared` means that libtool
258# only compiles each source once, for static objects. In actuality,
259# glibcxx_lt_pic_flag and glibcxx_compiler_shared_flag are added to
260# the libtool command that is used create the object, which is
261# suitable for shared libraries.  The `--tag disable-shared` must be
262# placed after --tag CXX lest things CXX undo the affect of
263# disable-shared.
264
265# 2) Need to explicitly set LTCXXCOMPILE so that EXTRA_CXX_FLAGS is
266# last. (That way, things like -O2 passed down from the toplevel can
267# be overridden by --enable-debug and --enable-cxx-flags.)
268LTCXXCOMPILE = \
269          $(LIBTOOL) --tag CXX \
270          $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
271          --mode=compile $(CXX) $(INCLUDES) \
272          $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) $(EXTRA_CXX_FLAGS)
273
274LTLDFLAGS = $(shell $(SHELL) $(top_srcdir)/../libtool-ldflags $(LDFLAGS))
275
276# 3) We'd have a problem when building the shared libstdc++ object if
277# the rules automake generates would be used.  We cannot allow g++ to
278# be used since this would add -lstdc++ to the link line which of
279# course is problematic at this point.  So, we get the top-level
280# directory to configure libstdc++-v3 to use gcc as the C++
281# compilation driver.
282CXXLINK = \
283          $(LIBTOOL) --tag CXX \
284          $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
285          --mode=link $(CXX) \
286          $(VTV_CXXLINKFLAGS) \
287          $(OPT_LDFLAGS) $(SECTION_LDFLAGS) $(AM_CXXFLAGS) \
288          $(LTLDFLAGS) $(LTLIBICONV) \
289          -o $@
290
291# Symbol versioning for shared libraries.
292if ENABLE_SYMVERS
293libstdc++-symbols.ver:  ${glibcxx_srcdir}/$(SYMVER_FILE) \
294                    $(port_specific_symbol_files)
295          cp ${glibcxx_srcdir}/$(SYMVER_FILE) $@.tmp
296          chmod +w $@.tmp
297          if test "x$(port_specific_symbol_files)" != x; then \
298            if grep '^# Appended to version file.' \
299                 $(port_specific_symbol_files) > /dev/null 2>&1; then \
300              cat $(port_specific_symbol_files) >> $@.tmp; \
301            else \
302              sed -n '1,/DO NOT DELETE/p' $@.tmp > tmp.top; \
303              sed -n '/DO NOT DELETE/,$$p' $@.tmp > tmp.bottom; \
304              cat tmp.top $(port_specific_symbol_files) tmp.bottom > $@.tmp; \
305              rm tmp.top tmp.bottom; \
306            fi; \
307          fi
308          $(EGREP) -v '^[     ]*#(#| |$$)' $@.tmp | \
309            $(CC) -E -P -include $(CONFIG_HEADER) - > $@ || (rm -f $@ ; exit 1)
310          rm -f $@.tmp
311
312CLEANFILES = libstdc++-symbols.ver
313
314if ENABLE_SYMVERS_GNU
315version_arg = -Wl,--version-script=libstdc++-symbols.ver
316version_dep = libstdc++-symbols.ver
317endif
318if ENABLE_SYMVERS_GNU_NAMESPACE
319version_arg = -Wl,--version-script=libstdc++-symbols.ver
320version_dep = libstdc++-symbols.ver
321endif
322if ENABLE_SYMVERS_SUN
323version_arg = -Wl,-M,libstdc++-symbols.ver-sun
324version_dep = libstdc++-symbols.ver-sun
325libstdc++-symbols.ver-sun : libstdc++-symbols.ver \
326                    $(toplevel_srcdir)/contrib/make_sunver.pl \
327                    $(libstdc___la_OBJECTS) $(libstdc___la_LIBADD)
328          CXXFILT="$(CXXFILT)"; export CXXFILT; \
329          perl $(toplevel_srcdir)/contrib/make_sunver.pl \
330            libstdc++-symbols.ver \
331            $(libstdc___la_OBJECTS:%.lo=.libs/%.o) \
332           `echo ' $(libstdc___la_LIBADD) ' | \
333              sed -e 's,/\([^/.]*\)\.la,/.libs/\1.a,g' -e 's/ -l[^ ]* / /'` \
334           > $@ || (rm -f $@ ; exit 1)
335endif
336if ENABLE_SYMVERS_DARWIN
337version_arg = -Wl,-exported_symbols_list,libstdc++-symbols.explist
338version_dep = libstdc++-symbols.explist
339libstdc++-symbols.explist : libstdc++-symbols.ver \
340                    ${glibcxx_srcdir}/scripts/make_exports.pl \
341                    $(libstdc___la_OBJECTS) $(libstdc___la_LIBADD)
342          perl ${glibcxx_srcdir}/scripts/make_exports.pl \
343            libstdc++-symbols.ver \
344            $(libstdc___la_OBJECTS:%.lo=.libs/%.o) \
345           `echo $(libstdc___la_LIBADD) | \
346              sed 's,/\([^/.]*\)\.la,/.libs/\1.a,g'` \
347           > $@ || (rm -f $@ ; exit 1)
348endif
349
350CLEANFILES += $(version_dep)
351else
352version_arg =
353version_dep =
354endif
355
356
357# Control additional build primary rules.
358all-once: libstdc++convenience.la $(STAMP_DEBUG)
359install-data-once: $(STAMP_INSTALL_DEBUG)
360
361all-local: all-once
362install-data-local: install-data-once
363clean-local:
364          rm -rf libstdc++convenience.la stamp* $(CLEAN_DEBUG)
365
366# Make a non-installed convenience library, so that --disable-static
367# may work.
368libstdc++convenience.la: $(toolexeclib_LTLIBRARIES)
369          $(CXXLINK) $(libstdc___la_LIBADD) $(LIBS); \
370          if test ! -f .libs/libstdc++.a; then \
371            cp .libs/libstdc++convenience.a .libs/libstdc++.a; \
372          fi; \
373          echo `date` > stamp-libstdc++convenience;
374
375# Added rules.
376# 1 debug library
377# 2 supra-convenience library
378if GLIBCXX_BUILD_DEBUG
379STAMP_DEBUG = build-debug
380STAMP_INSTALL_DEBUG = install-debug
381CLEAN_DEBUG = debug
382else
383STAMP_DEBUG =
384STAMP_INSTALL_DEBUG =
385CLEAN_DEBUG =
386endif
387
388# Build a debug variant.
389# Take care to fix all possibly-relative paths.
390debugdir = ${glibcxx_builddir}/src/debug
391stamp-debug: Makefile $(foreach dir,$(SUBDIRS),$(dir)/Makefile)
392          if test ! -d ${debugdir} || test ! -f ${debugdir}/Makefile ; then \
393            mkdir -p ${debugdir}; \
394            for d in $(SUBDIRS); do mkdir -p  ${debugdir}/$$d; done; \
395            (cd ${debugdir}; \
396            sed -e 's/top_builddir = \.\./top_builddir = ..\/../' \
397                -e 's/top_build_prefix = \.\./top_build_prefix = ..\/../' \
398                -e 's/srcdir = \.\./srcdir = ..\/../' \
399                -e 's/VPATH = \.\./VPATH = ..\/../' \
400                -e 's/glibcxx_basedir = \.\./glibcxx_basedir = ..\/../' \
401                -e 's/MKDIR_P = \.\./MKDIR_P = ..\/../' \
402            < ../Makefile > Makefile ; \
403            for d in . $(SUBDIRS); do \
404            sed -e 's/top_builddir = \.\./top_builddir = ..\/../' \
405                -e 's/top_build_prefix = \.\./top_build_prefix = ..\/../' \
406                -e 's/srcdir = \.\./srcdir = ..\/../' \
407                -e 's/VPATH = \.\./VPATH = ..\/../' \
408                -e 's/glibcxx_basedir = \.\./glibcxx_basedir = ..\/../' \
409                -e 's/MKDIR_P = \.\./MKDIR_P = ..\/../' \
410            < ../$$d/Makefile > $$d/Makefile ; \
411            done) ; \
412          fi; \
413          echo `date` > stamp-debug;
414
415if ENABLE_BACKTRACE
416${debugdir}/$(backtrace_supported_h): $(backtrace_supported_h) stamp-debug
417          cp $< $@
418debug_backtrace_supported_h = ${debugdir}/$(backtrace_supported_h)
419else
420debug_backtrace_supported_h =
421endif
422
423build-debug: stamp-debug $(debug_backtrace_supported_h)
424            (cd ${debugdir}; \
425            mv Makefile Makefile.tmp; \
426            sed -e 's,all-local: all-once,all-local:,' \
427                -e 's,install-data-local: install-data-once,install-data-local:,' \
428                -e '/vpath/!s,src/c,src/debug/c,' \
429            < Makefile.tmp > Makefile ; \
430            rm -f Makefile.tmp ; \
431            $(MAKE) CXXFLAGS='$(DEBUG_FLAGS)' \
432            toolexeclibdir=$(glibcxx_toolexeclibdir)/debug all) ;
433
434# Install debug library.
435install-debug: build-debug
436          (cd ${debugdir} && $(MAKE) CXXFLAGS='$(DEBUG_FLAGS)' \
437          toolexeclibdir=$(glibcxx_toolexeclibdir)/debug install) ;
438