]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - Makefile
build-many-glibcs.py: Add openrisc hard float glibc variant
[thirdparty/glibc.git] / Makefile
index ac1125853bf692c4b631f97ba2b38bf2bde02067..adf47491240b85ef2193823072b6ce5e500ccc5f 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-# Copyright (C) 1991-2019 Free Software Foundation, Inc.
+# Copyright (C) 1991-2024 Free Software Foundation, Inc.
 # This file is part of the GNU C Library.
 
 # The GNU C Library is free software; you can redistribute it and/or
@@ -13,7 +13,7 @@
 
 # You should have received a copy of the GNU Lesser General Public
 # License along with the GNU C Library; if not, see
-# <http://www.gnu.org/licenses/>.
+# <https://www.gnu.org/licenses/>.
 
 #
 #      Master Makefile for the GNU C library
@@ -26,8 +26,17 @@ include Makeconfig
 
 
 # This is the default target; it makes everything except the tests.
-.PHONY: all
-all: lib others
+.PHONY: all help minihelp
+all: minihelp lib others
+
+help:
+       @sed '0,/^help-starts-here$$/d' Makefile.help
+
+minihelp:
+       @echo
+       @echo type \"make help\" for help with common glibc makefile targets
+       @echo
+
 \f
 ifneq ($(AUTOCONF),no)
 
@@ -59,7 +68,7 @@ endif # $(AUTOCONF) = no
                   subdir_objs subdir_stubs subdir_testclean            \
                   $(addprefix install-, no-libc.a bin lib data headers others)
 \f
-headers := limits.h values.h features.h gnu-versions.h \
+headers := limits.h values.h features.h features-time64.h gnu-versions.h \
           bits/xopen_lim.h gnu/libc-version.h stdc-predef.h \
           bits/libc-header-start.h
 
@@ -100,12 +109,6 @@ elf/ldso_install:
 # Ignore the error if we cannot update /etc/ld.so.cache.
 ifeq (no,$(cross-compiling))
 ifeq (yes,$(build-shared))
-install: install-symbolic-link
-.PHONY: install-symbolic-link
-install-symbolic-link: subdir_install
-       $(symbolic-link-prog) $(symbolic-link-list)
-       rm -f $(symbolic-link-list)
-
 install:
        -test ! -x $(elf-objpfx)ldconfig || LC_ALL=C \
          $(elf-objpfx)ldconfig $(addprefix -r ,$(install_root)) \
@@ -135,8 +138,15 @@ builddir=`dirname "$$0"`
 GCONV_PATH="$${builddir}/iconvdata"
 
 usage () {
-  echo "usage: $$0 [--tool=strace] PROGRAM [ARGUMENTS...]" 2>&1
-  echo "       $$0 --tool=valgrind PROGRAM [ARGUMENTS...]" 2>&1
+cat << EOF
+Usage: $$0 [OPTIONS] <program> [ARGUMENTS...]
+
+  --tool=TOOL  Run with the specified TOOL. It can be strace, rpctrace,
+               valgrind or container. The container will run within
+               support/test-container.  For strace and valgrind,
+               additional arguments can be passed after the tool name.
+EOF
+
   exit 1
 }
 
@@ -165,12 +175,21 @@ case "$$toolname" in
     exec $(subst $(common-objdir),"$${builddir}", $(test-program-prefix)) \
       $${1+"$$@"}
     ;;
-  strace)
-    exec strace $(patsubst %, -E%, $(run-program-env)) \
+  strace*)
+    exec $$toolname $(patsubst %, -E%, $(run-program-env)) \
+      $(test-via-rtld-prefix) $${1+"$$@"}
+    ;;
+  rpctrace)
+    exec rpctrace $(patsubst %, -E%, $(run-program-env)) \
       $(test-via-rtld-prefix) $${1+"$$@"}
     ;;
