2.3 Makefile.def and AutoGen: how make orders the build

GCC 15.2.0. To run the commands: a GCC checkout, and binutils for arm-none-eabi installed under $HOME/cross.

Cross-compiler recipes tell you to run make all-gcc first and make all-target-libgcc later. Look for either target in a checkout, and gcc/Makefile.in defines neither. The top-level Makefile.in defines both, among nearly 70,000 lines, and its first line says that a program wrote it. If you add a rule there by hand, the next regeneration deletes it without a warning.

The top-level build order is data: Makefile.def lists the modules and the edges between them. AutoGen expands that list into the top-level Makefile.in, configure deletes the modules you do not build, and make walks what is left as a graph.

This chapter assumes Chapter 1.2, for build, host and target, the Canadian cross and the uninstalled xgcc. It also uses the specs file of Chapter 1.3, the -B search lists of Chapter 1.5 and the multilib variants of Chapter 1.6. From Part II, it assumes Chapter 2.1, for the top-level directory map and for why libgcc/ is not under gcc/, and Chapter 2.2, for how --enable-languages drops modules.

Makefile.def and Makefile.tpl: the AutoGen input for Makefile.in

Makefile.def and Makefile.tpl are the two files from which AutoGen, a template processor separate from Autoconf and Automake, writes the top-level Makefile.in. Makefile.def holds records, such as the lists of modules, and Makefile.tpl holds make syntax with macros that loop over those records. The top level therefore has three files where an Automake project has two, and a change to the build order starts in one of the two inputs. The first lines of the definitions file say how they fit together:

#! /usr/bin/autogen
AutoGen definitions Makefile.tpl;

// Makefile.in is generated from Makefile.tpl by 'autogen Makefile.def'.

Listing 2.3-1: the head of the definitions file (Makefile.def:1-4).

A record in Makefile.def looks like target_modules = { module= libgcc; ... };, and the macros in Makefile.tpl are written [+ ... +]. The template also contains Scheme functions (Makefile.tpl:1940-2039), which is why the install manual lists Guile next to AutoGen. Its Prerequisites page says that both are "Necessary to regenerate the top level Makefile.in file from Makefile.tpl and Makefile.def".

The loop that writes the all-target rule shows how records become make syntax. It writes one all-target line per target module:

.PHONY: all-target
[+ FOR target_modules +][+ IF bootstrap +]
@if target-[+module+]-no-bootstrap[+ ENDIF bootstrap +]
all-target: maybe-all-target-[+module+][+ IF bootstrap +]
@endif target-[+module+]-no-bootstrap[+
  ENDIF bootstrap +][+ ENDFOR target_modules +]

Listing 2.3-2: the template loop for all-target (Makefile.tpl:903-908).

@if target-libvtv-no-bootstrap
all-target: maybe-all-target-libvtv
@endif target-libvtv-no-bootstrap
all-target: maybe-all-target-libssp
all-target: maybe-all-target-newlib
@if target-libgcc-no-bootstrap
all-target: maybe-all-target-libgcc
@endif target-libgcc-no-bootstrap

Listing 2.3-3: what the loop wrote, in the checked-in file (Makefile.in:1335-1342).

A flag in a record changes the output. libgcc and libvtv carry bootstrap=true in Makefile.def, so their lines are fenced by @if. libssp and newlib do not, so their lines are bare.

autogen Makefile.def: regenerating the top-level Makefile.in

In a normal build tree, nothing runs autogen Makefile.def, because configure disables the template rule that would regenerate the top-level Makefile.in. A hand edit of Makefile.in therefore lasts until the next person runs autogen, and an edit of Makefile.def changes nothing until then. The rule is in the template:

# Rebuilding Makefile.in, using autogen.
AUTOGEN = autogen
$(srcdir)/Makefile.in: @MAINT@ $(srcdir)/Makefile.tpl $(srcdir)/Makefile.def
	cd $(srcdir) && $(AUTOGEN) Makefile.def

Listing 2.3-4: regeneration (Makefile.tpl:2136-2139).

configure replaces @MAINT@ with # unless you give it --enable-maintainer-mode (configure.ac:4139-4147). The # turns the prerequisites into a comment, so the rule never runs. The install manual documents that option under Configuration, for "the build rules that regenerate the Autoconf and Automake output files", and does not name this rule.

