[patch#2] Fix in-src-tree builds by gdbserver/gnulib/ copy

Jan Kratochvil
2012-04-16T10:01:18Z

On Mon, 16 Apr 2012 09:56:10 +0200, Yao Qi wrote:
> I am afraid your patch doesn't work for gdbserver-only build, because
> target `diststuff' is not invoked at all.

True, fixed.

It is a bit incorrect with out-of-src-tree-gdbserver-only build it tries to
look at ../gnulib while this is outside of the directory being compiled, maybe
one could check if configure was run from parent configure or something like
that; but I did not consider it significant enough.

Thanks,
Jan

gdb/
2012-04-16 Jan Kratochvil <jan.kratochvil@redhat.com>

Fix builds in source tree.
* Makefile.in (diststuff): Recurse also into gdbserver.

gdb/gdbserver/
2012-04-16 Jan Kratochvil <jan.kratochvil@redhat.com>

Fix builds in source tree.
* Makefile.in (top_srcdir): New.
(GNULIB_INCLUDE_DIR): Change to ...
(GNULIB_INCLUDE_CFLAGS): ... here, include also local gnulib.
(GNULIB_FLAGS_TO_PASS): Remove.
(DISTSTUFF): New.
(all, install-only, uninstall, clean-info with others, all-lib, clean)
(distclean with others): Remove $(GNULIB_FLAGS_TO_PASS).
(diststuff, gnulib, gnulib-copy): New.
* configure: Regenerate.
* configure.ac: Test for gnulib/Makefile.in and create $GNULIB_SRC.
Call AC_CHECK_TOOL for AR.
(AC_OUTPUT) <gnulib/Makefile>: Use $GNULIB_SRC.

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index b8b7109..5fb8418 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -1249,6 +1249,7 @@ do-maintainer-clean:

diststuff: $(DISTSTUFF) $(PACKAGE).pot $(CATALOGS)
cd doc; $(MAKE) $(MFLAGS) diststuff
+ cd gdbserver; $(MAKE) $(MFLAGS) diststuff

subdir_do: force
@for i in $(DODIRS); do \
diff --git a/gdb/gdbserver/Makefile.in b/gdb/gdbserver/Makefile.in
index 6225e65..69da269 100644
--- a/gdb/gdbserver/Makefile.in
+++ b/gdb/gdbserver/Makefile.in
@@ -54,6 +54,7 @@ CC = @CC@
# Directory containing source files. Don't clean up the spacing,
# this exact string is matched for by the "configure" script.
srcdir = @srcdir@
+top_srcdir = @top_srcdir@
abs_top_srcdir=@abs_top_srcdir@
abs_srcdir=@abs_srcdir@
VPATH = @srcdir@
@@ -75,18 +76,10 @@ INCLUDE_DEP = $$(INCLUDE_DIR)
ustlibs = @ustlibs@
ustinc = @ustinc@

-# gnulib
-GNULIB_INCLUDE_DIR = $(srcdir)/../gnulib
+# gnulib; see gnulib-copy as it may be placed both in srcdir or objdir.
+GNULIB_INCLUDE_CFLAGS = -Ignulib -I$(srcdir)/../gnulib
GNULIB_LIB = gnulib/libgnu.a

-# We build gnulib directly under the gdbserver build directory, but
-# its sources don't live directly under gdbserver's source directory.
-# Tweak $srcdir and VPATH to make that work.
-GNULIB_FLAGS_TO_PASS = \
- "top_srcdir=$(abs_top_srcdir)/.." \
- "srcdir=$(abs_srcdir)/../gnulib" \
- "VPATH=$(abs_top_srcdir)/../gnulib:$(abs_top_srcdir)"
-
# Generated headers in the gnulib directory. These must be listed
# so that they are generated before other files are compiled.
GNULIB_H = gnulib/string.h @GNULIB_STDINT_H@
@@ -97,7 +90,7 @@ GNULIB_H = gnulib/string.h @GNULIB_STDINT_H@
# -I$(srcdir)/../regformats for regdef.h.
INCLUDE_CFLAGS = -I. -I${srcdir} -I$(srcdir)/../common \
-I$(srcdir)/../regformats -I$(INCLUDE_DIR) \
- -I$(GNULIB_INCLUDE_DIR)
+ $(GNULIB_INCLUDE_CFLAGS)

# M{H,T}_CFLAGS, if defined, has host- and target-dependent CFLAGS
# from the config/ directory.
@@ -122,6 +115,9 @@ INTERNAL_CFLAGS = ${INTERNAL_WARN_CFLAGS} $(WERROR_CFLAGS)
LDFLAGS = @LDFLAGS@
INTERNAL_LDFLAGS = $(LDFLAGS) @RDYNAMIC@

+# Things which need to be built when making a distribution.
+DISTSTUFF = gnulib
+
# All source files that go into linking GDB remote server.

SFILES= $(srcdir)/gdbreplay.c $(srcdir)/inferiors.c $(srcdir)/dll.c \
@@ -212,7 +208,7 @@ FLAGS_TO_PASS = \
${CC} -c ${INTERNAL_CFLAGS} $<

all: gdbserver$(EXEEXT) gdbreplay$(EXEEXT) $(extra_libraries)
- @cd gnulib; $(MAKE) $(FLAGS_TO_PASS) $(GNULIB_FLAGS_TO_PASS) all
+ @cd gnulib; $(MAKE) $(FLAGS_TO_PASS) all

# Traditionally "install" depends on "all". But it may be useful
# not to; for example, if the user has made some trivial change to a
@@ -233,13 +229,13 @@ install-only:
$(INSTALL_PROGRAM) gdbserver$(EXEEXT) $(DESTDIR)$(bindir)/$$n$(EXEEXT); \
$(SHELL) $(srcdir)/../../mkinstalldirs $(DESTDIR)$(man1dir); \
$(INSTALL_DATA) $(srcdir)/gdbserver.1 $(DESTDIR)$(man1dir)/$$n.1
- @cd gnulib; $(MAKE) $(FLAGS_TO_PASS) $(GNULIB_FLAGS_TO_PASS) install
+ @cd gnulib; $(MAKE) $(FLAGS_TO_PASS) install

uninstall: force
n=`echo gdbserver | sed '$(program_transform_name)'`; \
if [ x$$n = x ]; then n=gdbserver; else true; fi; \
rm -f $(DESTDIR)/$(bindir)/$$n$(EXEEXT) $(DESTDIR)$(man1dir)/$$n.1
- @cd gnulib; $(MAKE) $(FLAGS_TO_PASS) $(GNULIB_FLAGS_TO_PASS) uninstall
+ @cd gnulib; $(MAKE) $(FLAGS_TO_PASS) uninstall

installcheck:
check:
@@ -249,7 +245,7 @@ install-pdf:
html:
install-html:
clean-info: force
- @cd gnulib; $(MAKE) $(FLAGS_TO_PASS) $(GNULIB_FLAGS_TO_PASS) $@
+ @cd gnulib; $(MAKE) $(FLAGS_TO_PASS) $@

gdbserver$(EXEEXT): $(OBS) ${ADD_DEPS} ${CDEPS} $(GNULIB_LIB)
rm -f gdbserver$(EXEEXT)
@@ -258,7 +254,7 @@ gdbserver$(EXEEXT): $(OBS) ${ADD_DEPS} ${CDEPS} $(GNULIB_LIB)

$(GNULIB_LIB) $(GNULIB_H): all-lib
all-lib: gnulib/Makefile
- @cd gnulib; $(MAKE) $(FLAGS_TO_PASS) $(GNULIB_FLAGS_TO_PASS) all
+ @cd gnulib; $(MAKE) $(FLAGS_TO_PASS) all

.PHONY: all-lib

@@ -316,13 +312,44 @@ clean:
rm -f i386-mmx.c i386-mmx-linux.c
rm -f x32.c x32-linux.c
rm -f x32-avx.c x32-avx-linux.c
- @cd gnulib; $(MAKE) $(FLAGS_TO_PASS) $(GNULIB_FLAGS_TO_PASS) clean
+ @cd gnulib; $(MAKE) $(FLAGS_TO_PASS) clean

maintainer-clean realclean distclean: clean
rm -f nm.h tm.h xm.h config.h stamp-h config.log
- @cd gnulib; $(MAKE) $(FLAGS_TO_PASS) $(GNULIB_FLAGS_TO_PASS) $@
+ @cd gnulib; $(MAKE) $(FLAGS_TO_PASS) $@
rm -f Makefile config.status

+diststuff: $(DISTSTUFF)
+
+# gnulib is normally included in distributed tar. If we build from repository
+# and outside of the source tree put the gdbserver/gnulib copy into objdir.
+
+.PHONY: gnulib
+gnulib:
+ rm -rf gnulib.new
+ # gdbserver can be configured standalone, without ../gnulib/Makefile.
+ if test -e ../gnulib/Makefile ; then \
+ $(MAKE) -C ../gnulib distdir=../gdbserver/gnulib.new distdir; \
+ else \
+ cp -R -p ${srcdir}/../gnulib gnulib.new; \
+ fi
+ for src in `find gnulib.new -type d` ; do \
+ dst=`echo $$src | sed 's/gnulib\.new/gnulib/'`; \
+ mkdir -p $$dst; \
+ done
+ for src in `find gnulib.new -type f` ; do \
+ dst=`echo $$src | sed 's/gnulib\.new/gnulib/'`; \
+ rm -f $$dst; \
+ cp $$src $$dst; \
+ done
+ sed -e "s&\(@\)srcdir@&.&" \
+ -e "s&\(@\)top_srcdir@&..&" \
+ -e "s&\(@\)abs_srcdir@&$$PWD/gnulib&" \
+ -e "s&\(@\)abs_top_srcdir@&$$PWD&" \
+ < gnulib.new/Makefile.in > gnulib/Makefile.in
+ rm -rf gnulib.new
+ $(SHELL) ./config.status gnulib/Makefile
+
config.h: stamp-h ; @true
stamp-h: config.in config.status
CONFIG_FILES="" CONFIG_HEADERS=config.h:config.in $(SHELL) ./config.status
diff --git a/gdb/gdbserver/configure b/gdb/gdbserver/configure
index 2ff44ce..eca6532 100755
--- a/gdb/gdbserver/configure
+++ b/gdb/gdbserver/configure
@@ -597,6 +597,7 @@ gltests_LIBOBJS
gl_LTLIBOBJS
gl_LIBOBJS
LTLIBOBJS
+AR
GNULIB_STDINT_H
am__fastdepCC_FALSE
am__fastdepCC_TRUE
@@ -9981,7 +9982,109 @@ if test x"$STDINT_H" != x; then
fi

-ac_config_files="$ac_config_files Makefile gnulib/Makefile:${srcdir}/../gnulib/Makefile.in"
+# gnulib is normally included in distributed tar. If we build from repository
+# and outside of the source tree put the gdbserver/gnulib copy into objdir.
+if ! test -e ${srcdir}/gnulib/Makefile.in ; then
+ GNULIB_SRC=:${srcdir}/../gnulib/Makefile.in
+ ac_config_commands="$ac_config_commands gnulib"
+
+else
+ GNULIB_SRC=
+fi
+if test -n "$ac_tool_prefix"; then
+ # Extract the first word of "${ac_tool_prefix}ar", so it can be a program name with args.
+set dummy ${ac_tool_prefix}ar; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_AR+set}" = set; then :
+ $as_echo_n "(cached) " >&6
+else
+ if test -n "$AR"; then
+ ac_cv_prog_AR="$AR" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+ ac_cv_prog_AR="${ac_tool_prefix}ar"
+ $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+ break 2
+ fi
+done
+ done
+IFS=$as_save_IFS
+
+fi
+fi
+AR=$ac_cv_prog_AR
+if test -n "$AR"; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $AR" >&5
+$as_echo "$AR" >&6; }
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_AR"; then
+ ac_ct_AR=$AR
+ # Extract the first word of "ar", so it can be a program name with args.
+set dummy ar; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if test "${ac_cv_prog_ac_ct_AR+set}" = set; then :
+ $as_echo_n "(cached) " >&6
+else
+ if test -n "$ac_ct_AR"; then
+ ac_cv_prog_ac_ct_AR="$ac_ct_AR" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+ ac_cv_prog_ac_ct_AR="ar"
+ $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+ break 2
+ fi
+done
+ done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_AR=$ac_cv_prog_ac_ct_AR
+if test -n "$ac_ct_AR"; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_AR" >&5
+$as_echo "$ac_ct_AR" >&6; }
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+ if test "x$ac_ct_AR" = x; then
+ AR=""
+ else
+ case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+ AR=$ac_ct_AR
+ fi
+else
+ AR="$ac_cv_prog_AR"
+fi
+
+
+ac_config_files="$ac_config_files Makefile gnulib/Makefile$GNULIB_SRC"

ac_config_commands="$ac_config_commands default"

@@ -10733,8 +10836,9 @@ do
case $ac_config_target in
"config.h") CONFIG_HEADERS="$CONFIG_HEADERS config.h:config.in" ;;
"depfiles") CONFIG_COMMANDS="$CONFIG_COMMANDS depfiles" ;;
+ "gnulib") CONFIG_COMMANDS="$CONFIG_COMMANDS gnulib" ;;
"Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;;
- "gnulib/Makefile") CONFIG_FILES="$CONFIG_FILES gnulib/Makefile:${srcdir}/../gnulib/Makefile.in" ;;
+ "gnulib/Makefile$GNULIB_SRC") CONFIG_FILES="$CONFIG_FILES gnulib/Makefile$GNULIB_SRC" ;;
"default") CONFIG_COMMANDS="$CONFIG_COMMANDS default" ;;

*) as_fn_error "invalid argument: \`$ac_config_target'" "$LINENO" 5;;
@@ -11415,6 +11519,7 @@ $as_echo X"$file" |
done
}
;;
+ "gnulib":C) make gnulib ;;
"default":C) case x$CONFIG_HEADERS in
xconfig.h:config.in)
echo > stamp-h ;;
diff --git a/gdb/gdbserver/configure.ac b/gdb/gdbserver/configure.ac
index ac8223a..33e82a5 100644
--- a/gdb/gdbserver/configure.ac
+++ b/gdb/gdbserver/configure.ac
@@ -450,7 +450,17 @@ if test x"$STDINT_H" != x; then
fi
AC_SUBST(GNULIB_STDINT_H)

-AC_OUTPUT(Makefile gnulib/Makefile:${srcdir}/../gnulib/Makefile.in,
+# gnulib is normally included in distributed tar. If we build from repository
+# and outside of the source tree put the gdbserver/gnulib copy into objdir.
+if ! test -e ${srcdir}/gnulib/Makefile.in ; then
+ GNULIB_SRC=:${srcdir}/../gnulib/Makefile.in
+ AC_CONFIG_COMMANDS([gnulib], [make gnulib])
+else
+ GNULIB_SRC=
+fi
+AC_CHECK_TOOL(AR, ar)
+
+AC_OUTPUT(Makefile gnulib/Makefile$GNULIB_SRC,
[case x$CONFIG_HEADERS in
xconfig.h:config.in)
echo > stamp-h ;;