-  valgrind)
-    exec env $(run-program-env) valgrind $(test-via-rtld-prefix) $${1+"$$@"}
+  valgrind*)
+    exec env $(run-program-env) $$toolname $(test-via-rtld-prefix) $${1+"$$@"}
+    ;;
+  container)
+    exec env $(run-program-env) $(test-via-rtld-prefix) \
+      $(common-objdir)/support/test-container \
+      env $(run-program-env) $(test-via-rtld-prefix) $${1+"$$@"}
     ;;
   *)
     usage
@@ -187,7 +206,213 @@ $(common-objpfx)testrun.sh: $(common-objpfx)config.make \
        mv -f $@T $@
 postclean-generated += testrun.sh
 
-others: $(common-objpfx)testrun.sh
+define debugglibc
+#!/bin/bash
+
+SOURCE_DIR="$(CURDIR)"
+BUILD_DIR="$(common-objpfx)"
+CMD_FILE="$(common-objpfx)debugglibc.gdb"
+CONTAINER=false
+DIRECT=true
+STATIC=false
+SYMBOLSFILE=true
+unset TESTCASE
+unset BREAKPOINTS
+unset ENVVARS
+
+usage()
+{
+cat << EOF
+Usage: $$0 [OPTIONS] <program>
+
+   Or: $$0 [OPTIONS] -- <program> [<args>]...
+
+  where <program> is the path to the program being tested,
+  and <args> are the arguments to be passed to it.
+
+Options:
+
+  -h, --help
+       Prints this message and leaves.
+
+  The following options require one argument:
+
+  -b, --breakpoint
+       Breakpoints to set at the beginning of the execution
+       (each breakpoint demands its own -b option, e.g. -b foo -b bar)
+  -e, --environment-variable
+       Environment variables to be set with 'exec-wrapper env' in GDB
+       (each environment variable demands its own -e option, e.g.
+       -e FOO=foo -e BAR=bar)
+
+  The following options do not take arguments:
+
+  -c, --in-container
+       Run the test case inside a container and automatically attach
+       GDB to it.
+  -i, --no-direct
+       Selects whether to pass the --direct flag to the program.
+       --direct is useful when debugging glibc test cases. It inhibits the
+       tests from forking and executing in a subprocess.
+       Default behaviour is to pass the --direct flag, except when the
+       program is run with user specified arguments using the "--" separator.
+  -s, --no-symbols-file
+       Do not tell GDB to load debug symbols from the program.
+EOF
+}
+
+# Parse input options
+while [[ $$# > 0 ]]
+do
+  key="$$1"
+  case $$key in
+    -h|--help)
+      usage
+      exit 0
+      ;;
+    -b|--breakpoint)
+      BREAKPOINTS="break $$2\n$$BREAKPOINTS"
+      shift
+      ;;
+    -e|--environment-variable)
+      ENVVARS="$$2 $$ENVVARS"
+      shift
+      ;;
+    -c|--in-container)
+      CONTAINER=true
+      ;;
+    -i|--no-direct)
+      DIRECT=false
+      ;;
+    -s|--no-symbols-file)
+      SYMBOLSFILE=false
+      ;;
+    --)
+      shift
+      TESTCASE=$$1
+      COMMANDLINE="$$@"
+      # Don't add --direct when user specifies program arguments
+      DIRECT=false
+      break
+      ;;
+    *)
+      TESTCASE=$$1
+      COMMANDLINE=$$TESTCASE
+      ;;
+  esac
+  shift
+done
+
+# Check for required argument and if the testcase exists
+if [ ! -v TESTCASE ] || [ ! -f $${TESTCASE} ]
+then
+  usage
+  exit 1
+fi
+
+# Container tests needing locale data should install them in-container.
+# Other tests/binaries need to use locale data from the build tree.
+if [ "$$CONTAINER" = false ]
+then
+  ENVVARS="GCONV_PATH=$${BUILD_DIR}/iconvdata $$ENVVARS"
+  ENVVARS="LOCPATH=$${BUILD_DIR}/localedata $$ENVVARS"
+  ENVVARS="LC_ALL=C $$ENVVARS"
+fi
+
+# Expand environment setup command
+if [ -v ENVVARS ]
+then
+  ENVVARSCMD="set exec-wrapper env $$ENVVARS"
+fi
+
+# Expand direct argument
+if [ "$$DIRECT" == true ]
+then
+  DIRECT="--direct"
+else
+  DIRECT=""
+fi
+
+# Check if the test case is static
+if file $${TESTCASE} | grep "statically linked" >/dev/null
+then
+  STATIC=true
+else
+  STATIC=false
+fi
+
+# Expand symbols loading command
+if [ "$$SYMBOLSFILE" == true ]
+then
+  SYMBOLSFILE="add-symbol-file $${TESTCASE}"
+else
+  SYMBOLSFILE=""
+fi
+
+# GDB commands template
+template ()
+{
+cat <<EOF
+set environment C -E -x c-header
+set auto-load safe-path $${BUILD_DIR}/nptl_db:\$$debugdir:\$$datadir/auto-load
+set libthread-db-search-path $${BUILD_DIR}/nptl_db
+__ENVVARS__
+__SYMBOLSFILE__
+break _dl_start_user
+run --library-path $(rpath-link):$${BUILD_DIR}/nptl_db \
+__COMMANDLINE__ __DIRECT__
+__BREAKPOINTS__
+EOF
+}
+
+# Generate the commands file for gdb initialization
+template | sed \
+  -e "s|__ENVVARS__|$$ENVVARSCMD|" \
+  -e "s|__SYMBOLSFILE__|$$SYMBOLSFILE|" \
+  -e "s|__COMMANDLINE__|$$COMMANDLINE|" \
+  -e "s|__DIRECT__|$$DIRECT|" \
+  -e "s|__BREAKPOINTS__|$$BREAKPOINTS|" \
+  > $$CMD_FILE
+
+echo
+echo "Debugging glibc..."
+echo "Build directory  : $$BUILD_DIR"
+echo "Source directory : $$SOURCE_DIR"
+echo "GLIBC Testcase   : $$TESTCASE"
+echo "GDB Commands     : $$CMD_FILE"
+echo "Env vars         : $$ENVVARS"
+echo
+
+if [ "$$CONTAINER" == true ]
+then
+# Use testrun.sh to start the test case with WAIT_FOR_DEBUGGER=1, then
+# automatically attach GDB to it.
+WAIT_FOR_DEBUGGER=1 $(common-objpfx)testrun.sh --tool=container $${TESTCASE} &
+gdb -x $${TESTCASE}.gdb
+elif [ "$$STATIC" == true ]
+then
+gdb $${TESTCASE}
+else
+# Start the test case debugging in two steps:
+#   1. the following command invokes gdb to run the loader;
+#   2. the commands file tells the loader to run the test case.
+gdb -q \
+  -x $${CMD_FILE} \
+  -d $${SOURCE_DIR} \
+  $${BUILD_DIR}/elf/ld.so
+fi
+endef
+
+# This is another handy script for debugging dynamically linked program
+# against the current libc build for testing.
+$(common-objpfx)debugglibc.sh: $(common-objpfx)config.make \
+                           $(..)Makeconfig $(..)Makefile
+       $(file >$@T,$(debugglibc))
+       chmod a+x $@T
+       mv -f $@T $@
+postclean-generated += debugglibc.sh debugglibc.gdb
+
+others: $(common-objpfx)testrun.sh $(common-objpfx)debugglibc.sh
 \f
 # Makerules creates a file `stubs' in each subdirectory, which
 # contains `#define __stub_FUNCTION' for each function defined in that