A hand edit of Makefile.in does take effect, because the next rule rebuilds Makefile from it through config.status (Makefile.tpl:2141-2143). For a change that lasts, edit Makefile.def or Makefile.tpl, run autogen Makefile.def in the source directory, and commit the regenerated Makefile.in with your change.

@if gcc and @endif gcc: how configure prunes the Makefile

@if gcc and @endif gcc are not make syntax but markers for the top-level configure. For a module that stays in the build, configure deletes the marker lines and keeps the lines between them. For a module that it dropped from the build, it deletes the lines between them too, so that module has no rules at all in your Makefile.

configure deletes the markers while it writes its one output file, AC_CONFIG_FILES([Makefile]), through three sed scripts (configure.ac:4226-4234). It builds the scripts from its module lists. Before that, it removes from those lists every module that --enable-languages or the target excluded (configure.ac:2716-2744), and every module whose source directory is not in the tree (:2755-2782). For each host module that is left, it adds these commands:

  extrasub_host="$extrasub_host
/^@if $module\$/d
/^@endif $module\$/d
/^@unless $module\$/,/^@endunless $module\$/d
/^@if $module-$host_bootstrap_suffix\$/d
/^@endif $module-$host_bootstrap_suffix\$/d
/^@unless $module-$host_bootstrap_suffix\$/,/^@endunless $module-$host_bootstrap_suffix\$/d"

Listing 2.3-5: per-module commands for host modules (configure.ac:3378-3384). The build and target lists get the same commands at :3356-3362 and :3400-3406.

Those commands handle the modules that are still in the build. One final sweep then removes every fence that is left, with the lines inside it:

# Do the final fixup along with target modules.
extrasub_target="$extrasub_target
/^@if /,/^@endif /d
/^@unless /d
/^@endunless /d"

Listing 2.3-6: the final sweep (configure.ac:3409-3413).

$bootstrap_suffix is bootstrap or no-bootstrap (configure.ac:3180-3189). Bootstrap, which builds GCC with itself three times, is on by default only when build, host and target are the same (configure.ac:1532-1541). A cross build therefore keeps the -no-bootstrap blocks and drops the per-stage rules, which Chapter 2.5 covers.

The top-level configure does not configure the subdirectories. Each one is configured by a configure-<module> rule, when make first needs it. The comment in configure.ac says that configure removes their Makefiles "so that the top-level Makefile reconfigures them, like we used to do when configure itself was recursive" (configure.ac:3317-3321).

build_modules, host_modules, target_modules: directory, CC and --host

build_modules, host_modules and target_modules are the three lists in Makefile.def, and every module is in one or more of them. The list that a module is in decides how the top level builds and configures it, which is why a target library is configured with the target as its host. In the abridged records below, libiberty and libcpp appear twice, as build modules and as host modules:

build_modules= { module= libiberty; };
...
build_modules= { module= libcpp;
                 extra_configure_flags='--disable-nls am_cv_func_iconv=no';};
...
host_modules= { module= gcc; bootstrap=true; 
		extra_make_flags="$(EXTRA_GCC_FLAGS)";
		extra_configure_flags='@gcc_host_pie@'; };
...
host_modules= { module= libcpp; bootstrap=true; };
...
host_modules= { module= libiberty; bootstrap=true;
	        extra_configure_flags='@extra_host_libiberty_configure_flags@';};
...
target_modules = { module= libstdc++-v3;
		   bootstrap=true;
		   lib_path=src/.libs;
		   raw_cxx=true; };
...
target_modules = { module= newlib; };
target_modules = { module= libgcc; bootstrap=true; no_check=true;
		  missing=TAGS;
		  missing=install-dvi; };

Listing 2.3-7: the three lists, abridged (Makefile.def:27-185). The build list is :27-34, the host list :36-167 and the target list :169-212.

The list decides three things: the directory in the build tree, the compiler in CC, and the --host that the module's own configure receives.

ListDirectory in the build treeCC in its environmentIts configure gets
build_modulesbuild-<build>/CC_FOR_BUILD--host=<build>
host_modulesthe top of the build treeCC--host=<host>
target_modules<target>/CC_FOR_TARGET--host=<target>

