Allowing both cross building and using an alternative compiler

Guillem Jover guillem at debian.org
Sun May 10 01:32:27 UTC 2015


[ Please followup on debian-devel (M-F-T set). ]

Hi!

There are currently two goals people are pursuing that seemed to
initially conflict with each other:

  <https://wiki.debian.org/ReleaseGoals/CrossBuildableBase>
  <https://wiki.debian.org/ReleaseGoals/honorCCandCXX>

But they can be made to coexist gracefully, if using the same
semantics as used by autotools but on a Makefile.

,---
DEB_HOST_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)

ifeq ($(origin CC),default)
CC = $(DEB_HOST_GNU_TYPE)-gcc
endif
CC ?= $(DEB_HOST_GNU_TYPE)-gcc
CC_FOR_BUILD = gcc
`---

This allows the user to both set CC to any non-default compiler such
as clang or gcc-6, and supports cross compiling out of the box. I guess
that if people do not see any obvious problem with it, something like
this should probably be codified in policy.

I'm in principle planning to add the attached Makefile to dpkg-dev to
make this kind of usage easier for packagers.

Thanks,
Guillem
-------------- next part --------------
# This Makefile snippet defines the following variables for host tools:
#
# CPP: C preprocessor
# CC: C compiler
# CXX: C++ compiler
# OBJC: Objective C compiler
# OBJCXX: Objective C++ compiler
# GCJ: GNU Java compiler
# F77: Fortran 77 compiler
# FC: Fortran 9x compiler
# LD: linker
#
# All the above variables have a counterpart variable for the build tool,
# as in CC ? CC_FOR_BUILD.
#
# The variables are not exported by default. This can be changed by
# defining DPKG_EXPORT_BUILDTOOLS.

DEB_HOST_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)

define dpkg_buildtool_setvar
ifeq ($(origin $(1)),default)
$(1) = $(DEB_HOST_GNU_TYPE)-$(2)
endif
$(1) ?= $(DEB_HOST_GNU_TYPE)-$(2)
$(1)_FOR_BUILD = $(2)
ifdef DPKG_EXPORT_BUILDTOOLS
export $(1)
export $(1)_FOR_BUILD
endif
endef

$(eval $(call dpkg_buildtool_setvar,CPP,gcc -E))
$(eval $(call dpkg_buildtool_setvar,CC,gcc))
$(eval $(call dpkg_buildtool_setvar,CXX,g++))
$(eval $(call dpkg_buildtool_setvar,OBJC,gcc))
$(eval $(call dpkg_buildtool_setvar,OBJCXX,g++))
$(eval $(call dpkg_buildtool_setvar,GCJ,gcj))
$(eval $(call dpkg_buildtool_setvar,F77,f77))
$(eval $(call dpkg_buildtool_setvar,FC,f95))
$(eval $(call dpkg_buildtool_setvar,LD,ld))


More information about the Pkg-llvm-team mailing list