#/*! \page config_macros Default configuration: /usr/lib/debbuild/macros
# \verbatim
#
# This is a global DEBBUILD configuration file. All changes made here will be
# lost when the debbuild package is upgraded. Any per-system configuration
# should be added to /etc/debbuild/macros, while per-user configuration should
# be added to ~/.debmacros.
#
#==============================================================================
# ---- A macro that expands to nothing.
#
%nil			%{!?nil}

#==============================================================================
# ---- filesystem macros.
#
%_usr			/usr
%_var			/var

#==============================================================================
# ---- Generally useful path macros.
#
%__bzip2		/bin/bzip2
%__cat			/bin/cat
%__chgrp		/bin/chgrp
%__chmod		/bin/chmod
%__chown		/bin/chown
%__cp			/bin/cp
%__debsigs		/usr/bin/debsigs
%__dpkg			/usr/bin/dpkg
%__dpkg_architecture	/usr/bin/dpkg-architecture
%__dpkg_deb		/usr/bin/dpkg-deb
%__dpkg_query		/usr/bin/dpkg-query
%__dpkg_sig		/usr/bin/dpkg-sig
%__du			/usr/bin/du
%__echo			/bin/echo
%__fakeroot		/usr/bin/fakeroot
%__find			/usr/bin/find
%__gem			/usr/bin/gem
%__gpg			/usr/bin/gpg2
%__gzip			/bin/gzip
%__id			/usr/bin/id
%__id_u			/usr/bin/id -u
%__install		/usr/bin/install
%__ldd			/usr/bin/ldd
%__ln_s			/bin/ln -s
%__lsb_release		/usr/bin/lsb_release
%__make			/usr/bin/make
%__mkdir		/bin/mkdir
%__mkdir_p		/bin/mkdir -p
%__mv			/bin/mv
%__patch		/usr/bin/patch
%__pax			/bin/pax
%__perl			/usr/bin/perl
%__rm			/bin/rm
%__rpm			/usr/bin/rpm
%__sed			/bin/sed
%__sed_i		/bin/sed -i
%__tar			/bin/tar
%__test			/usr/bin/test
%__unzip		/usr/bin/unzip
%__xargs		/usr/bin/xargs
%__xz			/usr/bin/xz
%__zstd			/usr/bin/zstd

#==============================================================================
# Conditional build stuff.
#
# Check if symbol is defined.
# Example usage: %if %{defined with_foo} && %{undefined with_bar} ...
%defined()	%{expand:%%{?%{1}:1}%%{!?%{1}:0}}
%undefined()	%{expand:%%{?%{1}:0}%%{!?%{1}:1}}

# Shorthand for %{defined with_...}
%with()		%{expand:%%{?with_%{1}:1}%%{!?with_%{1}:0}}
%without()	%{expand:%%{?with_%{1}:0}%%{!?with_%{1}:1}}

# Handle conditional builds. %bcond_with is for case when feature is
# default off and needs to be activated with --with ... command line
# switch. %bcond_without is for the dual case.
#
# %bcond_with foo defines symbol with_foo if --with foo was specified on
# command line.
# %bcond_without foo defines symbol with_foo if --without foo was *not*
# specified on command line.
#
# For example (spec file):
#
# (at the beginning)
# %bcond_with extra_fonts
# %bcond_without static
# (and later)
# %if %{with extra_fonts}
# ...
# %else
# ...
# %endif
# %if ! %{with static}
# ...
# %endif
# %{?with_static: ... }
# %{!?with_static: ... }
# %{?with_extra_fonts: ... }
# %{!?with_extra_fonts: ... }
#
# The bottom line: never use without_foo, _with_foo nor _without_foo, only
# with_foo. This way changing default set of bconds for given spec is just
# a matter of changing single line in it and syntax is more readable.
%bcond_with()		%{expand:%%{?_with_%{1}:%%global with_%{1} 1}}
%bcond_without()	%{expand:%%{!?_without_%{1}:%%global with_%{1} 1}}

#==============================================================================
# ---- Required rpmrc macros.
#	Macros that used to be initialized as a side effect of rpmrc parsing.
#	These are the default values that can be overridden by other
#	(e.g. per-platform, per-system, per-packager, per-package) macros.
#
#	The directory where debbuild's configuration and scripts live
%_debconfigdir		%{getconfdir}

#       The directory where debbuild's macro files live
%_debmacrodir		%{_debconfigdir}/macros.d

#	The directory where sources/patches will be unpacked and built.
%_builddir		%{_topdir}/BUILD

#	The directory where newly built binary packages will be written.
%_debdir		%{_topdir}/DEBS

#	The directory where sources/patches from a source package will be
#	installed. This is also where sources/patches are found when building.
%_sourcedir		%{_topdir}/SOURCES