The directories come from GCC_TOPLEV_SUBDIRS (config/acx.m4:84-101). The host directory becomes host-<host>/ in a few cases, for example when you configure inside the source directory. The compilers come from BUILD_EXPORTS, HOST_EXPORTS and BASE_TARGET_EXPORTS, and the --host values from the template arguments (Makefile.tpl:154-158, :199-201 and :304-308 for the compilers, :1343-1344, :1359 and :1491 for --host).

To its own configure, a target library runs on the target, so the target is its host. The generated rule for libgcc shows that --host, and it shows the other step that every target module takes before it configures:

configure-target-libgcc: 
	@r=`${PWD_COMMAND}`; export r; \
	...
	$(CC_FOR_TARGET) --print-multi-lib > $(TARGET_SUBDIR)/libgcc/multilib.tmp 2> /dev/null; \
	...
	$(NORMAL_TARGET_EXPORTS)  \
	echo Configuring in $(TARGET_SUBDIR)/libgcc; \
	...
	  $(TARGET_CONFIGARGS) --build=${build_alias} --host=${target_alias} \
	  --target=${target_alias}  \
	  || exit 1

Listing 2.3-8: configure-target-libgcc, abridged (Makefile.in:49946-49979).

The rule runs the target compiler to get the multilib list. It reconfigures the module when that list changes, so a change to the multilib variants of Chapter 1.6 reaches every target library. It also means that configure-target-libgcc cannot start until the target compiler exists.

The build copy of a module such as libcpp exists because a generator links it. build/genmatch runs on the build machine during the build, and it links the build machine's libcpp (gcc/Makefile.in:3324-3328, :3336). The host copy is linked into cc1. Chapter 2.4 covers the generators.

CC_FOR_TARGET: the xgcc that the build just made

CC_FOR_TARGET is the compiler that configures and builds every target library. When build and host are the same and the tree builds gcc, it is the xgcc that the build has made, with a -B that points into the compiler's own build directory. That choice is why no target library can be configured before the compiler is built. The value starts as one line of the top-level configure.ac:

GCC_TARGET_TOOL(cc, CC_FOR_TARGET, CC, [gcc/xgcc -B$$r/$(HOST_SUBDIR)/gcc/])

Listing 2.3-9: the in-tree default (configure.ac:4059).

The macro decides whether to use that default. Watch the first if, which compares build with host, and the case on configdirs:

if test "x${build}" != "x${host}" ; then
  if expr "x[$]$2" : "x/" > /dev/null; then
    # We already found the complete path
    ac_dir=`dirname [$]$2`
    AC_MSG_RESULT(pre-installed in $ac_dir)
  else
    # Canadian cross, just use what we found
    AC_MSG_RESULT(pre-installed)
  fi
else
  ifelse([$4],,,
  [ok=yes
  case " ${configdirs} " in
    *" patsubst([$4], [/.*], []) "*) ;;
    *) ok=no ;;
  esac
  ...
  if test $ok = yes; then
    # An in-tree tool is available and we can use it
    $2='$$r/$(HOST_SUBDIR)/$4'
    AC_MSG_RESULT(just compiled)

Listing 2.3-10: GCC_TARGET_TOOL, abridged (config/acx.m4:553-577).

Read it with the three flavours of Chapter 1.2 in mind. A Canadian cross takes the first branch, and a native or a cross build takes the second:

  1. On a Canadian cross, build and host differ. The new xgcc runs on the host, so the build machine cannot run it. The macro keeps the target compiler that configure found installed (configure.ac:4031).
  2. Otherwise, patsubst cuts the default at its first / to get gcc. If gcc is in configdirs, the value becomes $$r/$(HOST_SUBDIR)/gcc/xgcc -B$$r/$(HOST_SUBDIR)/gcc/, and configure prints "just compiled" for it.

$$r is the top of the build tree: each module recipe starts with r=`${PWD_COMMAND}` (Listing 2.3-8). The top-level Makefile adds $(STAGE_CC_WRAPPER) in front (Makefile.tpl:591). The value then reaches each target module twice: as CC in the environment of its configure (Makefile.tpl:308) and as CC= on its make command line (Makefile.tpl:787).

The compiler's own directory, gcc/, gets a different variable. EXTRA_GCC_FLAGS passes GCC_FOR_TARGET to its make (Makefile.tpl:826-827), and gcc/Makefile.in uses it to run the new xgcc, for example to dump specs. The comment above EXTRA_GCC_FLAGS says "gcc builds a library, libgcc.a" (Makefile.tpl:820-822). The comment is out of date: in GCC 15.2.0, libgcc is a target module (Listing 2.3-7), and the quickstrap target in gcc/Makefile.in hands over to the top-level all-target-libgcc (gcc/Makefile.in:2212-2215).

