2 # Shell script to build GNU Make in the absence of any 'make' program.
4 # Copyright (C) 1993-2020 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 <http://www.gnu.org/licenses/>.
20 # Get configure-generated values
26 # Directory to find libraries in for '-lXXX'.
27 libdir=$exec_prefix/lib
28 # Directory to search by default for included makefiles.
29 includedir=$prefix/include
31 localedir=$prefix/share/locale
33 defines="-DLOCALEDIR=\"$localedir\" -DLIBDIR=\"$libdir\" -DINCLUDEDIR=\"$includedir\""
35 # Look up a make variable value.
36 # It can handle simple recursion where variables are separate words.
37 # Print the value to stdout.
44 v=$(sed -e :a -e '/\\$/N; s/\\\n//; ta' "$file" | sed -n "s=^ *$var *\= *==p")
47 (\$[\(\{]*[\)\}]) w=${w#\$[\(\{]}; w=$(get_mk_var "$file" "${w%[\)\}]}") ;;
55 # Compile source files. Object files are put into $objs.
60 file="${ofile%.$OBJEXT}.c"
61 echo "compiling $file..."
64 $CC $cflags $CPPFLAGS $CFLAGS -c -o "$of" "$top_srcdir/$file"
65 objs="${objs:+$objs }$of"
69 # Use config.status to convert a .in file. Output file is put into $out.
70 # $out will be empty if no conversion was needed.
75 var="GENERATE_$(echo $base | tr 'a-z./+' A-Z__X)"
77 # Is this file disabled?
78 grep "${var}_FALSE\"]=\"\"" config.status >/dev/null && return
80 # Not disabled, so create it
81 in="$top_srcdir/lib/$(echo ${base%.*}.in.${base##*.} | tr / _)"
85 # First perform the normal replacements, using config.status
86 sed -e 's|@GUARD_PREFIX@|GL|g' \
87 -e 's/@GNULIB_UNISTD_H_GETOPT@/0/g' \
89 ./config.status --file "${out}__:${out}_"
92 # Then see if there any files we need to include. Unfortunately there's no
93 # algorithmic conversion so we just have to hard-code it.
94 incls=$(sed -n 's/.*definitions* of \(_[^ $]*\).*/\1/p' "$in")
98 (_GL_FUNCDECL_RPL) fn=$(get_mk_var lib/Makefile CXXDEFS_H) ;;
99 (_GL_ARG_NONNULL) fn=$(get_mk_var lib/Makefile ARG_NONNULL_H) ;;
100 (_GL_WARN_ON_USE) fn=$(get_mk_var lib/Makefile WARN_ON_USE_H) ;;
101 (_Noreturn) fn=$(get_mk_var lib/Makefile _NORETURN_H) ;;
102 (*) echo "Unknown file replacement: $inc"; exit 1 ;;
105 fn="$top_srcdir/lib/${fn##*/}"
106 [ -f "$fn" ] || { echo "Missing file: $fn"; exit 1; }
108 sed "/definitions* of $inc/r $fn" "$int" > "${int}_"
116 # Get source files provided from gnulib and convert to object files
118 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
119 LIBOBJS="${LIBOBJS:+$LIBOBJS }lib/$lo"
122 # Get object files from the Makefile
123 OBJS=$(get_mk_var Makefile make_OBJECTS | sed "s=\$[\(\{]OBJEXT[\)\}]=$OBJEXT=g")
125 # Exit as soon as any command fails.
128 # Generate gnulib header files that would normally be created by make
129 for b in $(get_mk_var lib/Makefile BUILT_SOURCES); do
133 # Build the gnulib library
134 cflags="$DEFS -I$OUTLIB -Ilib -I$top_srcdir/lib -I$OUTDIR/src -Isrc -I$top_srcdir/src"
137 echo "creating libgnu.a..."
138 $AR $ARFLAGS "$OUTLIB"/libgnu.a $objs
140 # Compile the source files into those objects.
141 cflags="$DEFS $defines -I$OUTDIR/src -Isrc -I$top_srcdir/src -I$OUTLIB -Ilib -I$top_srcdir/lib"
144 # Link all the objects together.
145 echo "linking make..."
146 $CC $CFLAGS $LDFLAGS -L"$OUTLIB" $objs -lgnu $LOADLIBES -o "$OUTDIR/makenew$EXEEXT"
147 mv -f "$OUTDIR/makenew$EXEEXT" "$OUTDIR/make$EXEEXT"