#	The directory where the spec file from a source package will be
#	installed.
%_specdir		%{_topdir}/SPECS

#	The directory where newly built source packages will be written.
%_srcdebdir		%{_topdir}/SDEBS

#	The directory where buildroots will be created.
%_buildrootdir		%{_topdir}/BUILDROOT

#	Build root path, where %install installs the package during build.
%buildroot		%{_buildrootdir}/%{name}-%{version}-%{release}.%{_arch}

#	Directory where temporaray files can be created.
%_tmppath		%{_var}/tmp

#	Path to top of build area.
%_topdir		%{getenv:HOME}/debbuild

#==============================================================================
# ---- Optional rpmrc macros.
#	Macros that are initialized as a side effect of rpmrc and/or spec
#	file parsing.
#
#	The sub-directory (relative to %{_builddir}) where sources are compiled.
#	This macro is set after processing %setup, either explicitly from the
#	value given to -n or the default name-version.
#
%buildsubdir %{name}-%{version}

#	Default fuzz level for %patch in spec file.
%_default_patch_fuzz	0

#	Default patch flags
%_default_patch_flags	--no-backup-if-mismatch

#==============================================================================
# ---- GPG/PGP/PGP5 signature macros.
#	Macro(s) to hold the arguments passed to GPG/PGP for package
#	signing and verification.
#
%__gpg_sign_cmd		%{__gpg} \
  --keyserver %{_hkp_keyserver} --no-default-keyring --keyring \
  %{buildroot}%{_keyringpath}/%{_gpg_key_full}/debsig.gpg \
  --recv-keys %{_gpg_key_short}

# Horowitz Key Protocol server configuration
#
%_hkp_keyserver		http://pgp.mit.edu

%_keyringpath		%{_datadir}/debsig/keyrings
%_policiespath		%{_sysconfdir}/debsig/policies

#==============================================================================
# ---- Scriptlet template templates.
#	Global defaults used for building scriptlet templates.
#
%___build_shell		%{?_buildshell:%{_buildshell}}%{!?_buildshell:/bin/sh}
%___build_args		-e
%___build_cmd		%{?_sudo:%{_sudo} }%{?_remsh:%{_remsh} %{_remhost} }%{?_remsudo:%{_remsudo} }%{?_remchroot:%{_remchroot} %{_remroot} }%{___build_shell} %{___build_args}
%___build_pre	\
  RPM_SOURCE_DIR=\"%{u2p:%{_sourcedir}}\"\
  RPM_BUILD_DIR=\"%{u2p:%{_builddir}}\"\
  RPM_OPT_FLAGS=\"%{optflags}\"\
  RPM_ARCH=\"%{_arch}\"\
  RPM_OS=\"%{_os}\"\
  export RPM_SOURCE_DIR RPM_BUILD_DIR RPM_OPT_FLAGS RPM_ARCH RPM_OS\
  RPM_DOC_DIR=\"%{_docdir}\"\
  export RPM_DOC_DIR\
  RPM_PACKAGE_NAME=\"%{name}\"\
  RPM_PACKAGE_VERSION=\"%{version}\"\
  RPM_PACKAGE_RELEASE=\"%{release}\"\
  export RPM_PACKAGE_NAME RPM_PACKAGE_VERSION RPM_PACKAGE_RELEASE\
  LANG=C\
  export LANG\
  unset CDPATH DISPLAY ||:\
  RPM_BUILD_ROOT=\"%{u2p:%{buildroot}}\"\
  export RPM_BUILD_ROOT\
  \
  %{verbose:set -x}%{!verbose:exec > /dev/null}\
  umask 022\
  cd \"$RPM_BUILD_DIR\"\

%___build_body		%{nil}
%___build_post		exit $?

%___build_template	#!%{___build_shell}\
%{___build_pre}\
%{___build_body}\
%{___build_post}\
%{nil}

#==============================================================================
# ---- configure macros.
#	Macro(s) slavishly copied from autoconf's config.status.
#
%_prefix		%{_usr}
%_exec_prefix		%{_prefix}
%_bindir		%{_exec_prefix}/bin
%_sbindir		%{_exec_prefix}/sbin
%_libexecdir		%{_exec_prefix}/libexec
%_datadir		%{_prefix}/share
%_docdir		%{_datadir}/doc
%_sysconfdir		/etc
%_sharedstatedir	%{_prefix}/com
%_localstatedir		%{_prefix}/var
%_lib			lib
%_libdir		%{_exec_prefix}/%{_lib}
%_includedir		%{_prefix}/include
%_infodir		%{_datadir}/info
%_mandir		%{_datadir}/man