-B into gcc/: why libgcc copies its files back

The -B in CC_FOR_TARGET makes the new xgcc look for its own files in gcc/, the compiler's directory in the build tree. The target libraries need files from libgcc as well, and libgcc builds in a directory of its own, so it copies its results back into gcc/. The libgcc edges that lang_env_dependencies gives the target libraries wait for that copy.

The GCC manual documents -B under Directory Options, as the option that says "where to find the executables, libraries, include files, and data files of the compiler itself". Chapter 1.5 showed that -B feeds the program, startfile and header search lists at once, so -B$$r/gcc/ makes xgcc find its own cc1 and headers in the build directory. gcc/Makefile.in also writes a specs file there, "to make -B./ read these specs over installed ones" (gcc/Makefile.in:2441-2444).

The files that the target libraries need from libgcc include libgcc.a and crtbegin.o, and libgcc builds them in <target>/libgcc/, not in gcc/. Its all target copies them back:

all: all-multi
	# Now that we have built all the objects, we need to copy
	# them back to the GCC directory.  Too many things (other
	# in-tree libraries, and DejaGNU) know about the layout
	# of the build tree, for now.
	$(MAKE) install-leaf DESTDIR=$(gcc_objdir) \
	  slibdir= libsubdir= MULTIOSDIR=$(MULTIDIR)

Listing 2.3-11: libgcc installs into the compiler's build directory (libgcc/Makefile.in:116-122). gcc_objdir is ../../gcc from the library's directory (:25).

After that step, every later xgcc -B$$r/gcc/ link finds libgcc without an installed toolchain.

dependencies in Makefile.def: hard edges and soft maybe- edges

Each dependencies record in Makefile.def is one edge between two make targets, and a record marked hard=true is a hard edge. A hard edge stops the build when the module it names is missing, and a soft edge lets the build do without it. Soft edges are what let one top level build both a combined tree, with binutils beside GCC, and a GCC checkout alone. The records start at the comment // Inter-module dependencies (Makefile.def:354), and the compiler's own edges look like this:

dependencies = { module=all-gcc; on=all-libiberty; hard=true; };
...
dependencies = { module=all-gcc; on=all-build-libcpp; };
dependencies = { module=all-gcc; on=all-zlib; };
dependencies = { module=all-gcc; on=all-libbacktrace; hard=true; };
dependencies = { module=all-gcc; on=all-libcpp; hard=true; };
dependencies = { module=all-gcc; on=all-libcody; hard=true; };
dependencies = { module=all-gcc; on=all-libdecnumber; hard=true; };

Listing 2.3-12: edges into all-gcc, abridged (Makefile.def:378-394). The edges into configure-gcc are at :367-377.

The template's comment defines the two kinds:

# There are two types of dependencies here: 'hard' dependencies, where one
# module simply won't build without the other; and 'soft' dependencies, where
# if the depended-on module is missing, the depending module will do without
# or find a substitute somewhere (perhaps installed).  Soft dependencies
# are made here to depend on a 'maybe-' target.  If you're not sure,
# it's safer to use a soft dependency.

Listing 2.3-13: hard and soft (Makefile.tpl:1933-1938).

The generated file has all-gcc: all-libcpp for the hard edge (Makefile.in:68206) and all-gcc: maybe-all-zlib for a soft one (:68186). A maybe- target is how a soft edge survives a missing module:

.PHONY: all-gcc maybe-all-gcc
maybe-all-gcc:
@if gcc-bootstrap
all-gcc: stage_current
@endif gcc-bootstrap
@if gcc
TARGET-gcc=all
maybe-all-gcc: all-gcc
all-gcc: configure-gcc

Listing 2.3-14: maybe-all-gcc (Makefile.in:12432-12440), expanded from the template at Makefile.tpl:1265-1275.

maybe-all-gcc always exists, with no recipe. Only inside @if gcc does it gain a prerequisite on all-gcc. When configure prunes a module, its maybe- target stays as an empty target, and a soft edge to it does nothing. A hard edge names all-libcpp itself, so if libcpp is pruned, make has no rule for it and stops.