@@ -293,7 +518,10 @@ mostlyclean: parent-mostlyclean
        @$(MAKE) subdir_mostlyclean no_deps=t
        -rm -f $(postclean)
 
-tests-clean:
+# Remove test artifacts from the whole glibc build.
+# do-tests-clean removes test artifacts from top-level directory, and
+# subdir_testclean removes them from individual sub-directories.
+tests-clean: do-tests-clean
        @$(MAKE) subdir_testclean no_deps=t
 
 ifneq (,$(CXX))
@@ -317,7 +545,7 @@ tests-special += $(objpfx)check-installed-headers-c.out
 libof-check-installed-headers-c := testsuite
 $(objpfx)check-installed-headers-c.out: \
     scripts/check-installed-headers.sh $(headers)
-       $(SHELL) $(..)scripts/check-installed-headers.sh c \
+       $(SHELL) $(..)scripts/check-installed-headers.sh c $(supported-fortify) \
          "$(CC) $(filter-out -std=%,$(CFLAGS)) -D_ISOMAC $(+includes)" \
          $(headers) > $@; \
        $(evaluate-test)
@@ -327,7 +555,7 @@ tests-special += $(objpfx)check-installed-headers-cxx.out
 libof-check-installed-headers-cxx := testsuite
 $(objpfx)check-installed-headers-cxx.out: \
     scripts/check-installed-headers.sh $(headers)
