#! /usr/bin/make -f
# -*- makefile -*-

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

# This is the debhelper compatability version to use.
export DH_COMPAT=2

include debian/rules.defs
-include debian/rules.parameters

include debian/rules.unpack
include debian/rules.patch

# some tools
SHELL	= /bin/bash -e		# brace expansion in rules file
IR	= install -p -m 644	# Install regular file
IP	= install -p -m 755	# Install program
IS	= install -p -m 755	# Install script

# the recipient for the test summaries. Send with: debian/rules mail-summary
S_EMAIL = gcc@packages.debian.org gcc-testresults@gcc.gnu.org $(shell whoami)
#S_EMAIL = gcc@packages.debian.org $(shell whoami)

CPPFLAGS	=
CFLAGS		= $(CPPFLAGS)
CC		= cc $(CPPFLAGS)
LDFLAGS		=
BOOT_CFLAGS	= -g -O2 $(CPPFLAGS)

docdir		= usr/share/doc
#docdir		= usr/doc

cxx_inc_dir	= g++-$(LIBSTDCXX_IF)
ifeq ($(DEB_HOST_GNU_SYSTEM),linux-gnu)
  lib_arlib	= libstdc++-$(LIBSTDCXX_IF)$(LIBC_IF)$(CXX_IF)-$(lib_version).a
  lib_marlink	= libstdc++$(LIBC_IF)$(CXX_IF).a.$(LIBSTDCXX_IF)
  lib_shlib	= libstdc++-$(LIBSTDCXX_IF)$(LIBC_IF)$(CXX_IF)-$(lib_version).so
  lib_mshlink	= libstdc++$(LIBC_IF)$(CXX_IF).so.$(LIBSTDCXX_IF)
  lgp_arlib	= libg++-$(LIBSTDCXX_IF)$(LIBC_IF)$(CXX_IF)-$(lgp_version).a
  lgp_marlink	= libg++$(LIBC_IF)$(CXX_IF).a.$(LIBSTDCXX_IF)
  lgp_shlib	= libg++-$(LIBSTDCXX_IF)$(LIBC_IF)$(CXX_IF)-$(lgp_version).so
  lgp_mshlink	= libg++$(LIBC_IF)$(CXX_IF).so.$(LIBSTDCXX_IF)
else
  lib_arlib	= libstdc++.a.$(lib_version)
  lib_marlink	=
  lib_shlib	= libstdc++.so.$(lib_version)
  lib_mshlink	=
  lgp_arlib	= libg++.a.$(lgp_version)
  lgp_marlink	=
  lgp_shlib	= libg++.so.$(lgp_version)
  lgp_mshlink	=
endif
# lib_linkdir is the directory for the lib{stdc,g}++.{a,so} links

ifeq ($(TARGET),native)
lib_linkdir	= lib/gcc-lib/$(DEB_HOST_GNU_TYPE)/$(VER)
else
lib_linkdir	= lib/gcc-lib/$(TARGET)-linux/$(VER)
endif

# PF is the installation prefix for the package without the leading slash.
# It's "usr" for gcc releases; gcc snapshots go elsewhere.
ifneq ($(SNAPSHOT),yes)
  PF = usr
else
  PF = usr/lib/gcc-ss
endif

ifeq ($(TARGET),native)
LIBBUILDDIR	= $(DEB_HOST_GNU_TYPE)
gcc_lib_dir	= $(PF)/lib/gcc-lib/$(DEB_HOST_GNU_TYPE)/$(VER)
else
LIBBUILDDIR	= $(TARGET)-linux
gcc_lib_dir	= $(PF)/lib/gcc-lib/$(TARGET)-linux/$(VER)
endif

CONFARGS = -v \
	--enable-languages=$(shell echo $(enabled_languages) | tr -s ' ' ',') \
	--prefix=/$(PF) \
	--infodir=/$(PF)/share/info \
	--mandir=/$(PF)/share/man \
	--enable-shared \
	--disable-nls \
	--with-fast-fixincludes \
	--with-gnu-as \
	--with-gnu-ld
ifeq ($(with_java),yes)
  CONFARGS += --enable-java-gc=boehm
else
  CONFARGS += --enable-java-gc=no
endif
ifneq ($(SNAPSHOT),yes)
  CONFARGS += --with-cpp-install-dir=bin
endif
ifneq ($(SNAPSHOT),no)
  CONFARGS += --enable-threads=posix
else
  CONFARGS += --enable-threads
endif
ifeq ($(with_gplusplus),yes)
  ifneq ($(SNAPSHOT),no)
    CONFARGS += --enable-libstdcxx-v3
  endif
endif
ifeq ($(with_objc)-$(with_objc_gc),yes-yes)
    CONFARGS += --enable-objc-gc
endif
# MULTILIBS is one or more of "gcc g++ stdc++ chill objc g77"
# MULTIDIRS is in the format "32" or "{m68000,m68020,m68040}"
ifeq ($(DEB_HOST_GNU_TYPE),sparc64-linux-gnu)
    CONFARGS += --with-cpu=ultrasparc
    MULTIDIRS := 32
    MULTILIBS := gcc
  ifeq ($(with_gplusplus),yes)
    MULTILIBS += g++ stdc++
  endif
  ifeq ($(with_chill),yes)
    MULTILIBS += chill
  endif
  ifeq ($(with_objc),yes)
    MULTILIBS += objc
  endif
  ifeq ($(with_fortran),yes)
    MULTILIBS += g77
  endif
endif
ifeq ($(DEB_HOST_GNU_TYPE),sparc-linux-no)
    CONFARGS += --with-cpu=v7
    MULTIDIRS := 64
    MULTILIBS := gcc
endif
ifeq ($(DEB_HOST_GNU_TYPE),alpha-linux-gnu)
    MULTIDIRS := ieee
    MULTILIBS += g77
endif

CONFARGS += $(DEB_HOST_GNU_TYPE)

ifneq ($(TARGET),native)
CONFARGS += --target=$(TARGET)-linux
endif

ifneq ($(SNAPSHOT),yes)
  with_mail := no
else
  # see if we can find a tiny mail program to send the success story
  with_mail := $(strip $(shell if [ -x /usr/bin/mailx ]; \
		 then echo yes; else echo no; fi))
endif

default: build

$(configure_stamp_native):
	dh_testdir
	: # give information about the build process
	@echo "-------------------------- Build process variables --------------------------"
	@echo "Package source: $(PKGSOURCE)"
	@echo "Version: $(VER)"
	@echo "Base Debian version: $(DPKGVER)"
	@echo -e "Configured with: $(foreach i,$(CONFARGS),$(i)\n\t)"
	@echo "Using shell $(SHELL)"
	@echo "Architecture: $(DEB_HOST_ARCH) (GNU: $(DEB_HOST_GNU_TYPE))"
	@echo "SONAME: $(SONAME)"
	@echo "CPPFLAGS: $(CPPFLAGS)"
	@echo "CFLAGS: $(CFLAGS)"
	@echo "LDFLAGS: $(LDFLAGS)"
	@echo "BOOT_CFLAGS: $(BOOT_CFLAGS)"
	@echo "Install prefix: $(PF)"
	@echo "Will build a primary C compiler."
ifeq ($(with_check),yes)
	@echo "Will run the testsuite."
else
	@echo "Will not run the testsuite: $(with_check)"
	@echo "Please install dejagnu and restart."
#	false
endif
ifeq ($(with_gplusplus),yes)
	@echo "Will build the C++ compiler."
else
	@echo "Will not build the C++ compiler: $(with_gplusplus)"
endif
ifeq ($(with_objc_gc),yes)
	@echo "Will build the extra ObjC runtime for garbage collection."
else
	@echo "Will not build the extra ObjC runtime for garbage collection."
endif
ifeq ($(with_java),yes)
	@echo "Will build the Java compiler."
else
	@echo "Will not build the Java compiler: $(with_java)"
endif
ifeq ($(with_chill),yes)
	@echo "Will build the CHILL compiler."
else
	@echo "Will not build the CHILL compiler: $(with_chill)"
endif
ifeq ($(with_pascal),yes)
	@echo "Will build the Pascal compiler."
else
	@echo "Will not build the Pascal compiler: $(with_pascal)"
endif
ifeq ($(with_fortran),yes)
	@echo "Will build the Fortran compiler."
else
	@echo "Will not build the Fortran compiler: $(with_fortran)"
endif
ifeq ($(with_proto),yes)
	@echo "Will build the protoize/unprotoize programs."
else
	@echo "Will not build the protoize/unprotoize programs: $(with_proto)"
endif
ifeq ($(with_libgpp),yes)
	@echo "Will build the deprecated g++ libraries."
else
	@echo "Will not build the deprecated g++ libraries: $(with_libgpp)"
endif
ifeq ($(with_check),yes)
  ifeq ($(with_mail),yes)
	@echo "Will send the success story to the Debian GCC maintainers."
  else
	@echo "Cannot find the mailx program to send a build report to the"
	@echo "Debian GCC maintainers. Please install and restart."
#	false
  endif
endif
	@echo "-----------------------------------------------------------------------------"
	@echo ""
	rm -f $(configure_stamp)-$(TARGET) $(build_stamp)-$(TARGET)
	: # generate debian/README.Debian
	cat debian/README $(patch_stamp)-$(TARGET) > debian/README.Debian

ifeq ($(with_pascal),yes)
	echo '# dummy file' >> $(srcdir)/gcc/p/Makefile.in
