2 # Shell script to build GNU Make in the absence of any 'make' program.
4 # Copyright (C) 1993-2022 Free Software Foundation, Inc.
5 # This file is part of GNU Make.
7 # GNU Make is free software; you can redistribute it and/or modify it under
8 # the terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 3 of the License, or (at your option) any later
12 # GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 # You should have received a copy of the GNU General Public License along with
18 # this program. If not, see <https://www.gnu.org/licenses/>.
20 # Get configure-generated values
23 die () { echo "$*" 1>&2; exit 1; }
24 usage () { echo "$0 [-k]"; exit $1; }
31 # Directory to find libraries in for '-lXXX'.
32 libdir=$exec_prefix/lib
33 # Directory to search by default for included makefiles.
34 includedir=$prefix/include
36 localedir=$prefix/share/locale
38 defines="-DLOCALEDIR=\"$localedir\" -DLIBDIR=\"$libdir\" -DINCLUDEDIR=\"$includedir\""
40 # Look up a make variable value.
41 # It can handle simple recursion where variables are separate words.
42 # Print the value to stdout.
49 v=$(sed -e :a -e '/\\$/N; s/\\\n//; ta' "$file" | sed -n "s=^ *$var *\= *==p")
52 (\$[\(\{]*[\)\}]) w=${w#\$[\(\{]}; w=$(get_mk_var "$file" "${w%[\)\}]}") ;;
60 # Compile source files. Object files are put into $objs.
66 # We should try to use a Makefile variable like libgnu_a_SOURCES or
67 # something but just hardcode it.
68 file="${ofile%.$OBJEXT}.c"
70 (lib/libgnu_a-*.c) file="lib/${file#lib/libgnu_a-}" ;;
72 echo "compiling $file..."
74 mkdir -p "${of%/*}" || exit 1
75 if $CC $cflags $CPPFLAGS $CFLAGS -c -o "$of" "$top_srcdir/$file"; then
78 $keep_going || die "Compilation failed."
82 objs="${objs:+$objs }$of"
88 # Use config.status to convert a .in file. Output file is put into $out.
89 # $out will be empty if no conversion was needed.
94 var="GENERATE_$(echo $base | tr 'a-z./+' A-Z__X)"
96 # Is this file disabled?
97 grep "${var}_FALSE\"]=\"\"" config.status >/dev/null && return 0
99 # If there's no .in file then no conversion needed
100 in="$top_srcdir/lib/$(echo ${base%.*}.in.${base##*.} | tr / _)"
101 test -f "$in" || return 0
103 # Not disabled, so create it
107 # First perform the normal replacements, using config.status
108 sed -e 's|@GUARD_PREFIX@|GL|g' \
109 -e 's/@GNULIB_UNISTD_H_GETOPT@/0/g' \
111 ./config.status --file "${out}__:${out}_"
114 # Then see if there any files we need to include. Unfortunately there's no
115 # algorithmic conversion so we just have to hard-code it.
116 incls=$(sed -n 's/.*definitions* of \(_[^ $]*\).*/\1/p' "$in")
118 for inc in $incls; do
120 (_GL_FUNCDECL_RPL) fn=$(get_mk_var lib/Makefile CXXDEFS_H) ;;
121 (_GL_ARG_NONNULL) fn=$(get_mk_var lib/Makefile ARG_NONNULL_H) ;;
122 (_GL_WARN_ON_USE) fn=$(get_mk_var lib/Makefile WARN_ON_USE_H) ;;
123 (_Noreturn) fn=$(get_mk_var lib/Makefile _NORETURN_H) ;;
124 (*) echo "Unknown file replacement: $inc"; exit 1 ;;
127 fn="$top_srcdir/lib/${fn##*/}"
128 test -f "$fn" || { echo "Missing file: $fn"; exit 1; }
130 sed "/definitions* of $inc/r $fn" "$int" > "${int}_"
138 # Get source files provided from gnulib and convert to object files
140 for lo in $( (get_mk_var lib/Makefile libgnu_a_OBJECTS; get_mk_var lib/Makefile libgnu_a_LIBADD) | sed "s=\$[\(\{]OBJEXT[\)\}]=$OBJEXT=g"); do
141 LIBOBJS="${LIBOBJS:+$LIBOBJS }lib/$lo"
144 # Get object files from the Makefile
145 OBJS=$(get_mk_var Makefile make_OBJECTS | sed "s=\$[\(\{]OBJEXT[\)\}]=$OBJEXT=g")
147 while test -n "$1"; do
149 (-k) keep_going=true; shift ;;
152 (-*) echo "Unknown option: $1"; usage 1 ;;
156 test -z "$1" || die "Unknown argument: $*"
158 # Generate gnulib header files that would normally be created by make
160 for b in $(get_mk_var lib/Makefile BUILT_SOURCES); do
165 # Build the gnulib library
166 cflags="$DEFS -I$OUTLIB -Ilib -I$top_srcdir/lib -I$OUTDIR/src -Isrc -I$top_srcdir/src"
167 compile $LIBOBJS || die "Compilation failed."
169 echo "creating libgnu.a..."
170 $AR $ARFLAGS "$OUTLIB"/libgnu.a $objs || die "Archive of libgnu failed."
172 # Compile the source files into those objects.
173 cflags="$DEFS $defines -I$OUTDIR/src -Isrc -I$top_srcdir/src -I$OUTLIB -Ilib -I$top_srcdir/lib"
174 compile $OBJS || die "Compilation failed."
176 # Link all the objects together.
177 echo "linking make..."
178 $CC $CFLAGS $LDFLAGS -L"$OUTLIB" -o "$OUTDIR/makenew$EXEEXT" $objs -lgnu $LOADLIBES || die "Link failed."
180 mv -f "$OUTDIR/makenew$EXEEXT" "$OUTDIR/make$EXEEXT" || exit 1