-       $(SHELL) $(..)scripts/check-installed-headers.sh c++ \
+       $(SHELL) $(..)scripts/check-installed-headers.sh c++ $(supported-fortify) \
          "$(CXX) $(filter-out -std=%,$(CXXFLAGS)) -D_ISOMAC $(+includes)" \
          $(headers) > $@; \
        $(evaluate-test)
@@ -339,11 +567,31 @@ $(objpfx)check-wrapper-headers.out: scripts/check-wrapper-headers.py $(headers)
          --generated $(common-generated) > $@; $(evaluate-test)
 endif # $(headers)
 
+# Lint all Makefiles; including this one.  Pass `pwd` as the source
+# directory since the top-level Makefile is in the root of the source
+# tree and these tests are run from there.  We add light-weight linting
+# to the 'check' target to support the existing developer workflow of:
+# edit -> make -> make check; without needing an additional step.
+tests-special += $(objpfx)lint-makefiles.out
+$(objpfx)lint-makefiles.out: scripts/lint-makefiles.sh
+       $(SHELL) $< "$(PYTHON)" `pwd` > $@ ; \
+       $(evaluate-test)
+
+# Link libc.a as a whole to verify that it does not contain multiple
+# definitions of any symbols.
+tests-special += $(objpfx)link-static-libc.out
+$(objpfx)link-static-libc.out:
+       $(LINK.o) $(whole-archive) -r $(objpfx)libc.a -o /dev/null > $@ 2>&1; \
+       $(evaluate-test)
+
+# Print test summary for tests in $1 .sum file;
+# $2 is optional test identifier.
+# Fail if there are unexpected failures in the test results.
 define summarize-tests
-@egrep -v '^(PASS|XFAIL):' $(objpfx)$1 || true
-@echo "Summary of test results$2:"
-@sed 's/:.*//' < $(objpfx)$1 | sort | uniq -c
-@! egrep -q -v '^(X?PASS|XFAIL|UNSUPPORTED):' $(objpfx)$1
+@grep -E '^[A-Z]+:' $(objpfx)$1 | grep -E -v '^(PASS|XFAIL):' || true
+@echo "                === Summary of results$2 ==="
+@sed -e '/:.*/!d' -e 's/:.*//' < $(objpfx)$1 | sort | uniq -c
+@! grep -E '^[A-Z]+:' $(objpfx)$1 | grep -E -q -v '^(X?PASS|XFAIL|UNSUPPORTED):'
 endef
 
 # The intention here is to do ONE install of our build into the
@@ -377,32 +625,42 @@ $(objpfx)testroot.pristine/install.stamp :
        # We need a working /bin/sh for some of the tests.
        test -d $(objpfx)testroot.pristine/bin || \
          mkdir $(objpfx)testroot.pristine/bin