endif

#ifeq ($(with_pascal),yes)
#	if [ ! -f $(srcdir)/gcc/p/config-lang.in ]; then \
#	  cp -p $(srcdir)/gcc/p/config-lang.in.debian \
#	     $(srcdir)/gcc/p/config-lang.in; \
#	else \
#	  true; \
#	fi
#else
#	if [ -f $(srcdir)/gcc/p/config-lang.in ]; then \
#	  mv -f $(srcdir)/gcc/p/config-lang.in \
#	    $(srcdir)/gcc/p/config-lang.in.debian; \
#	else \
#	  true; \
#	fi
#endif

#	rm -f $(srcdir)/gcc/configure
#	cd $(srcdir)/gcc && autoconf
	rm -rf $(builddir)
	mkdir $(builddir)

	rm -rf bin
	mkdir bin
	if [ -f /usr/bin/bison-1.35 ]; then \
	  ln -s /usr/bin/bison-1.35 bin/bison; \
	else \
	  ln -s /usr/bin/bison bin/bison; \
	fi

	: # configure
	PATH=`pwd`/bin:$$PATH cd $(builddir) \
		&& CC="$(CC)" $(srcdir)/configure $(CONFARGS)

	touch $(configure_stamp_native)

$(configure_stamps_cross):
	dh_testdir
	: # give information about the build process
	@echo "-------------------------- Build process variables --------------------------"
	@echo "Package source: $(PKGSOURCE)"
	@echo "Version: $(VER)"
	@echo "Base Debian version: $(DPKGVER)"
	@echo -e "Configured with: $(foreach i,$(CONFARGS),$(i)\n\t)"
	@echo "Using shell $(SHELL)"
	@echo "Architecture: $(DEB_HOST_ARCH) (GNU: $(DEB_HOST_GNU_TYPE))"
	@echo "SONAME: $(SONAME)"
	@echo "CPPFLAGS: $(CPPFLAGS)"
	@echo "CFLAGS: $(CFLAGS)"
	@echo "LDFLAGS: $(LDFLAGS)"
	@echo "BOOT_CFLAGS: $(BOOT_CFLAGS)"
	@echo "Install prefix: $(PF)"
	@echo "Will build a CROSS C compiler."

	rm -rf $(builddir)
	mkdir $(builddir)

	rm -rf bin
	mkdir bin
	ln -s /usr/bin/bison-1.35 bin/bison

	PATH=`pwd`/bin:$$PATH cd $(builddir) \
		&& CC="$(CC)" $(srcdir)/configure $(CONFARGS)

	touch $@


$(build_stamp_native):
	dh_testdir
	: # start the build
	rm -f bootstrap-protocol
	( \
	  set +e; \
	  PATH=`pwd`/bin:$$PATH \
	    $(MAKE) -C $(builddir) bootstrap-lean \
		CC="$(CC)" CFLAGS="$(CFLAGS)" \
		BISON=bison-1.35 \
		BOOT_CFLAGS="$(BOOT_CFLAGS)" LDFLAGS="$(LDFLAGS)"; \
	  echo $$? > status; \
	) 2>&1 | tee bootstrap-protocol
	s=`cat status`; rm -f status; test $$s -eq 0
ifeq ($(with_gplusplus),yes)
  ifeq ($(versioned_packages),yes)
	sed -e 's/iostream\.info/iostream-2.95.info/g' \
	  $(builddir)/$(LIBBUILDDIR)/libio/Makefile \
	  > $(builddir)/$(LIBBUILDDIR)/libio/Makefile2
	mv -f $(builddir)/$(LIBBUILDDIR)/libio/Makefile2 \
	  $(builddir)/$(LIBBUILDDIR)/libio/Makefile
  endif
	$(MAKE) -C $(builddir)/$(LIBBUILDDIR)/libio info
  ifeq ($(with_libgpp),yes)
	$(MAKE) -C $(builddir)/$(LIBBUILDDIR)/libg++ info
  endif
endif
	-chmod 755 $(srcdir)/contrib/warn_summary
	if [ -x $(srcdir)/contrib/warn_summary ]; then \
	  rm -f bootstrap-summary; \
	  $(srcdir)/contrib/warn_summary bootstrap-protocol \
	    > bootstrap-summary; \
	fi

ifeq ($(with_fortran),yes)
	: # build libg2c.a with PIC enabled
	rm -rf $(builddir)/$(DEB_HOST_GNU_TYPE)/libf2c-pic
	cp -a $(builddir)/$(DEB_HOST_GNU_TYPE)/libf2c \
		$(builddir)/$(DEB_HOST_GNU_TYPE)/libf2c-pic
	$(MAKE) -C $(builddir)/$(DEB_HOST_GNU_TYPE)/libf2c-pic clean
	$(MAKE) -C $(builddir)/$(DEB_HOST_GNU_TYPE)/libf2c-pic \
		LIBG2C=libg2c-pic.a CFLAGS="-O2 -fPIC -DPIC"
endif

# make check ...
ifeq ($(with_check),yes)
	rm -f test-protocol

  ifeq ($(DEB_HOST_GNU_SYSTEM),linux-gnu)
	-echo "Running testsuite ..."; \
	  if [ -e /proc/meminfo ]; then \
	    m=`awk '/^((Mem|Swap)Free|Cached)/{m+=$$2}END{print int(m*.9)}' \
		/proc/meminfo`; \
	  else \
	    m=`vmstat --free --swap-free --kilobytes|awk '{m+=$$2}END{print int(m*.9)}'`; \
	  fi; \
	  ulimit -m $$m; \
	  echo "Limited memory for test runs to `ulimit -m`kB"; \
	  $(MAKE) -C $(builddir) -k check 2>&1 | tee test-protocol
  else
	-echo "Running testsuite ..."; \
	  $(MAKE) -C $(builddir) -k check 2>&1 | tee test-protocol
  endif

	-chmod 755 $(srcdir)/contrib/test_summary
	if [ -x $(srcdir)/contrib/test_summary ]; then \
	  rm -f test-summary; \
	  ( \
	    cd $(builddir); \
	    BOOT_CFLAGS="$(BOOT_CFLAGS)" LIBS=-lpthread \
	      $(srcdir)/contrib/test_summary -i $(patch_stamp) -m "$(S_EMAIL)" \
	  ) > raw-test-summary; \
	  awk '/^cat/, /^EOF/' raw-test-summary | grep -v EOF > test-summary; \
	fi
endif
ifeq ($(with_pascal),yes)
	$(MAKE) -C $(builddir)/gcc -k check-pascal
	if [ -f $(builddir)/gcc/p/test/test_summary ]; then \
	  echo 'BEGIN gpc-test-summary'; \
	  cat $(builddir)/gcc/p/test/test_summary | tee gpc-test-summary; \
	  echo 'END gpc-test-summary'; \
	else \
	  echo "No gpc test results" > gpc-test-summary; \
	fi
endif
	touch $(build_stamp_native)

# make check ...
check:
	rm -f test-protocol

ifeq ($(DEB_HOST_GNU_SYSTEM),linux-gnu)
	-echo "Running testsuite ..."; \
	  if [ -e /proc/meminfo ]; then \
	    m=`awk '/^((Mem|Swap)Free|Cached)/{m+=$$2}END{print int(m*.9)}' \
		/proc/meminfo`; \
	  else \
	    m=`vmstat --free --swap-free --kilobytes|awk '{m+=$$2}END{print int(m*.9)}'`; \
	  fi; \
	  ulimit -m $$m; \
	  echo "Limited memory for test runs to `ulimit -m`kB"; \
	  $(MAKE) -C $(builddir) -k check 2>&1 | tee test-protocol
else
	-echo "Running testsuite ..."; \
	  $(MAKE) -C $(builddir) -k check 2>&1 | tee test-protocol
endif

	-chmod 755 $(srcdir)/contrib/test_summary
	if [ -x $(srcdir)/contrib/test_summary ]; then \
	  rm -f test-summary; \
	  ( \
	    cd $(builddir); \
	    BOOT_CFLAGS="$(BOOT_CFLAGS)" LIBS=-lpthread \
	      $(srcdir)/contrib/test_summary -i $(patch_stamp) -m "$(S_EMAIL)" \
	  ) > raw-test-summary; \
	  awk '/^cat/, /^EOF/' raw-test-summary | grep -v EOF > test-summary; \
	fi
ifeq ($(with_pascal),yes)
	$(MAKE) -C $(builddir)/gcc -k check-pascal
	if [ -f $(builddir)/gcc/p/test/test_summary ]; then \
	  echo 'BEGIN gpc-test-summary'; \
	  cat $(builddir)/gcc/p/test/test_summary | tee gpc-test-summary; \
	  echo 'END gpc-test-summary'; \
	else \
	  echo "No gpc test results" > gpc-test-summary; \
	fi
endif

$(build_stamps_cross):
  ifeq ($(with_gplusplus),yes)
	  PATH=`pwd`/bin:$$PATH \
	    $(MAKE) -C $(builddir) LANGUAGES="c c++" BISON=bison-1.35
  else
	  PATH=`pwd`/bin:$$PATH \
	    $(MAKE) -C $(builddir) LANGUAGES="c" BISON=bison-1.35
  endif
	touch $@


