summaryrefslogtreecommitdiff
path: root/scripts/mk/buildflags.mk
blob: 8f0f215f86282e4990abc865fd1968a411a8c860 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# This Makefile snippet defines the following variables:
#
# CFLAGS: flags for the C compiler
# CPPFLAGS: flags for the C preprocessor
# CXXFLAGS: flags for the C++ compiler
# FFLAGS: flags for the Fortran compiler
# LDFLAGS: flags for the linker
#
# You can also export them in the environment by setting
# DPKG_EXPORT_BUILDFLAGS to a non-empty value.
#
# This list is kept in sync with the default set of flags returned
# by dpkg-buildflags.

dpkg_late_eval ?= $(or $(value DPKG_CACHE_$(1)),$(eval DPKG_CACHE_$(1) := $(shell $(2)))$(value DPKG_CACHE_$(1)))

DPKG_BUILDFLAGS_LIST = CFLAGS CPPFLAGS CXXFLAGS FFLAGS LDFLAGS

define dpkg_buildflags_export_envvar
ifdef $(1)
DPKG_BUILDFLAGS_EXPORT_ENVVAR += $(1)="$(value $(1))"
endif
endef

$(eval $(call dpkg_buildflags_export_envvar,DEB_BUILD_MAINT_OPTIONS))
$(foreach flag,$(DPKG_BUILDFLAGS_LIST),\
  $(foreach operation,SET STRIP APPEND PREPEND,\
    $(eval $(call dpkg_buildflags_export_envvar,DEB_$(flag)_MAINT_$(operation)))))

dpkg_buildflags_setvar = $(1) = $(call dpkg_late_eval,$(1),$(DPKG_BUILDFLAGS_EXPORT_ENVVAR) dpkg-buildflags --get $(1))

$(foreach flag,$(DPKG_BUILDFLAGS_LIST),\
  $(eval $(call dpkg_buildflags_setvar,$(flag))))

ifdef DPKG_EXPORT_BUILDFLAGS
  export $(DPKG_BUILDFLAGS_LIST)
endif