+       # We need the compiled locale dir for localedef tests.
+       test -d $(objpfx)testroot.pristine/$(complocaledir) || \
+         mkdir -p $(objpfx)testroot.pristine/$(complocaledir)
        cp $(objpfx)support/shell-container $(objpfx)testroot.pristine/bin/sh
        cp $(objpfx)support/echo-container $(objpfx)testroot.pristine/bin/echo
        cp $(objpfx)support/true-container $(objpfx)testroot.pristine/bin/true
 ifeq ($(run-built-tests),yes)
        # Copy these DSOs first so we can overwrite them with our own.
        for dso in `$(test-wrapper-env) LD_TRACE_LOADED_OBJECTS=1  \
-               $(rtld-prefix) \
+               $(rtld-prefix) --inhibit-cache \
                $(objpfx)testroot.pristine/bin/sh \
-               | grep / | sed 's/^[^/]*//' | sed 's/ .*//'` ;\
+               | sed -n '/\//{s@.*=> /@/@;s/^[^/]*//;s/ .*//p;}'` ;\
          do \
            test -d `dirname $(objpfx)testroot.pristine$$dso` || \
              mkdir -p `dirname $(objpfx)testroot.pristine$$dso` ;\
            $(test-wrapper) cp $$dso $(objpfx)testroot.pristine$$dso ;\
          done
        for dso in `$(test-wrapper-env) LD_TRACE_LOADED_OBJECTS=1  \
-               $(rtld-prefix) \
+               $(rtld-prefix) --inhibit-cache \
                $(objpfx)support/$(LINKS_DSO_PROGRAM) \
-               | grep / | sed 's/^[^/]*//' | sed 's/ .*//'` ;\
+               | sed -n '/\//{s@.*=> /@/@;s/^[^/]*//;s/ .*//p;}'` ;\
          do \
            test -d `dirname $(objpfx)testroot.pristine$$dso` || \
              mkdir -p `dirname $(objpfx)testroot.pristine$$dso` ;\
            $(test-wrapper) cp $$dso $(objpfx)testroot.pristine$$dso ;\
          done
 endif
+       # $(symbolic-link-list) is a file that encodes $(DESTDIR) so we
+       # have to purge it
+       rm -f $(symbolic-link-list)
+       # Setting INSTALL_UNCOMPRESSED causes localedata/Makefile to
+       # install the charmaps uncompressed, as the testroot does not
+       # provide a gunzip program.
        $(MAKE) install DESTDIR=$(objpfx)testroot.pristine \
-         subdirs='$(sorted-subdirs)'
+         INSTALL_UNCOMPRESSED=yes subdirs='$(sorted-subdirs)'
+       rm -f $(symbolic-link-list)
        touch $(objpfx)testroot.pristine/install.stamp
 
 tests-special-notdir = $(patsubst $(objpfx)%, %, $(tests-special))
@@ -455,7 +713,7 @@ TAGS:
 
 generated := $(generated) stubs.h
 
-files-for-dist := README INSTALL configure ChangeLog NEWS
+files-for-dist := README INSTALL configure NEWS
 
 # Regenerate stuff, then error if these things are not committed yet.
 dist-prepare: $(files-for-dist)
@@ -486,7 +744,7 @@ endif
 INSTALL: manual/install-plain.texi manual/macros.texi \
         $(common-objpfx)manual/pkgvers.texi manual/install.texi
        makeinfo --no-validate --plaintext --no-number-sections \
-                -I$(common-objpfx)manual $< -o $@-tmp
+                --disable-encoding -I$(common-objpfx)manual $< -o $@-tmp
        $(AWK) 'NF == 0 { ++n; next } \
                NF != 0 { while (n-- > 0) print ""; n = 0; print }' \
          < $@-tmp > $@-tmp2
@@ -499,3 +757,12 @@ FORCE:
 
 iconvdata/% localedata/% po/%: FORCE
        $(MAKE) $(PARALLELMFLAGS) -C $(@D) $(@F)
+
+# Convenience target to rerun one test, from the top of the build tree
+# Example: make test t=wcsmbs/test-wcsnlen
+.PHONY: test
+test :
+       @-rm -f $(objpfx)$t.out
+       $(MAKE) subdir=$(patsubst %/,%,$(dir $t)) -C $(dir $t) ..=../ $(objpfx)$t.out
+       @cat $(objpfx)$t.test-result
+       @cat $(objpfx)$t.out