mail-summary:
	@if [ ! -f /usr/bin/Mail ]; then \
	  echo "Please install the mailx package to send the summary"; \
	  exit 1; \
	fi
	-chmod 755 contrib/test_summary
	if [ -x contrib/test_summary ]; then \
	  rm -f test-summary; \
	  ( \
	    cd $(builddir); \
	    BOOT_CFLAGS="$(BOOT_CFLAGS)" \
	      $(srcdir)/contrib/test_summary -i $(patch_stamp) -m "$(S_EMAIL)" \
	  ) > raw-test-summary; \
	fi
	echo -n "Send summary to $(S_EMAIL) (y/n) "; read x; \
	case "$$x" in \
	  y*|Y*) cat raw-test-summary | sh; echo "Sent mail to $(S_EMAIL)";; \
	  *) echo "Mail not sent.";; \
	esac

clean: debian/control
	dh_testdir
	rm -f pxxx status
# remove temporary dirs used for unpacking
	rm -rf $(gcc_srcdir) $(libgpp_srcdir) $(gpc_srcdir)
ifeq ($(with_pascal),yes)
	rm -f $(srcdir)/gcc/p/doc/*info
	rm -f $(srcdir)/gcc/p/test/{fjf51,fjf141aa,fjf199aa,magic,?,knownbugs/a.out}
endif
	if [ -f $(srcdir)/gcc/p/config-lang.in.debian ]; then \
	  mv -f $(srcdir)/gcc/p/config-lang.in.debian $(srcdir)/gcc/p/config-lang.in; \
	else true; fi
	rm -f $(srcdir)/gcc/po/*.gmo
	rm -f debian/lib{g++,stdc++}[0-9]*.{{pre,post}{inst,rm},shlibs}
	rm -rf debian/tmp*
	rm -f *-summary *-protocol

#	$(MAKE) -f debian/rules reverse-patches
	$(MAKE) -C debian/bugs clean
	rm -rf bin

	dh_clean

# ------------------------------------------------------------------------------
# some abbrevations for the package names and directories;
# p_XXX is the package name, d_XXX is the package directory
# these macros are only used in the binary-* targets.

# p_gcc used only for primary compiler, p_gpc used only for pascal.
ifeq ($(SNAPSHOT),yes)
  ss_suffix = -ss
endif

ifneq ($(TARGET),native)
  ss_suffix += -$(TARGET)
endif

ifeq ($(versioned_packages),yes)
  pkg_ver := -2.95
endif

p_gcc	= gcc$(pkg_ver)$(ss_suffix)
p_cpp	= cpp$(pkg_ver)$(ss_suffix)
p_cppd	= cpp$(pkg_ver)-doc$(ss_suffix)
p_objc	= gobjc$(pkg_ver)$(ss_suffix)
p_proto	= protoize$(pkg_ver)$(ss_suffix)
p_gpp	= g++$(pkg_ver)$(ss_suffix)
p_g77	= g77$(pkg_ver)$(ss_suffix)
p_g77d	= g77$(pkg_ver)-doc$(ss_suffix)
p_gch	= chill$(pkg_ver)$(ss_suffix)
p_java	= gcj$(pkg_ver)$(ss_suffix)
p_gpc	= gpc$(pkg_ver)$(ss_suffix)
p_gpcd	= gpc$(pkg_ver)-doc$(ss_suffix)
p_doc	= gcc$(pkg_ver)-doc$(ss_suffix)

p_lib	= libstdc++$(PKG_SONAME)$(ss_suffix)
p_dev	= libstdc++$(PKG_DEV_SONAME)-dev$(ss_suffix)
p_dbg	= libstdc++$(PKG_DEV_SONAME)-dbg$(ss_suffix)
p_lgp	= libg++$(LGP_PKG_SONAME)$(ss_suffix)
p_lgd	= libg++$(LGP_PKG_DEV_SONAME)-dev$(ss_suffix)
p_lgdbg	= libg++$(LGP_PKG_DEV_SONAME)-dbg$(ss_suffix)

d=debian/tmp-$(TARGET)

d_gcc	= debian/$(p_gcc)
d_cpp	= debian/$(p_cpp)
d_cppd	= debian/$(p_cppd)
d_objc	= debian/$(p_objc)
d_proto	= debian/$(p_proto)
d_gpp	= debian/$(p_gpp)
d_g77	= debian/$(p_g77)
d_g77d	= debian/$(p_g77d)
d_gch	= debian/$(p_gch)
d_java	= debian/$(p_java)
d_gpc	= debian/$(p_gpc)
d_gpcd	= debian/$(p_gpcd)
d_lib	= debian/$(p_lib)
d_dev	= debian/$(p_dev)
d_dbg	= debian/$(p_dbg)
d_lgp	= debian/$(p_lgp)
d_lgd	= debian/$(p_lgd)
d_lgdbg	= debian/$(p_lgdbg)
d_doc	= debian/$(p_doc)
d_docs	= debian/$(p_docs)

ifeq ($(DEB_HOST_ARCH),powerpc)
  p_nof  = gcc$(pkg_ver)-nof$(ss_suffix)
  d_nof  = debian/$(p_nof)
endif

ifeq ($(DEB_HOST_ARCH),arm)
  p_softfloat  = gcc$(pkg_ver)-soft-float$(ss_suffix)
  d_softfloat  = debian/$(p_softfloat)
endif

ifeq ($(DEB_HOST_ARCH),armeb)
  p_softfloat  = gcc$(pkg_ver)-soft-float$(ss_suffix)
  d_softfloat  = debian/$(p_softfloat)
endif

# gcc must be moved after g77 and g++
# not all files $(PF)/include/*.h are part of gcc,
# but it becomes difficult to name all these files ...
dirs_gcc = \
	lib \
	$(docdir)/$(p_gcc) \
	$(PF)/bin \
	$(gcc_lib_dir)/include \
	$(PF)/share/man/man1
ifeq ($(TARGET),native)
files_gcc = \
	$(PF)/bin/{$(TP)gcc,gcov}$(pkg_ver) \
	$(gcc_lib_dir)/{collect2,specs,cc1,libgcc.*,*.o} \
	$(PF)/share/man/man1/{$(TP)gcc,gcov}$(pkg_ver).1 \
	$(gcc_lib_dir)/include/{README,*.h} \
	$(shell for d in asm bits gnu linux; do \
		  test -e $(d)/$(gcc_lib_dir)/include/$$d \
		    && echo $(gcc_lib_dir)/include/$$d; \
		done)
#ifeq ($(VER),2.95.4)
#    files_gcc += \
#	$(PF)/bin/egcc \
#	$(PF)/share/man/man1/egcc.1
#endif
else
files_gcc = \
	$(PF)/bin/$(TP)gcc \
	$(gcc_lib_dir)/{collect2,specs,cc1,libgcc.*,*.o} \
	$(gcc_lib_dir)/include/{README,*.h} \
	$(shell for d in asm bits gnu linux; do \
		  test -e $(d)/$(gcc_lib_dir)/include/$$d \
		    && echo $(gcc_lib_dir)/include/$$d; \
		done)
ifeq ($(TARGET),powerpc)
    dirs_gcc += $(gcc_lib_dir)/nof $(gcc_lib_dir)/nof/pic $(gcc_lib_dir)/pic
    files_gcc += \
	$(gcc_lib_dir)/nof/{libgcc.a,*.o} \
	$(gcc_lib_dir)/nof/pic/{libgcc.a,*.o} $(gcc_lib_dir)/pic/{libgcc.a,*.o}
endif
ifeq ($(TARGET)-$(with_arm_soft_float),arm-yes)
    dirs_gcc += $(gcc_lib_dir)/soft-float
    files_gcc += $(gcc_lib_dir)/soft-float/{libgcc.a,*.o}
endif
ifeq ($(TARGET)-$(with_arm_soft_float),armeb-yes)
    dirs_gcc += $(gcc_lib_dir)/soft-float
    files_gcc += $(gcc_lib_dir)/soft-float/{libgcc.a,*.o}
endif
endif
files_gcc += \
	$(shell test -e $(d)/$(gcc_lib_dir)/SYSCALLS.c.X \
		&& echo $(gcc_lib_dir)/SYSCALLS.c.X)
#files_gcc += \
#	$(gcc_lib_dir)/SYSCALLS.c.X
ifneq (,$(findstring gcc,$(MULTILIBS)))
    dirs_gcc += $(gcc_lib_dir)/$(MULTIDIRS)
    files_gcc += $(gcc_lib_dir)/$(MULTIDIRS)/{libgcc.a,*.o}
endif
ifeq ($(DEB_HOST_GNU_TYPE),sparc-linux-no)
    files_gcc += $(PF)/bin/sparc64-linux-gcc-wrapper
endif

ifeq ($(DEB_HOST_ARCH),powerpc)
  dirs_nof = \
	$(PF)/lib/nof \
	$(gcc_lib_dir)/nof
  files_nof = \
	$(PF)/lib/nof \
	$(gcc_lib_dir)/nof
endif

ifeq ($(TARGET)-$(with_arm_soft_float),arm-yes)
  dirs_softfloat = \
	$(PF)/lib/soft-float \
	$(gcc_lib_dir)/soft-float
  files_softfloat = \
	$(PF)/lib/soft-float \
	$(gcc_lib_dir)/soft-float
endif

ifeq ($(TARGET)-$(with_arm_soft_float),armeb-yes)
  dirs_softfloat = \
	$(PF)/lib/soft-float \
	$(gcc_lib_dir)/soft-float
  files_softfloat = \
	$(PF)/lib/soft-float \
	$(gcc_lib_dir)/soft-float
endif

dirs_cpp = \
	$(docdir)/$(p_cpp) \
	$(PF)/share/man/man1 \
	$(PF)/bin
ifeq ($(TARGET),native)
files_cpp = \
	$(PF)/bin/cpp$(pkg_ver) \
	$(gcc_lib_dir)/cpp0 \
	$(PF)/share/man/man1/cpp$(pkg_ver).1
else
files_cpp = \
	$(gcc_lib_dir)/cpp0
endif
#ifeq ($(TARGET),native)
#ifneq ($(SNAPSHOT),yes)
#  dirs_cpp += lib
#  files_cpp += lib/cpp
#endif
#endif

dirs_cppd = \
	$(docdir)/$(p_cppd) \
	$(PF)/share/info
files_cppd = \
	$(PF)/share/info/cpp*

dirs_objc = \
	$(docdir)/$(p_gcc) \
	$(gcc_lib_dir)/include
files_objc = \
	$(gcc_lib_dir)/include/objc \
	$(gcc_lib_dir)/{cc1obj,libobjc*.a}
ifneq (,$(findstring objc,$(MULTILIBS)))
    dirs_objc += $(gcc_lib_dir)/$(MULTIDIRS)
    files_objc += $(gcc_lib_dir)/$(MULTIDIRS)/libobjc*.a
endif

dirs_proto = \
	$(docdir)/$(p_gcc) \
	$(PF)/share/man/man1 \
	$(PF)/bin
files_proto = \
	$(PF)/bin/{protoize,unprotoize}$(pkg_ver) \
	$(PF)/share/man/man1/{protoize,unprotoize}$(pkg_ver).1

dirs_gpp = \
	$(docdir)/$(p_gpp) \
	$(PF)/bin \
	$(PF)/share/info \
	$(gcc_lib_dir)/include \
	$(PF)/share/man/man1
files_gpp = \
	$(PF)/bin/$(TP)g++$(pkg_ver) \
	$(gcc_lib_dir)/cc1plus \
	$(gcc_lib_dir)/include/{new,new.h,typeinfo,exception}
ifeq ($(TARGET),native)
  files_gpp += \
	$(PF)/share/man/man1/g++$(pkg_ver).1
endif


dirs_g77 = \
	$(docdir)/$(p_g77) \
	$(PF)/bin \
	$(gcc_lib_dir)/include \
	$(PF)/include \
	$(PF)/share/man/man1
files_g77 = \
	$(PF)/bin/g77$(pkg_ver) \
	$(gcc_lib_dir)/{f771,libg2c*.a} \
	$(gcc_lib_dir)/include/g2c.h \
	$(PF)/share/man/man1/g77$(pkg_ver).1
ifneq (,$(findstring g77,$(MULTILIBS)))
    dirs_g77 += $(gcc_lib_dir)/$(MULTIDIRS)
    files_g77 += $(gcc_lib_dir)/$(MULTIDIRS)/libg2c.a
endif

dirs_g77d = \
	$(docdir)/$(p_g77d) \
	$(PF)/share/info
files_g77d = \
	$(PF)/share/info/g77*

dirs_chill = \
	$(docdir)/$(p_gch) \
	$(PF)/bin \
	$(gcc_lib_dir) \
	$(PF)/share/man/man1 \
	$(PF)/share/info

files_chill = \
	$(PF)/bin/chill$(pkg_ver) \
	$(gcc_lib_dir)/*chill* \
	$(PF)/share/info/chill*
ifneq (,$(findstring chill,$(MULTILIBS)))
    dirs_chill += $(gcc_lib_dir)/$(MULTIDIRS)
    files_chill += $(gcc_lib_dir)/$(MULTIDIRS)/*chill*.{a,o}
endif

dirs_java = \
	$(docdir)/$(p_java) \
	$(PF)/bin \
	$(PF)/share/man/man1 \
	$(gcc_lib_dir)
files_java = \
	$(PF)/bin/{gcj,gcjh,jv-scan,jcf-dump}$(pkg_ver) \
	$(gcc_lib_dir)/{jc1,jvgenmain}

dirs_gpc = \
	$(docdir)/$(p_gpc) \
	$(PF)/bin \
	$(gcc_lib_dir)/{include,units} \
	$(PF)/share/man/man1
files_gpc = \
	$(PF)/bin/gpc$(pkg_ver) \
	$(PF)/bin/gpc-run$(pkg_ver) \
	$(PF)/bin/binobj$(pkg_ver) \
	$(PF)/bin/gpidump$(pkg_ver) \
	$(PF)/share/man/man1/gpc$(pkg_ver).1 \
	$(PF)/share/man/man1/gpc-run$(pkg_ver).1 \
	$(PF)/share/man/man1/binobj$(pkg_ver).1 \
	$(PF)/share/man/man1/gpidump$(pkg_ver).1 \
	$(gcc_lib_dir)/{gpcpp,gpc1,libgpc.a,units} \
	$(gcc_lib_dir)/include/gpc-in-c.h
ifneq (,$(findstring gpc,$(MULTILIBS)))
    dirs_gpc += $(gcc_lib_dir)/$(MULTIDIRS)
    files_gpc += $(gcc_lib_dir)/$(MULTIDIRS)/libgpc.a
endif

dirs_gpcd = \
	$(docdir)/$(p_gpcd) \
	$(PF)/share/info
files_gpcd = \
	$(docdir)/$(p_gpc)/examples/* \
	$(docdir)/$(p_gpc)/docdemos \
	$(PF)/share/info/gpc*2.95*

dirs_lgp = \
	$(docdir)/$(p_lgp) \
	$(PF)/lib
files_lgp = \
	$(addprefix $(PF)/lib/, $(lgp_shlib) $(lgp_mshlink))
ifneq (,$(findstring g++,$(MULTILIBS)))
    dirs_lgp += $(PF)/lib/$(MULTIDIRS)
    files_lgp += \
	$(addprefix $(PF)/lib/$(MULTIDIRS)/, $(lgp_shlib) $(lgp_mshlink))
endif

dirs_lgd = \
	$(docdir)/$(p_lgp) \
	$(PF)/bin \
	$(PF)/share/info \
	$(gcc_lib_dir) \
	$(PF)/share/man/man1 \
	$(PF)/include/$(cxx_inc_dir)/gen
files_lgd = \
	$(PF)/bin/genclass \
	$(PF)/share/man/man1/genclass.1 \
	$(PF)/share/info/libg++.info* \
	$(addprefix $(PF)/lib/, $(lgp_arlib) $(lgp_marlink)) \
	$(gcc_lib_dir)/libg++.{a,so} \
	$(PF)/include/$(cxx_inc_dir)/gen/ \
	$(PF)/include/$(cxx_inc_dir)/{$(shell cd $(srcdir)/libg++/src; \
						echo *.h | tr ' ' ,)}
ifneq (,$(findstring g++,$(MULTILIBS)))
    dirs_lgd += $(gcc_lib_dir)/$(MULTIDIRS)
    files_lgd += \
	$(addprefix $(PF)/lib/$(MULTILIB)/, $(lgp_arlib) $(lgp_marlink)) \
	$(gcc_lib_dir)/$(MULTIDIRS)/libg++.{a,so}
endif

dirs_lgdbg = \
	usr/share/lintian/overrides \
	$(docdir) \
	$(PF)/lib/debug
#files_lgd =

ifeq ($(TARGET),native)

dirs_lib = \
	$(docdir)/$(p_lib) \
	$(PF)/lib
files_lib = \
	$(addprefix $(PF)/lib/, $(lib_shlib) $(lib_mshlink))
ifneq (,$(findstring stdc++,$(MULTILIBS)))
    dirs_lib += $(PF)/lib/$(MULTIDIRS)
    files_lib += \
	$(addprefix $(PF)/lib/$(MULTIDIRS)/, $(lib_shlib) $(lib_mshlink))
endif
else
dirs_lib = \
	$(docdir)/$(p_lib) \
	$(gcc_lib_dir)
files_lib = \
	$(addprefix $(PF)/$(TARGET)-linux/lib/, $(lib_shlib) $(lib_mshlink))
ifneq (,$(findstring stdc++,$(MULTILIBS)))
    dirs_lib += $(gcc_lib_dir)/$(MULTIDIRS)
    files_lib += \
	$(addprefix $(gcc_lib_dir)/$(MULTIDIRS)/, $(lib_shlib) $(lib_mshlink))

endif
endif

ifeq ($(TARGET),native)

dirs_dev = \
	$(docdir)/$(p_lib) \
	$(PF)/share/info \
	$(PF)/lib \
	$(PF)/include/$(cxx_inc_dir)/std
# libg++-dev must be moved first !!!
# not all files in $(PF)/include/$(cxx_inc_dir)/,
# but it becomes difficult to name all these files ...
files_dev = \
	$(addprefix $(PF)/lib/, $(lib_arlib) $(lib_marlink)) \
	$(PF)/include/$(cxx_inc_dir)/ \
	$(PF)/share/info/iostream* \
	$(PF)/$(lib_linkdir)/libstdc++.{a,so}
ifneq (,$(findstring stdc++,$(MULTILIBS)))
    files_dev += $(PF)/$(lib_linkdir)/$(MULTIDIRS)/libstdc++.{a,so} \
       $(addprefix $(PF)/lib/$(MULTIDIRS)/, $(lib_arlib) $(lib_marlink))
endif
ifeq ($(DEB_HOST_GNU_SYSTEM),gnu)
    files_dev += $(PF)/include/_G_config.h
endif

else

dirs_dev = \
	$(docdir)/$(p_lib) \
	$(PF)/lib
# libg++-dev must be moved first !!!
# not all files in $(PF)/include/$(cxx_inc_dir)/,
# but it becomes difficult to name all these files ...
files_dev = \
	$(addprefix $(PF)/$(TARGET)-linux/lib/, $(lib_arlib) $(lib_marlink)) \
	$(PF)/$(lib_linkdir)/libstdc++.{a,so}
ifneq (,$(findstring stdc++,$(MULTILIBS)))
    files_dev += $(PF)/$(TARGET)-linux/lib/$(MULTIDIRS)/libstdc++.{a,so} \
       $(addprefix $(PF)/$(TARGET)-linux/lib/$(MULTIDIRS)/, $(lib_arlib) $(lib_marlink))

endif

endif

dirs_dbg = \
	usr/share/lintian/overrides \
	$(docdir) \
	$(PF)/lib/debug
files_dbg =

dirs_doc = \
	$(docdir)/$(p_doc) \
	$(PF)/share/info
files_doc = \
	$(PF)/share/info/gcc*

ifeq ($(TARGET)-$(with_arm_soft_float),arm-yes)
  dirs_gcc += $(PF)/lib/soft-float
endif

ifeq ($(TARGET)-$(with_arm_soft_float),armeb-yes)
  dirs_gcc += $(PF)/lib/soft-float
endif

foo-%:
	echo T: $(TARGET) $(d)
	echo $(dirs_gcc)
	echo $(files_gcc)
	echo X: test -e $(d)/$(gcc_lib_dir)/SYSCALLS.c.X \
		&& echo $(gcc_lib_dir)/SYSCALLS.c.X
	echo X: $(shell test -e $(d)/$(gcc_lib_dir)/SYSCALLS.c.X \
		&& echo $(gcc_lib_dir)/SYSCALLS.c.X)


# ----------------------------------------------------------------------
# install: $(install_stamps) first-move-stamp
$(install_stamp)-%:
	dh_testdir
	dh_testroot

	rm -f debian/tmp
	ln -sf tmp-$(TARGET) debian/tmp

	rm -Rf $(PDIRS)

#	rm -f debian/control
#	$(MAKE) -f debian/rules debian/control
#ifeq ($(TARGET),native)
#	dh_clean -k
#endif
	: # Install directories
	rm -rf $(d)/$(PF)


# directories which need to be created by hand:
# $(PF)/share, because infodir and mandir are reset
# $(PF)/bin, because libio does not check for include/g++-X
# $(PF)/include/$(cxx_inc_dir), because libio does not check for include/g++-X
# $(PF)/include/$(cxx_inc_dir)/std, because libstdc++ doesn't check for g++-X/std
# $(PF)/include/$(cxx_inc_dir)/gen, because libg++ doesn't check for g++-X/gen

# Now that we use install -D again, none.
#	mkdir -p $(d)/$(PF) \
#		$(d)/$(PF)/share/doc \
#		$(d)/$(PF)/include/$(cxx_inc_dir)/{gen,std}
	mkdir -p $(d)/$(PF) \
		$(d)/$(PF)/share/{info,man} \
		$(d)/$(PF)/{bin,lib}
	: # Install everything
ifeq  ($(TARGET),native)
  ifneq ($(SNAPSHOT),yes)
	PATH=$(PWD)/$(builddir)/texinfo/util:`pwd`/bin:$$PATH \
	  $(MAKE) -C $(builddir) CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" \
	    BOOT_CFLAGS="$(BOOT_CFLAGS)" \
	    BISON=bison-1.35 \
	    INSTALL="$(IR) -D" \
	    INSTALL_PROGRAM="$(IP) -D" \
	    prefix=$(PWD)/$(d)/$(PF) \
	    infodir=$(PWD)/$(d)/$(PF)/share/info \
	    mandir=$(PWD)/$(d)/$(PF)/share/man \
	    cpp_install_dir=$(PWD)/$(d)/bin install

    ifeq ($(with_fortran),yes)
	PATH=$(PWD)/$(builddir)/texinfo/util:$$PATH \
	  $(MAKE) -C $(builddir)/$(DEB_HOST_GNU_TYPE)/libf2c-pic \
	    LIBG2C=libg2c-pic.a \
	    CFLAGS="$(CFLAGS) -fPIC -DPIC" LDFLAGS="$(LDFLAGS)" \
	    INSTALL="$(IR) -D" \
	    INSTALL_PROGRAM="$(IP) -D" \
	    prefix=$(PWD)/$(d)/$(PF) \
	    infodir=$(PWD)/$(d)/$(PF)/share/info \
	    mandir=$(PWD)/$(d)/$(PF)/share/man install
    endif
  else
	PATH=$(PWD)/$(builddir)/texinfo/util:`pwd`/bin:$$PATH \
	  $(MAKE) -C $(builddir) CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" \
	    BOOT_CFLAGS="$(BOOT_CFLAGS)" \
	    BISON=bison-1.35 \
	    INSTALL="$(IR) -D" \
	    INSTALL_PROGRAM="$(IP) -D" \
	    prefix=$(PWD)/$(d)/$(PF) \
	    infodir=$(PWD)/$(d)/$(PF)/share/info \
	    mandir=$(PWD)/$(d)/$(PF)/share/man install
  endif
else
	PATH=`pwd`/bin:$$PATH \
	  $(MAKE) -C $(builddir) LANGUAGES="c c++" \
	    BISON=bison-1.35 \
	    INSTALL="$(IR) -D" \
	    INSTALL_PROGRAM="$(IP) -D" \
	    prefix=$(PWD)/$(d)/$(PF) \
	    infodir=$(PWD)/$(d)/$(PF)/share/info \
	    mandir=$(PWD)/$(d)/$(PF)/share/man install
endif

	: # Adjust installation such that we can begin moving things around:
#	$(IS) debian/c89 $(d)/$(PF)/bin/
#	$(IR) debian/c89.1 $(d)/$(PF)/share/man/man1/
ifeq ($(VER),2.95.4)
	mv $(d)/$(PF)/share/man/man1/cccp.1 $(d)/$(PF)/share/man/man1/cpp.1
endif

	: # - Remove files, which are not part of any package
	rm -f $(d)/$(PF)/bin/$(DEB_HOST_GNU_TYPE)-gcc
	rm -f $(d)/$(PF)/bin/{c++,c++filt}
	rm -f $(d)/$(PF)/share/man/man1/c++.1
	rm -f $(d)/$(PF)/lib/libiberty.a
	rm -rf $(d)/$(PF)/$(DEB_HOST_GNU_TYPE)
#	rm -f $(d)/$(gcc_lib_dir)/include/{asm/posix_types.h,gnu/types.h}

	: # adjustments needed for the snapshot ...
	: # rm -f $(d)/$(PF)/bin/makeinfo

	: # install package directories
	dh_installdirs -p$(p_gcc)   $(dirs_gcc)
	dh_installdirs -p$(p_cpp)   $(dirs_cpp)
	dh_installdirs -p$(p_cppd)  $(dirs_cppd)
ifeq ($(with_objc),yes)
	dh_installdirs -p$(p_objc)  $(dirs_objc)
endif
ifeq ($(with_proto),yes)
	dh_installdirs -p$(p_proto) $(dirs_proto)
endif
ifeq ($(with_gplusplus),yes)
	dh_installdirs -p$(p_gpp)   $(dirs_gpp)
endif
ifeq ($(TARGET),native)
ifeq ($(with_fortran),yes)
	dh_installdirs -p$(p_g77)   $(dirs_g77)
	dh_installdirs -p$(p_g77d)  $(dirs_g77d)
endif
ifeq ($(with_chill),yes)
	dh_installdirs -p$(p_gch)   $(dirs_chill)
endif
ifeq ($(with_java),yes)
	dh_installdirs -p$(p_java)  $(dirs_java)
endif
ifeq ($(with_pascal),yes)
	dh_installdirs -p$(p_gpc)   $(dirs_gpc)
	dh_installdirs -p$(p_gpcd)  $(dirs_gpcd)
endif
endif
ifeq ($(with_gplusplus),yes)
	dh_installdirs -p$(p_lib)   $(dirs_lib)
	dh_installdirs -p$(p_dev)   $(dirs_dev)
	dh_installdirs -p$(p_dbg)   $(dirs_dbg)
endif
ifeq ($(with_libgpp),yes)
	dh_installdirs -p$(p_lgp)   $(dirs_lgp)
	dh_installdirs -p$(p_lgd)   $(dirs_lgd)
	dh_installdirs -p$(p_lgdbg) $(dirs_lgdbg)
endif
	dh_installdirs -p$(p_doc)   $(dirs_doc)
#ifeq ($(VER),2.95.4)
#	dh_installdirs -p$(p_docs)  $(docdir)
#endif
ifeq ($(DEB_HOST_ARCH),powerpc)
	dh_installdirs -p$(p_nof)   $(dirs_nof)
endif
ifeq ($(TARGET)-$(with_arm_soft_float),arm-yes)
	dh_installdirs -p$(p_softfloat) $(dirs_softfloat)
endif
ifeq ($(TARGET)-$(with_arm_soft_float),armeb-yes)
	dh_installdirs -p$(p_softfloat) $(dirs_softfloat)
endif

ifeq ($(TARGET),native)

# first-move-stamp: $(install_stamp)
	# rm -f $(install_stamp)
	: # - cpp installation
#ifneq ($(SNAPSHOT),yes)
#	-mkdir -p $(d)/lib
#	ln -sf /usr/bin/cpp $(d)/lib/cpp
#endif
#ifneq ($(SNAPSHOT),yes)
#	mv $(d)/$(PF)/bin/cpp $(d)/lib/cpp
#	dh_link /lib/cpp /$(PF)/bin/cpp
#endif
	$(IR) debian/gcov.1 $(d)/$(PF)/share/man/man1/
	: # - Adjust files for compiler
ifeq ($(with_proto),yes)
	$(IR) debian/protoize.1 $(d)/$(PF)/share/man/man1/
	ln -f $(d)/$(PF)/share/man/man1/protoize.1 \
	    $(d)/$(PF)/share/man/man1/unprotoize.1
endif
ifeq ($(with_pascal),yes)
	$(IR) debian/gpc-run.1 $(d)/$(PF)/share/man/man1/
endif
#ifeq ($(VER),2.95.4)
#	ln -sf gcc $(d)/$(PF)/bin/egcc
#	ln -sf gcc.1 $(d)/$(PF)/share/man/man1/egcc.1
#endif

ifeq ($(with_pascal),yes)
	: # adjust gpc
	mkdir -p $(d)/$(PF)/share/doc/$(p_gpc) || true
	mv $(d)/$(PF)/doc/gpc/demos $(d)/$(PF)/share/doc/$(p_gpc)/examples
	mv $(d)/$(PF)/doc/gpc/docdemos $(d)/$(PF)/share/doc/$(p_gpc)/
	rm -f $(d)/$(PF)/bin/pc $(d)/$(PF)/share/man/man1/pc.1
endif
ifeq ($(with_gplusplus),yes)
	: # - libstdc++ iostream info files
	$(IR) $(builddir)/$(LIBBUILDDIR)/libio/iostream*info* \
	  $(d)/$(PF)/share/info/
  ifeq ($(with_libgpp),yes)
	: # - libg++ info files and genclass man page
	$(IR) $(builddir)/$(LIBBUILDDIR)/libg++/libg++.info* \
	  $(d)/$(PF)/share/info/
	$(IR) debian/genclass.1 $(d)/$(PF)/share/man/man1/
  endif
endif

ifeq ($(versioned_packages),yes)
	: # rename files (versioned binaries)
	for i in cpp gcc gcov; do \
	  mv $(d)/$(PF)/bin/$$i $(d)/$(PF)/bin/$$i$(pkg_ver); \
	done
	: # rename files (versioned man pages)
	for i in cpp gcc gcov; do \
	  mv $(d)/$(PF)/share/man/man1/$$i.1 \
		$(d)/$(PF)/share/man/man1/$$i$(pkg_ver).1; \
	done
  ifeq ($(with_gplusplus),yes)
	: # rename files (versioned binaries)
	for i in g++; do \
	  mv $(d)/$(PF)/bin/$$i $(d)/$(PF)/bin/$$i$(pkg_ver); \
	done
	: # rename files (versioned man pages)
	for i in g++; do \
	  mv $(d)/$(PF)/share/man/man1/$$i.1 \
		$(d)/$(PF)/share/man/man1/$$i$(pkg_ver).1; \
	done
  endif
  ifeq ($(with_pascal),yes)
	: # rename files (versioned pascal binaries)
	for i in binobj gpc gpc-run gpidump; do \
	  mv $(d)/$(PF)/bin/$$i $(d)/$(PF)/bin/$$i$(pkg_ver); \
	done
	: # rename files (versioned pascal man pages)
	for i in binobj gpc gpc-run gpidump; do \
	  mv $(d)/$(PF)/share/man/man1/$$i.1 \
		$(d)/$(PF)/share/man/man1/$$i$(pkg_ver).1; \
	done
  endif
  ifeq ($(with_chill),yes)
	: # rename files (versioned chill binaries)
	for i in chill; do \
	  mv $(d)/$(PF)/bin/$$i $(d)/$(PF)/bin/$$i$(pkg_ver); \
	done
	for i in chill; do \
	  ln -sf $(d)/$(PF)/bin/$$i$(pkg_ver) $(d)/$(PF)/bin/$$i; \
	done
  endif
  ifeq ($(with_proto),yes)
	: # rename files (versioned protoize binaries)
	for i in protoize unprotoize; do \
	  mv $(d)/$(PF)/bin/$$i $(d)/$(PF)/bin/$$i$(pkg_ver); \
	done
	: # rename files (versioned protoize man pages)
	for i in protoize unprotoize; do \
	  mv $(d)/$(PF)/share/man/man1/$$i.1 \
		$(d)/$(PF)/share/man/man1/$$i$(pkg_ver).1; \
	done
  endif
  ifeq ($(with_fortran),yes)
	: # rename files (versioned g77 binaries)
	for i in g77; do \
	  mv $(d)/$(PF)/bin/$$i $(d)/$(PF)/bin/$$i$(pkg_ver); \
	done
	: # rename files (versioned g77 man pages)
	for i in g77; do \
	  mv $(d)/$(PF)/share/man/man1/$$i.1 \
		$(d)/$(PF)/share/man/man1/$$i$(pkg_ver).1; \
	done
  endif
  ifeq ($(with_java),yes)
	: # rename files (versioned java binaries)
	for i in gcj gcjh jv-scan jcf-dump; do \
	  mv $(d)/$(PF)/bin/$$i $(d)/$(PF)/bin/$$i$(pkg_ver); \
	done
  endif
endif

	: # Move files to subpackages.
	dh_movefiles -p$(p_doc) $(files_doc)
ifeq ($(DEB_HOST_ARCH),powerpc)
	dh_movefiles -p$(p_nof) $(files_nof)
  ifeq ($(with_gplusplus),yes)
    ifeq ($(CXX_IF),1.1)
	ln -s libstdc++$(LIBC_IF)$(CXX_IF).so.$(LIBSTDCXX_IF) \
	  $(d_lib)/$(PF)/lib/libstdc++$(LIBC_IF)1.so.$(LIBSTDCXX_IF)
	ln -s libstdc++$(LIBC_IF)$(CXX_IF).so.$(LIBSTDCXX_IF) \
	  $(d_nof)/$(PF)/lib/libstdc++$(LIBC_IF)1.so.$(LIBSTDCXX_IF)
      ifeq ($(with_libgpp),yes)
	ln -s libg++$(LIBC_IF)$(CXX_IF).so.$(LIBSTDCXX_IF) \
	  $(d_lgp)/$(PF)/lib/libg++$(LIBC_IF)1.so.$(LIBSTDCXX_IF)
	ln -s libg++$(LIBC_IF)$(CXX_IF).so.$(LIBSTDCXX_IF) \
	  $(d_nof)/$(PF)/lib/libg++$(LIBC_IF)1.so.$(LIBSTDCXX_IF)
      endif
    endif
  endif
endif
ifeq ($(TARGET)-$(with_arm_soft_float),arm-yes)
	dh_movefiles -p$(p_softfloat) $(files_softfloat)
endif
ifeq ($(TARGET)-$(with_arm_soft_float),armeb-yes)
	dh_movefiles -p$(p_softfloat) $(files_softfloat)
endif
	dh_movefiles -p$(p_cpp)   $(files_cpp)
	dh_movefiles -p$(p_cppd)  $(files_cppd)
ifeq ($(with_objc),yes)
	dh_movefiles -p$(p_objc)  $(files_objc)
endif
ifeq ($(with_proto),yes)
	dh_movefiles -p$(p_proto) $(files_proto)
endif
ifeq ($(with_fortran),yes)
	dh_movefiles -p$(p_g77)   $(files_g77)
	dh_movefiles -p$(p_g77d)  $(files_g77d)
endif
ifeq ($(with_chill),yes)
	dh_movefiles -p$(p_gch)   $(files_chill)
endif
ifeq ($(with_java),yes)
	dh_movefiles -p$(p_java)  $(files_java)
endif
ifeq ($(with_libgpp),yes)
# libg++-dev must be moved before libstdc++-dev !!!
	dh_movefiles -p$(p_lgd)   $(files_lgd)
	dh_movefiles -p$(p_lgdbg) $(files_lgdbg)
	dh_movefiles -p$(p_lgp)   $(files_lgp)
# Copy the libraries in libg++ to libg++-dbg
	(cd debian/$(p_lgp)/$(PF)/lib/$(lgp) ; tar cfp - .) | \
		(cd debian/$(p_lgdbg)/$(PF)/lib/debug ; tar xvfp -)
endif
ifeq ($(with_gplusplus),yes)
	dh_movefiles -p$(p_dev)  $(files_dev)
	dh_movefiles -p$(p_dbg)  $(files_dbg)
	dh_movefiles -p$(p_lib)  $(files_lib)
# Copy the libraries in libstdc++ to libstdc++-dbg
	(cd debian/$(p_lib)/$(PF)/lib/$(lib) ; tar cfp - .) | \
		(cd debian/$(p_dbg)/$(PF)/lib/debug ; tar xvfp -)
endif
ifeq ($(with_pascal),yes)
	dh_movefiles -p$(p_gpc) $(files_gpc)
	dh_movefiles -p$(p_gpcd) $(files_gpcd)
endif
ifeq ($(with_gplusplus),yes)
	dh_movefiles -p$(p_gpp) $(files_gpp)
endif
# gcc must be moved after g77 and g++
ifeq ($(DEB_HOST_GNU_TYPE),sparc-linux-no)
	: # compile the wrapper
	$(CC) $(CFLAGS) -o $(d)/usr/bin/sparc64-linux-gcc-wrapper \
		debian/sparc64-linux-gcc-wrapper.c
endif
else # NOT NATIVE
ifeq ($(versioned_packages),yes)
	: # rename files (versioned binaries)
	for i in g++; do \
	  mv $(d)/$(PF)/bin/$(TARGET)-linux-$$i $(d)/$(PF)/bin/$(TARGET)-linux-$$i$(pkg_ver); \
	done
endif

	dh_movefiles -p$(p_cpp) $(files_cpp)
ifeq ($(with_gplusplus),yes)
	dh_movefiles -p$(p_dev) $(files_dev)
	dh_movefiles -p$(p_dbg) $(files_dbg)
	dh_movefiles -p$(p_lib) $(files_lib)
	dh_movefiles -p$(p_gpp) $(files_gpp)
endif
endif # NATIVE
	dh_movefiles -p$(p_gcc) $(files_gcc)

	touch $(install_stamp)-$*
#	touch first-move-stamp

usr_doc_files = debian/{README.Debian,README.Bugs} \
	$(shell test -f $(srcdir)/FAQ && echo $(srcdir)/FAQ)
ifneq ($(SNAPSHOT),no)
  usr_doc_files += debian/README.snapshot
endif
ifeq ($(with_check),yes)
  usr_doc_files += test-summary
endif
ifeq ($(DEB_HOST_ARCH),sparc)
  usr_doc_files += debian/README.sparc
endif

ifeq ($(DEB_HOST_ARCH),powerpc)
  ifeq ($(CXX_IF),1.1)
    libstdc_eh_ver := $(empty_random_variable) (>= 2.91.63)
  endif
endif

# ----------------------------------------------------------------------
# Build architecture-dependent files here.
# binary-arch: build install
$(binary_stamp)-arch-%:
	dh_testdir
	dh_testroot

	rm -f debian/tmp
	ln -sf tmp-$(TARGET) debian/tmp

	: # Install documentation and changelogs
ifeq ($(TARGET),native)
  ifeq ($(with_objc),yes)
	dh_installchangelogs -a -N$(p_objc) -N$(p_proto) -N$(p_dev) \
		-N$(p_lgd) -N$(p_dbg) -N$(p_lgdbg)
	dh_installdocs -a -A -N$(p_objc) -N$(p_proto) -N$(p_dev) -N$(p_lgd) \
		-N$(p_dbg) -N$(p_lgdbg) $(usr_doc_files)
  else
	dh_installchangelogs -a -N$(p_proto) -N$(p_dev) \
		-N$(p_lgd) -N$(p_dbg) -N$(p_lgdbg)
	dh_installdocs -a -A -N$(p_proto) -N$(p_dev) -N$(p_lgd) \
		-N$(p_dbg) -N$(p_lgdbg) $(usr_doc_files)
  endif
else
	dh_installchangelogs -a -N$(p_proto) -N$(p_dev) \
		-N$(p_lgd) -N$(p_dbg) -N$(p_lgdbg) $(NOT_PACKAGES)
	dh_installdocs -a -A -N$(p_proto) -N$(p_dev) -N$(p_lgd) \
		-N$(p_dbg) -N$(p_lgdbg) $(NOT_PACKAGES) $(usr_doc_files)
endif
	dh_installdocs -p$(p_gcc) $(srcdir)/gcc/BUGS debian/README.cross
	cp -p debian/NEWS.gcc $(d_gcc)/$(docdir)/$(p_gcc)/NEWS
ifeq ($(TARGET),native)
  ifeq ($(with_objc),yes)
	ln -sf $(p_gcc) $(d_objc)/$(docdir)/$(p_objc)
  endif
  ifeq ($(with_proto),yes)
	ln -sf $(p_gcc) $(d_proto)/$(docdir)/$(p_proto)
  endif
  ifeq ($(with_fortran),yes)
	dh_installdocs -p$(p_g77) $(srcdir)/gcc/f/{NEWS,BUGS}
	$(IR) $(srcdir)/libf2c/README $(d_g77)/$(docdir)/$(p_g77)/README.libf2c
  endif
  ifeq ($(with_gplusplus),yes)
	dh_installdocs -p$(p_gpp) $(srcdir)/gcc/{cp/NEWS,BUGS} debian/README.C++
	$(IR) $(srcdir)/libio/NEWS $(d_dev)/$(docdir)/$(p_lib)/NEWS.libio
	$(IR) $(srcdir)/libstdc++/NEWS debian/README.C++ \
	    $(d_dev)/$(docdir)/$(p_lib)/
	ln -sf $(p_lib) $(d_dev)/$(docdir)/$(p_dev)
	ln -sf $(p_lib) $(d_dbg)/$(docdir)/$(p_dbg)
  endif
ifeq ($(with_libgpp),yes)
	$(IR) $(srcdir)/libg++/NEWS $(d_lgd)/$(docdir)/$(p_lgp)/
	ln -sf $(p_lgp) $(d_lgd)/$(docdir)/$(p_lgd)
	ln -sf $(p_lgp) $(d_lgdbg)/$(docdir)/$(p_lgdbg)
endif
ifeq ($(with_pascal),yes)
	dh_installdocs -p$(p_gpc) $(srcdir)/gcc/p/{AUTHORS,README,NEWS}
	$(IR) $(srcdir)/gcc/p/FAQ $(d_gpc)/$(docdir)/$(p_gpc)/FAQ.gpc
#	$(IR) $(srcdir)/gcc/p/BUGS $(d_gpc)/$(docdir)/$(p_gpc)/BUGS.gpc
	$(IR) $(srcdir)/gcc/p/test/README \
		$(d_gpc)/$(docdir)/$(p_gpc)/README.gpc-test
	if [ -f gpc-test-summary ]; then \
	  rm -f $(d_gpc)/$(docdir)/$(p_gpc)/test-summary; \
	  $(IR) gpc-test-summary $(d_gpc)/$(docdir)/$(p_gpc)/; \
	fi
endif
ifeq ($(with_java),yes)
	dh_installdocs -p$(p_java) debian/README.java
endif
ifeq ($(with_chill),yes)
	dh_installdocs -p$(p_gch) $(srcdir)/gcc/ch/README
endif
	: # Install man pages and undocumented links
#	dh_installmanpages -a $(NOT_PACKAGES)
ifeq ($(with_java),yes)
  ifeq ($(versioned_packages),yes)
	dh_undocumented -p$(p_java) {gcj,gcjh,jv-scan,jcf-dump}$(pkg_ver).1
  else
	dh_undocumented -p$(p_java) {gcj,gcjh,jv-scan,jcf-dump}.1
  endif
endif
ifeq ($(with_chill),yes)
  ifeq ($(versioned_packages),yes)
	dh_undocumented -p$(p_gch) chill$(pkg_ver).1
	dh_undocumented -p$(p_gch) chill.1
  else
	dh_undocumented -p$(p_gch) chill.1
  endif
endif

	: # remove empty directories, when all components are in place
	for d in `find debian -depth -type d -empty 2> /dev/null`; do \
	  while rmdir $$d 2> /dev/null; do d=`dirname $$d`; done; \
	done
endif # NATIVE

	: # strip executables and libraries
	dh_strip -a -Xdebug $(NOT_PACKAGES)

	: # in the snapshot package the man pages aren't compressed by default.
	dh_compress -a $(NOT_PACKAGES)
ifeq ($(TARGET),native)
ifeq ($(with_libgpp),yes)
	: # link libg++ doc files to libstdc++ doc files
	for i in $(usr_doc_files); do \
	  b=`basename $$i`; \
	  if [ -e $(d_lib)/$(docdir)/$(p_lib)/$$b ]; then \
	    ln -sf ../$(p_lib)/$$b $(d_lgp)/$(docdir)/$(p_lgp)/$$b; \
	  else \
	    ln -sf ../$(p_lib)/$$b.gz $(d_lgp)/$(docdir)/$(p_lgp)/$$b.gz; \
	  fi; \
	done
endif
endif # NATIVE
	dh_fixperms -a $(NOT_PACKAGES)

# when dh_installdeb is called from the snapshot package, the postinst/prerm
# packages are intentionally not called:
# - we don't want to call update-info for the snapshot ...
# - gcc-ss doesn't provide an alternative for cc
# - libstdc++ and libg++ don't call ldconfig, user should set LD_LIBRARY_PATH
#	dh_makeshlibs -a
ifneq ($(SNAPSHOT),yes)
  ifeq ($(with_gplusplus),yes)
    ifeq ($(DEB_HOST_GNU_SYSTEM),linux-gnu)
      ifeq ($(DEB_HOST_ARCH),powerpc)
	echo "libstdc++$(LIBC_IF)$(CXX_IF) $(LIBSTDCXX_IF) libstdc++$(PKG_SONAME)$(libstdc_eh_ver) (>= $(lib_pkg_req_version))" \
		> debian/$(p_lib).shlibs
      else
	echo "libstdc++$(LIBC_IF)$(CXX_IF) $(LIBSTDCXX_IF) libstdc++$(PKG_SONAME) (>= $(lib_pkg_req_version))" \
		> debian/$(p_lib).shlibs
      endif
    else
	echo "libstdc++ $(lib_version) libstdc++$(PKG_SONAME) (>= $(lib_pkg_req_version))" > debian/$(p_lib).shlibs
    endif
  endif
  ifeq ($(with_libgpp),yes)
	echo "libg++$(LIBC_IF)$(CXX_IF) $(LIBSTDCXX_IF) libg++$(LGP_PKG_SONAME)" \
		> debian/$(p_lgp).shlibs
  endif
endif

ifeq ($(with_libgpp),yes)
	b=libg++; \
	for ext in preinst postinst prerm postrm; do \
	  for t in '' -dev -dbg; do \
	    if [ -z "$$t" ]; then v=$(LGP_PKG_SONAME); else v=$(LGP_PKG_DEV_SONAME); fi; \
	    if [ -f debian/$$b$$t.$$ext ]; then \
	      cp -pf debian/$$b$$t.$$ext debian/$$b$$v$$t$(TS).$$ext; \
	    fi; \
	  done; \
	done
	mkdir -p $(d_lgdbg)/usr/share/lintian/overrides || true
	cp -p debian/libg++-dbg.overrides \
		$(d_lgdbg)/usr/share/lintian/overrides/$(p_lgdbg)
endif
ifeq ($(with_gplusplus),yes)
	b=libstdc++; \
	for ext in preinst postinst prerm postrm; do \
	  for t in '' -dev -dbg; do \
	    if [ -z "$$t" ]; then v=$(PKG_SONAME); else v=$(PKG_DEV_SONAME); fi; \
	    if [ -f debian/$$b$$t.$$ext ]; then \
	      cp -pf debian/$$b$$t.$$ext debian/$$b$$v$$t$(TS).$$ext; \
	    fi; \
	  done; \
	done
	mkdir -p $(d_dbg)/usr/share/lintian/overrides || true
	cp -p debian/libstdc++-dbg.overrides \
		$(d_dbg)/usr/share/lintian/overrides/$(p_dbg)
endif

#	: # help out debhelper ;-)
#ifeq ($(with_objc),yes)
#	for p in $(p_dev) $(p_dbg) $(p_lgd) $(p_lgdbg) $(p_objc); do \
#	  echo 'if [ "$$1" = "configure" ];'" then if [ -d /usr/doc -a ! -e /usr/doc/$$p -a -d /usr/share/doc/$$p ]; then ln -sf ../share/doc/$$p /usr/doc/$$p; fi; fi" >> debian/$$p.postinst.debhelper; \
#	  echo 'if [ \( "$$1" = "upgrade" -o "$$1" = "remove" \)'" -a -L /usr/doc/$$p ]; then rm -f /usr/doc/$$p; fi" >> debian/$$p.prerm.debhelper; \
#	done
#else
#	for p in $(p_dev) $(p_dbg) $(p_lgd) $(p_lgdbg); do \
#	  echo 'if [ "$$1" = "configure" ];'" then if [ -d /usr/doc -a ! -e /usr/doc/$$p -a -d /usr/share/doc/$$p ]; then ln -sf ../share/doc/$$p /usr/doc/$$p; fi; fi" >> debian/$$p.postinst.debhelper; \
#	  echo 'if [ \( "$$1" = "upgrade" -o "$$1" = "remove" \)'" -a -L /usr/doc/$$p ]; then rm -f /usr/doc/$$p; fi" >> debian/$$p.prerm.debhelper; \
#	done
#endif

# alternatives are disabled
#ifeq ($(versioned_packages),yes)
#	pv=`echo $(pkg_ver) | tr -d .`; \
#	echo "pkg_ver=$$pv" >> debian/postinst.debhelper; \
#	echo "pkg_ver=$$pv" >> debian/prerm.debhelper; \
#	for p in $(p_cpp) $(p_gpp) $(p_g77) $(p_proto) $(p_gpc) \
#		$(p_gch) $(p_java) $(p_dev); \
#	do \
#	  echo "pkg_ver=$$pv" >> debian/$$p.postinst.debhelper; \
#	  echo "pkg_ver=$$pv" >> debian/$$p.prerm.debhelper; \
#	done
#endif

ifeq ($(TARGET),native)
  ifeq ($(with_gplusplus),yes)
	: # dh_shlibdeps ... I hope I got it correct now ...
	: # we don't want the dep. on libstdc++, it's hardwired in control
    ifeq ($(DEB_HOST_GNU_SYSTEM),linux-gnu)
	echo "libstdc++$(LIBC_IF)$(CXX_IF) $(LIBSTDCXX_IF) $(p_lib) (>= $(lib_pkg_req_version))" \
		> debian/shlibs.local
    else
	echo "libstdc++ $(lib_version) $(p_lib) (>= $(lib_pkg_req_version))" > debian/shlibs.local
    endif
  endif
#	LD_LIBRARY_PATH=$(d_lib)/usr/lib dh_shlibdeps -a $(NOT_PACKAGES)
	dh_shlibdeps -l:$(d_lib)/usr/lib: -a $(NOT_PACKAGES)
else
	: Oh what a 'orrible 'ack
	for p in $(MY_CROSS_PACKAGES); do \
	    cp debian/cpp-2.95.substvars debian/$$p.substvars; \
	done
endif
ifneq ($(SNAPSHOT),yes)
	dh_installdeb -a $(NOT_PACKAGES)
endif
	dh_gencontrol -a -u-v1:$(DPKGVER) $(NOT_PACKAGES)
	for p in `dh_listpackages -a $(NOT_PACKAGES)`; do \
	  if grep -H '^Architecture' debian/$$p/DEBIAN/control; then \
	    : ; \
	  else \
	    echo "Missing architecture line: $$p"; \
	    s=error; \
	  fi; \
	done; \
	if [ "$$s" = error ]; then \
	  echo "dpkg-gencontrol generated control file without 'Architecture:' line"; \
	  echo "This error should not appear when building with dpkg-dev-1.8.x"; \
	  exit 1; \
	fi
	dh_md5sums -a $(NOT_PACKAGES)
	dh_builddeb -a $(NOT_PACKAGES)
ifeq ($(with_check),yes)
	: # Send Email about sucessfull build.
	# cat raw-test-summary | sh; echo "Sent mail to $(S_EMAIL)"
endif
	touch $(binary_stamp)-arch-$*

# ----------------------------------------------------------------------
# Build architecture-independent files here.
# binary-indep: build install
$(binary_stamp)-indep-%:
ifeq ($(TARGET),native)
	dh_testdir
	dh_testroot

	rm -f debian/tmp
	ln -sf tmp-$(TARGET) debian/tmp

#ifeq ($(VER),2.95.4)
#	dh_installdocs -i -N$(p_docs) $(NOT_PACKAGES)
#	dh_installchangelogs -i -N$(p_docs) $(NOT_PACKAGES)
#	ln -sf $(p_doc) $(d_docs)/$(docdir)/$(p_docs)
#else
	dh_installdocs -i $(NOT_PACKAGES)
	dh_installchangelogs -i $(NOT_PACKAGES)
#endif

#	dh_installexamples -i $(NOT_PACKAGES)
#	dh_installmenu -i $(NOT_PACKAGES)
#       dh_installinit -i $(NOT_PACKAGES)
#	dh_installcron -i $(NOT_PACKAGES)
#       dh_installmanpages -i $(NOT_PACKAGES)
#       dh_undocumented

	: # remove empty directories, when all components are in place
ifeq ($(with_pascal),yes)
	for d in `find $(d_doc) $(d_g77d) $(d_gpcd) \
		-depth -type d -empty 2> /dev/null`; do \
	  while rmdir $$d 2> /dev/null; do d=`dirname $$d`; done; \
	done
else
	for d in `find $(d_doc) $(d_g77d) \
		-depth -type d -empty 2> /dev/null`; do \
	  while rmdir $$d 2> /dev/null; do d=`dirname $$d`; done; \
	done
endif

	dh_compress -i $(NOT_PACKAGES) -X.pas
	dh_fixperms -i $(NOT_PACKAGES)
#	dh_suidregister -i $(NOT_PACKAGES)
ifneq ($(SNAPSHOT),yes)
	dh_installdeb -i $(NOT_PACKAGES)
endif
	dh_gencontrol -i -u-v1:$(DPKGVER) $(NOT_PACKAGES)
	dh_md5sums -i $(NOT_PACKAGES)
	dh_builddeb -i $(NOT_PACKAGES)
endif # NATIVE
	touch $(binary_stamp)-indep-$*


source diff:
	@echo >&2 'source and diff are obsolete - use dpkg-source -b'; false

binary: binary-indep binary-arch

-include debian/rules2.hack

ifeq ($(binary_hack),arch)
$(binary_stamp)-%: $(binary_stamp)-arch-%
	touch $(binary_stamp)-$*
else
ifeq ($(binary_hack),indep)
$(binary_stamp)-%: $(binary_stamp)-indep-%
	touch $(binary_stamp)-$*
else
$(binary_stamp)-%: $(binary_stamp)-indep-% $(binary_stamp)-arch-%
	touch $(binary_stamp)-$*
endif
endif

.PHONY: build clean binary-indep binary-arch binary