#==============================================================================
# ---- config.guess platform macros.
#	Macro(s) similar to the tokens used by configure.
#
%_build			%{_host}
%_build_alias		%{_host_alias}
%_build_cpu		%{_host_cpu}
%_build_vendor		%{_host_vendor}
%_build_os		%{_host_os}
%_host			%(%{__dpkg_architecture} -qDEB_HOST_GNU_TYPE)
%_host_alias		%{nil}
%_host_cpu		%(%{__dpkg_architecture} -qDEB_HOST_GNU_CPU)
%_host_vendor		pc
%_host_os		%(%{__dpkg_architecture} -qDEB_HOST_ARCH_OS)
%_target		%{_host}
%_target_alias		%{_host_alias}
%_target_cpu		%{_host_cpu}
%_target_vendor		%{_host_vendor}
%_target_os		%{_host_os}

#==============================================================================
# ---- compiler flags.

# C compiler flags.  This is traditionally called CFLAGS in makefiles.
# Historically also available as %%{optflags}, and %%build sets the
# environment variable RPM_OPT_FLAGS to this value.
%build_cflags %{optflags}

# C++ compiler flags.  This is traditionally called CXXFLAGS in makefiles.
%build_cxxflags %{optflags}

# Fortran compiler flags.  Makefiles use both FFLAGS and FCFLAGS as
# the corresponding variable names.
%build_fflags %{optflags} %{?_fmoddir:-I%{_fmoddir}}

# Link editor flags.  This is usually called LDFLAGS in makefiles.
#%build_ldflags -Wl,-z,relro

# Expands to shell code to seot the compiler/linker environment
# variables CFLAGS, CXXFLAGS, FFLAGS, FCFLAGS, LDFLAGS if they have
# not been set already.
%set_build_flags \
  CFLAGS="${CFLAGS:-%{?build_cflags}}" ; export CFLAGS ; \
  CXXFLAGS="${CXXFLAGS:-%{?build_cxxflags}}" ; export CXXFLAGS ; \
  FFLAGS="${FFLAGS:-%{?build_fflags}}" ; export FFLAGS ; \
  FCFLAGS="${FCFLAGS:-%{?build_fflags}}" ; export FCFLAGS ; \
  LDFLAGS="${LDFLAGS:-%{?build_ldflags}}" ; export LDFLAGS

#==============================================================================
# ---- specfile macros.
#	Macro(s) here can be used reliably for reproducible builds.
#	(Note: Above is the goal, below are the macros under development)
#
# The configure macro runs autoconf configure script with platform specific
# directory structure (--prefix, --libdir etc) and compiler flags
# such as CFLAGS.
#
%_configure ./configure
%configure \
  %{set_build_flags}; \
  %{_configure} --host=%{_host} --build=%{_build} \\\
	--program-prefix=%{?_program_prefix} \\\
	--disable-dependency-tracking \\\
	--prefix=%{_prefix} \\\
	--exec-prefix=%{_exec_prefix} \\\
	--bindir=%{_bindir} \\\
	--sbindir=%{_sbindir} \\\
	--sysconfdir=%{_sysconfdir} \\\
	--datadir=%{_datadir} \\\
	--includedir=%{_includedir} \\\
	--libdir=%{_libdir} \\\
	--libexecdir=%{_libexecdir} \\\
	--localstatedir=%{_localstatedir} \\\
	--sharedstatedir=%{_sharedstatedir} \\\
	--mandir=%{_mandir} \\\
	--infodir=%{_infodir}

#------------------------------------------------------------------------------
# Tested features of make
# Output synchronization for parallel make:
%_make_output_sync %(! %{__make} --version -O >/dev/null 2>&1 || echo -O)

#------------------------------------------------------------------------------
# Verbosity options passed to make
%_make_verbose V=1 VERBOSE=1

#------------------------------------------------------------------------------
# The "make" analogue, hiding the _smp_mflags magic from specs
%make_build %{__make} %{_make_output_sync} %{?_smp_mflags} %{_make_verbose}

#------------------------------------------------------------------------------
# The make install analogue of %configure for modern autotools:
%make_install %{__make} install DESTDIR=%{?buildroot} INSTALL="%{__install} -p"

#------------------------------------------------------------------------------
# Former make install analogue, kept for compatibility and for old/broken
#  packages that don't support DESTDIR properly.
%makeinstall \
  %{__echo} "warning: macro 'makeinstall' is deprecated, try 'make_install' instead" 1>&2\
  %{__make} \\\
	prefix=%{?buildroot:%{buildroot}}%{_prefix} \\\
	exec_prefix=%{?buildroot:%{buildroot}}%{_exec_prefix} \\\
	bindir=%{?buildroot:%{buildroot}}%{_bindir} \\\
	sbindir=%{?buildroot:%{buildroot}}%{_sbindir} \\\
	sysconfdir=%{?buildroot:%{buildroot}}%{_sysconfdir} \\\
	datadir=%{?buildroot:%{buildroot}}%{_datadir} \\\
	includedir=%{?buildroot:%{buildroot}}%{_includedir} \\\
	libdir=%{?buildroot:%{buildroot}}%{_libdir} \\\
	libexecdir=%{?buildroot:%{buildroot}}%{_libexecdir} \\\
	localstatedir=%{?buildroot:%{buildroot}}%{_localstatedir} \\\
	sharedstatedir=%{?buildroot:%{buildroot}}%{_sharedstatedir} \\\
	mandir=%{?buildroot:%{buildroot}}%{_mandir} \\\
	infodir=%{?buildroot:%{buildroot}}%{_infodir} \\\
  install