A combined tree shows a soft edge at work. configure-gcc waits for all-gas and all-ld (Makefile.def:374-375), and gcc's configure uses ../gas/as-new when it finds a configured gas beside it (gcc/configure.ac:2697-2700). With binutils sources in the tree, the compiler is configured against the assembler it will drive. Without them, the edge is empty and configure looks for an installed assembler.

lang_env_dependencies: what every target library waits for

Target libraries get most of their edges from defaults in the template, and lang_env_dependencies records adjust those defaults for one module at a time. By default, a target library waits for the compiler, for libgcc, and for the C library when it is in the tree. A record can exempt a module from the libgcc edge or the C-library edge, or add an edge to libstdc++-v3. Together they fix the order in which the target libraries are configured. The comment above the records states the defaults:

// Target modules.  These can also have dependencies on the language
// environment (e.g. on libstdc++).  By default target modules depend
// on libgcc and newlib/libgloss.
lang_env_dependencies = { module=libitm; cxx=true; };
lang_env_dependencies = { module=libffi; cxx=true; };
lang_env_dependencies = { module=newlib; no_c=true; };
lang_env_dependencies = { module=libgloss; no_c=true; };
lang_env_dependencies = { module=libgcc; no_gcc=true; no_c=true; };
// libiberty does not depend on newlib or libgloss because it must be
// built newlib on some targets (e.g. Cygwin).  It still needs
// a dependency on libgcc for native targets to configure.
lang_env_dependencies = { module=libiberty; no_c=true; };
lang_env_dependencies = { module=libgcobol; cxx=true; };

Listing 2.3-15: lang_env_dependencies (Makefile.def:647-659).

In that comment, newlib is a C library, and libgloss is its companion library of startup code and input/output support, with pieces for each board or debug monitor (Chapter 3.4). The template turns the flags into edges, here for a build that does not bootstrap:

@if gcc-no-bootstrap[+ FOR target_modules +][+ IF (not (lang-dep "no_gcc")) +]
configure-target-[+module+]: maybe-all-target-libgcc[+
  ENDIF +][+ ENDFOR target_modules +]
@endif gcc-no-bootstrap

[+ FOR target_modules +][+ IF (not (lang-dep "no_c")) +]
configure-target-[+module+]: maybe-all-target-newlib maybe-all-target-libgloss[+
  ENDIF +][+ IF (lang-dep "cxx") +]
configure-target-[+module+]: maybe-all-target-libstdc++-v3[+
  ENDIF +]
[+ ENDFOR target_modules +]

Listing 2.3-16: the default edges between target modules (Makefile.tpl:2108-2118).

Another loop, before the explicit edges in the template, gives every target module an edge to the compiler: configure-target-<module>: maybe-all-gcc (Makefile.tpl:1927-1930). Together, the loops give these rules:

  • Every target library waits for the compiler. No flag removes that edge.
  • Every target library except libgcc waits for libgcc. no_gcc is set only on libgcc.
  • Every target library except libgcc, newlib and libgloss waits for the C library, if the C library is in the tree.
  • libitm, libffi and libgcobol also wait for libstdc++-v3.

newlib has no_c but not no_gcc, so it waits for libgcc. The generated file has configure-target-newlib: maybe-all-target-libgcc (Makefile.in:69375), so in a tree with newlib in it, libgcc is built before newlib. Chapter 3.2 explains how libgcc builds before a C library exists, and Chapter 3.6 covers what the top level hands to both of them.

The edges land on configure-target-*, not on all-target-*, because a target library's configure runs CC_FOR_TARGET (Listing 2.3-8). The compiler and its runtime must exist before that step, not only before compilation. The other edges between target modules are explicit records, for example configure-target-libstdc++-v3 on configure-target-libgomp (Makefile.def:675).

The libiberty record in Listing 2.3-15 does nothing, because libiberty is not in target_modules. configure.ac says "Note that libiberty is not a target library" (configure.ac:146-148).

all-host and all-target: the module graph of a cross build

all-host and all-target have no order between them, so the edges between modules decide the whole order of a cross build. make with no target runs all, and for a build that does not bootstrap, all asks for those two targets (Makefile.tpl:876-877). The install manual's Building a cross compiler section gives the resulting order in four steps: host tools, binutils if they are in the tree, the compiler, and then the run-time libraries.

In the graph, arrows point from what is built first to what waits for it. Watch <target>/libgcc, which sits between the compiler and the C library:

