dpkg-architecture - set and determine the architecture for package building
dpkg-architecture [options] [action]
Valid options: -aDebian-Architecture -tGnu-System-Type -f
Valid actions: -l, -qVariable-Name, -s, -u, -c Command
dpkg-architecture does provide a facility to determine and set the build and host architecture for package building.
The build architecture is always determined by an external call to dpkg, and can not be set at the command line.
You can specify the host architecture by providing one or both of the options -a and -t. The default is determined by an external call to gcc, or the same as the build architecture if CC or gcc are both not available. One out of -a and -t is sufficient, the value of the other will be set to a usable default. Indeed, it is often better to only specify one, because dpkg-architecture will warn you if your choice doesn't match the default.
The default action is -l, which prints the environment variales, one each line, in the format VARIABLE=value. If you are only interested in the value of a single variable, you can use -q. If you specify -s, it will output an export command. This can be used to set the environment variables using eval. -u does return a similar command to unset all variables. -c does execute a command in an environment which has all variables set to the determined value.
Existing environment variables with the same name as used by the scripts are not overwritten, except if the -f force flag is present. This allows the user to override a value even when the call to dpkg-architecture is buried in some other script (for example dpkg-buildpackage).
dpkg-buildpackage accepts the -a option and passes it to dpkg-architecture. Other examples:
-c debian/rules build
The following variables are set by dpkg-architecture:
The environment variables set by dpkg-architecture are passed to debian/rules as make variables (see make documentation). However, you should not rely on them, as this breaks manual invocation of the script. Instead, you should always initialize them using dpkg-architecture with the -q option. Here are some examples, which also show how you can improve the cross compilation support in your package:
ARCH=`dpkg --print-architecture` configure $(ARCH)-linux
please use the following:
DEB_BUILD_GNU_TYPE := $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE) DEB_HOST_GNU_TYPE := $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
configure --build=$(DEB_BUILD_GNU_TYPE) --host=$(DEB_BUILD_GNU_SYSTEM)
ARCH=`dpkg --print-architecture` ifeq ($(ARCH),alpha) ... endif
DEB_HOST_ARCH := $(shell dpkg-architecture -qDEB_HOST_ARCH)
ifeq ($(DEB_HOST_ARCH),alpha) ... endif
In general, calling dpkg in the rules file to get architecture information is deprecated (until you want to provide backward compatibility, see below). Especially the --print-architecture option is unreliable since we have Debian architectures which don't equal a processor name.
When providing a new facility, it is always a good idea to stay compatible with old versions of the programs. Note that dpkg-architecture does not affect old debian/rules files, so the only thing to consider is using old versions of dpkg-dev with new debian/rules files. The following does the job:
DEB_BUILD_ARCH := $(shell dpkg --print-installation-architecture) DEB_BUILD_GNU_CPU := $(patsubst hurd-%,%,$(DEB_BUILD_ARCH)) ifeq ($(filter-out hurd-%,$(DEB_BUILD_ARCH)),) DEB_BUILD_GNU_SYSTEM := gnu else DEB_BUILD_GNU_SYSTEM := linux endif DEB_BUILD_GNU_TYPE=$(DEB_BUILD_GNU_CPU)-$(DEB_BUILD_GNU_SYSTEM)
DEB_HOST_ARCH := $(DEB_BUILD_ARCH) DEB_HOST_GNU_CPU := $(DEB_BUILD_GNU_CPU) DEB_HOST_GNU_SYSTEM := $(DEB_BUILD_GNU_SYSTEM) DEB_HOST_GNU_TYPE := $(DEB_BUILD_GNU_TYPE)
Put a subset of these lines at the top of your debian/rules file; these default values will be overwritten if dpkg-architecture is used.
You don't need the full set. Choose a consistent set which contains the values you use in the rules file. For example, if you only need the host Debian architecture, `DEB_HOST_ARCH=`dpkg --print-installation-architecture` is sufficient (this is indeed the Debian architecture of the build machine, but remember that we are only trying to be backward compatible with native compilation).
If you have questions about the usage of the make variables in your rules files, or about cross compilation support in your packages, please email me. The address is Marcus Brinkmann <firstname.lastname@example.org>.