#------------------------------------------------------------------------------
# arch macro for all Intel i?86 compatible processors
#  (Note: This macro (and it's analogues) will probably be obsoleted when
#   rpm can use regular expressions against target platforms in macro
#   conditionals.
#
%ix86   i386

#------------------------------------------------------------------------------
# arch macro for all supported ARM processors
%arm	armel armhf

#------------------------------------------------------------------------------
# arch macro for 32-bit MIPS processors
%mips32	mips mipsel

#------------------------------------------------------------------------------
# arch macro for 64-bit MIPS processors
%mips64	mips64 mips64el

#------------------------------------------------------------------------------
# arch macro for big endian MIPS processors
%mipseb	mips mips64

#------------------------------------------------------------------------------
# arch macro for little endian MIPS processors
%mipsel	mipsel mips64el

#------------------------------------------------------------------------------
# arch macro for all supported MIPS processors
%mips	%{mips32} %{mips64}

#------------------------------------------------------------------------------
# arch macro for all supported PowerPC 64 processors
%power64	ppc64 ppc64el

#------------------------------------------------------------------------
# Use in %install to generate locale specific file lists. For example,
#
# %install
# ...
# %find_lang %{name}
# ...
# %files -f %{name}.lang
#
%find_lang	%{_debconfigdir}/find-lang.pl %{buildroot}

#------------------------------------------------------------------------------
# Macros for further automated spec %setup and patch application
#
# default to plain patch
%__scm patch
# meh, figure something saner
%__scm_username debbuild
%__scm_usermail <debbuild>
%__scm_author %{__scm_username} %{__scm_usermail}

# Plain patch (-m is unused)
%__scm_setup_patch(q) %{nil}
%__scm_apply_patch(qp:m:)\
%{__patch} %{-p:-p%{-p*}} %{-q:-s} -F %{_default_patch_fuzz} %{_default_patch_flags}

# Plain patch with backups for gendiff
%__scm_setup_gendiff(q)=__scm_setup_patch
%__scm_apply_gendiff(qp:m:)\
%{__patch} %{-p:-p%{-p*}} %{-q:-s} -F %{_default_patch_fuzz} %{_default_patch_flags} -b -z ".%{2}"

# Mercurial (aka hg)
%__hg /usr/bin/hg
%__scm_setup_hg(q)\
%{__hg} init %{-q} .\
%{__hg} add %{-q} .\
%{__hg} commit %{-q} --user "%{__scm_author}" -m "%{name}-%{version} base"

%__scm_apply_hg(qp:m:)\
%{__hg} import - %{-p:-p%{-p*}} %{-q} -m %{-m*} --user "%{__scm_author}"

# Git
%__git /usr/bin/git
%__scm_setup_git(q)\
%{__git} init %{-q}\
%{__git} config user.name "%{__scm_username}"\
%{__git} config user.email "%{__scm_usermail}"\
%{__git} add .\
%{__git} commit %{-q} --allow-empty -a --author "%{__scm_author}" -m "%{name}-%{version} base"

%__scm_apply_git(qp:m:)\
%{__git} apply --index %{-p:-p%{-p*}} -\
%{__git} commit %{-q} -m %{-m*} --author "%{__scm_author}"

# Git, using "git am" (-m is unused)
%__scm_setup_git_am(q)=__scm_setup_git
%__scm_apply_git_am(qp:m:)\
%{__git} am %{-q} %{-p:-p%{-p*}}

# Quilt
%__quilt /usr/bin/quilt
%__scm_setup_quilt(q) %{nil}
%__scm_apply_quilt(qp:m:)\
%{__quilt} import %{-p:-p%{-p*}} %{1} && %{__quilt} push %{-q}

# Bzr
%__bzr /usr/bin/bzr
%__scm_setup_bzr(q)\
%{__bzr} init %{-q}\
%{__bzr} whoami --branch "%{__scm_author}"\
%{__bzr} add .\
%{__bzr} commit %{-q} -m "%{name}-%{version} base"

# bzr doesn't seem to have its own command to apply patches?
%__scm_apply_bzr(qp:m:)\
%{__patch} %{-p:-p%{-p*}} %{-q:-s}\
%{__bzr} commit %{-q} -m %{-m*}

# \endverbatim
#*/