build-<build>/libiberty --> build-<build>/libcpp ------------+  soft
libiberty --> libcpp ----------------------------------------+  hard
libdecnumber, libbacktrace, libcody -------------------------+  hard
fixincludes, lto-plugin, zlib -------------------------------+  soft
gmp, mpfr, mpc, isl, gas, ld (only if in the tree) ----------+  soft
                                                             |
                                                             v
                                                gcc  (xgcc, cc1, ...)
                                                             |
                                                             v
                                                   <target>/libgcc
                                                             |
                                                             v
                              <target>/newlib --> <target>/libgloss
                                       (only if in the tree) |
                                                             v
                     <target>/libstdc++-v3, <target>/libgomp, ...

The host libraries come before the compiler that links them. Under make -j, modules with no path between them can build at the same time.

Checking the build order: make all-gcc against make

The edges are in your build tree as soon as configure has run, so grep on the generated Makefile checks the build order before anything is built. The commands below configure an arm-none-eabi cross compiler, read two sets of edges, and then build in the order that cross recipes use: make all-gcc, make all-target-libgcc, then plain make.

Untested recipe. The results described below come from the source that the citations show. The commands were not run.

The commands assume a cross binutils for the target, with its as, ld, ar and ranlib in $HOME/cross/arm-none-eabi/bin. The install manual's Building a cross compiler section names that directory, <prefix>/<target>/bin, for binutils that are not in the GCC source tree.

$ mkdir build && cd build
$ ../gcc/configure --target=arm-none-eabi --prefix=$HOME/cross \
      --enable-languages=c,c++
$ grep -c '^@if ' Makefile                          # 0: Listing 2.3-6
$ grep -E '^(all-gcc|configure-target-libgcc):' Makefile
$ make -j8 all-gcc
$ make -j8 all-target-libgcc
$ make -j8

The grep -c line prints 0, because the final sweep of Listing 2.3-6 removes every @if line. The grep -E line prints the edges into all-gcc, with all-libcpp among the hard ones. For configure-target-libgcc it prints the rule, which has no prerequisites of its own, and one edge, to maybe-all-gcc. That edge comes from the gcc-no-bootstrap loop (Makefile.tpl:1927-1930), which survives because a cross build does not bootstrap.

make -n does not show the order, so read the edges with grep instead. GNU make runs a recipe line that mentions $(MAKE) even under -n, and each module rule does its cd and its $(MAKE) in one line (Makefile.in:12441-12446). The configure-<module> recipe before it is only printed. In a tree that is not built yet, make -n therefore stops at the first cd into a directory that no configure created.

make all-gcc configures and builds the build modules and host modules that all-gcc depends on, then gcc itself. It configures no target module, because no edge in Listing 2.3-12 or in the records of Makefile.def:366-413 names one. The host modules that do wait for target libraries are gnattools and gotools (Makefile.def:417-418, :430), and all-gcc does not depend on them.

make all-target-libgcc follows Listing 2.3-8. It runs all-gcc again through maybe-all-gcc, then runs xgcc --print-multi-lib, configures arm-none-eabi/libgcc with --host=arm-none-eabi, builds it, and copies it back into gcc/ (Listing 2.3-11).

Plain make then reaches every remaining target module, libstdc++-v3 among them, and what those modules need from a C library is Part III's subject. The split between the first two commands and the third is what Part III's stage 1 compilers rest on. A stage 1 compiler is the first GCC build of a cross recipe. It starts with make all-gcc, before any C library exists, and it is not the stage1 of a native bootstrap. Chapter 3.1 explains why a cross toolchain needs the split.

gcc/Makefile.in is written by hand, not by Automake

gcc/Makefile.in is written by hand, like the Makefile.in of several library directories, while others, such as libstdc++-v3, generate theirs with Automake. With AutoGen at the top level, a GCC tree therefore has three ways to make a Makefile.in. The way a directory uses decides what you edit to change its build.

The gcc/ directory has no Makefile.am (the gcc/ tree), and its Makefile.in starts like a file that a person wrote:

# Makefile for GNU Compiler Collection
# Run 'configure' to generate Makefile from Makefile.in

Listing 2.3-17: the head of gcc/Makefile.in (gcc/Makefile.in:1-2).

A runtime library that uses Automake starts with a line that names its source:

# Makefile.in generated by automake 1.15.1 from Makefile.am.

Listing 2.3-18: the head of libstdc++-v3/Makefile.in (libstdc++-v3/Makefile.in:1).

The table sorts the directories by the way they get their Makefile.in:

WhereHow its Makefile.in is made
top levelAutoGen, from Makefile.def and Makefile.tpl
gcc/, libgcc/, libcpp/, libiberty/, libdecnumber/, libobjc/, libcody/by hand
libstdc++-v3/, libgomp/, libbacktrace/, libquadmath/, lto-plugin/, zlib/Automake 1.15.1, from Makefile.am

The hand-written rows are the directories with no Makefile.am in GCC 15.2.0, and the Automake rows each start with the line in Listing 2.3-18. In all three cases, the directory's own configure turns Makefile.in into Makefile, and only the way Makefile.in itself is made differs.

If you change a hand-written Makefile.in, you edit it. If you change an Automake one, you edit Makefile.am and run automake. The install manual's Prerequisites page gives these two rules, with a list of the hand-written directories that is out of date in GCC 15.2.0. If you change the top level, you edit Makefile.def or Makefile.tpl and run autogen.

Three things to carry away

The top-level build order is in Makefile.def, not in a Makefile. AutoGen expands it into Makefile.in, and a hand edit of that file lasts only until the next autogen run.

configure deletes the modules you do not build, and make configures the rest. The @if module fences go, a soft maybe- edge to a missing module becomes empty, and each subdirectory is configured by a configure-<module> rule.

Every target library waits for xgcc, and all but libgcc wait for libgcc. CC_FOR_TARGET is xgcc -B$$r/gcc/, and libgcc copies itself into gcc/ so that the later libraries can link.

Things that surprise people

A target library's configure gets --host=<target>. The command line is at the top of <target>/libgcc/config.log (libgcc/configure:1806-1813).

make all-gcc gives you a compiler without libgcc. Nothing in its graph names a target module. Add make all-target-libgcc when you need it.

Editing Makefile.def in a build tree changes nothing. The regeneration rule is commented out unless you configured with --enable-maintainer-mode.

newlib waits for libgcc, not the other way round. Only libgcc, newlib and libgloss are exempt from the C-library edge, and only libgcc is exempt from the libgcc edge.

Documentation coverage

The install manual's Prerequisites page says that AutoGen and Guile are "Necessary to regenerate the top level Makefile.in file from Makefile.tpl and Makefile.def" (gcc/doc/install.texi:584-593). The same page says which directories do not use Automake (install.texi:549-557). The Building a cross compiler section lists the order that make follows, in four steps (install.texi:3247-3277). The internals manual's Makefile Targets node (gcc/doc/makefile.texi:81-84) says that the top level is "a complex Makefile that coordinates the various steps of the build".

What is not documented:

  • What Makefile.def contains, and that it holds the build order. The manuals name the file only as AutoGen input, and in one line for front-end check targets (gcc/doc/sourcebuild.texi:562-564).
  • The @if/@endif fences and the sed pass in configure that removes them.
  • hard and soft edges, and the maybe- targets. Only the comment in Listing 2.3-13 explains them.
  • The default edges between target modules (lang_env_dependencies), and that newlib waits for libgcc.
  • That CC_FOR_TARGET is xgcc -B into the build tree, and that libgcc copies its results into gcc/ for the later libraries.
  • make all-gcc and make all-target-libgcc. No manual in the gcc/doc/ of GCC 15.2.0 names either target.
  • That --enable-maintainer-mode also turns on the AutoGen rule. The option's entry names only Autoconf, Automake and gcc.pot (install.texi:1932-1939).

Two documented statements are out of date in GCC 15.2.0:

  • The Automake list in install.texi:554-557 names intl. That directory is in releases/gcc-13.1.0 and absent from releases/gcc-14.1.0. The list also omits libgcc, libdecnumber and libcody, which have hand-written Makefile.in files too.
  • The internals manual's Top Level node says that the top-level build system "is documented in a separate manual, included with GNU Binutils" (gcc/doc/sourcebuild.texi:157-160), and names no manual.

Next: Chapter 2.4, Generated sources in build/gcc/: options.cc, tm.h and insn-*, the files that make writes into gcc/ and that no checkout contains, from insn-recog.cc to options.h, and the generator that writes each.