New upstream version 17.11.3
[deb_dpdk.git] / mk / rte.sdkconfig.mk
1 #   BSD LICENSE
2 #
3 #   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
4 #   All rights reserved.
5 #
6 #   Redistribution and use in source and binary forms, with or without
7 #   modification, are permitted provided that the following conditions
8 #   are met:
9 #
10 #     * Redistributions of source code must retain the above copyright
11 #       notice, this list of conditions and the following disclaimer.
12 #     * Redistributions in binary form must reproduce the above copyright
13 #       notice, this list of conditions and the following disclaimer in
14 #       the documentation and/or other materials provided with the
15 #       distribution.
16 #     * Neither the name of Intel Corporation nor the names of its
17 #       contributors may be used to endorse or promote products derived
18 #       from this software without specific prior written permission.
19 #
20 #   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 #   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 #   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 #   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 #   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 #   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 #   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 #   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 #   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 #   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 #   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
32 .PHONY: showversion
33 showversion:
34         @set -- \
35                 $$(sed -rne 's,^#define RTE_VER_[A-Z_]*[[:space:]]+([0-9]+).*,\1,p' \
36                         -e 's,^#define RTE_VER_SUFFIX[[:space:]]+"(.*)",\1,p' \
37                         $(RTE_SRCDIR)/lib/librte_eal/common/include/rte_version.h) ;\
38                 printf '%d.%02d.%d' "$$1" "$$2" "$$3"; \
39                 if [ -z "$$5" ]; then echo; \
40                 else printf '%s' "$$4"; \
41                         if [ $$5 -lt 16 ] ; then echo $$5; \
42                         else echo $$(($$5 - 16)); fi; \
43                 fi
44
45 .PHONY: showversionum
46 showversionum:
47         @set -- \
48                 $$(sed -rne 's,^#define RTE_VER_[A-Z_]*[[:space:]]+([0-9]+).*,\1,p' \
49                         $(RTE_SRCDIR)/lib/librte_eal/common/include/rte_version.h); \
50                 printf '%02d%02d\n' "$$1" "$$2"
51
52 INSTALL_CONFIGS := $(sort $(filter-out %~,\
53         $(patsubst $(RTE_SRCDIR)/config/defconfig_%,%,\
54         $(wildcard $(RTE_SRCDIR)/config/defconfig_*))))
55 INSTALL_TARGETS := $(addsuffix _install,$(INSTALL_CONFIGS))
56
57 .PHONY: showconfigs
58 showconfigs:
59         @$(foreach CONFIG, $(INSTALL_CONFIGS), echo $(CONFIG);)
60
61 .PHONY: notemplate
62 notemplate:
63         @printf "No template specified. Use 'make defconfig' or "
64         @echo "use T=template from the following list:"
65         @$(MAKE) -rR showconfigs | sed 's,^,  ,'
66
67 .PHONY: defconfig
68 defconfig:
69         @$(MAKE) config T=$(shell \
70                 uname -m | awk '{ \
71                 if ($$0 == "aarch64") { \
72                         print "arm64-armv8a"} \
73                 else if ($$0 == "armv7l") { \
74                         print "arm-armv7a"} \
75                 else if ($$0 == "ppc64") { \
76                         print "ppc_64-power8"} \
77                 else if ($$0 == "amd64") { \
78                         print "x86_64-native"} \
79                 else { \
80                         printf "%s-native", $$0} }' \
81                 )-$(shell \
82                 uname | awk '{ \
83                 if ($$0 == "Linux") { \
84                         print "linuxapp"} \
85                 else { \
86                         print "bsdapp"} }' \
87                 )-$(shell \
88                 ${CC} --version | grep -o 'cc\|gcc\|icc\|clang' | awk \
89                 '{ \
90                 if ($$1 == "cc") { \
91                         print "gcc" } \
92                 else { \
93                         print $$1 } \
94                 }' \
95                 )
96
97 .PHONY: config
98 ifeq ($(RTE_CONFIG_TEMPLATE),)
99 config: notemplate
100 else
101 config: $(RTE_OUTPUT)/include/rte_config.h $(RTE_OUTPUT)/Makefile
102         @echo "Configuration done using" \
103                 $(patsubst defconfig_%,%,$(notdir $(RTE_CONFIG_TEMPLATE)))
104 endif
105
106 $(RTE_OUTPUT):
107         $(Q)mkdir -p $@
108
109 ifdef NODOTCONF
110 $(RTE_OUTPUT)/.config: ;
111 else
112 # Generate config from template, if there are duplicates keep only the last.
113 # To do so the temp config is checked for duplicate keys with cut/sort/uniq
114 # Then for each of those identified duplicates as long as there are more than
115 # just one left the last match is removed.
116 $(RTE_OUTPUT)/.config: $(RTE_CONFIG_TEMPLATE) FORCE | $(RTE_OUTPUT)
117         $(Q)if [ "$(RTE_CONFIG_TEMPLATE)" != "" -a -f "$(RTE_CONFIG_TEMPLATE)" ]; then \
118                 $(CPP) -undef -P -x assembler-with-cpp \
119                 -ffreestanding \
120                 -o $(RTE_OUTPUT)/.config_tmp $(RTE_CONFIG_TEMPLATE) ; \
121                 config=$$(cat $(RTE_OUTPUT)/.config_tmp) ; \
122                 echo "$$config" | awk -F '=' 'BEGIN {i=1} \
123                         /^#/ {pos[i++]=$$0} \
124                         !/^#/ {if (!s[$$1]) {pos[i]=$$0; s[$$1]=i++} \
125                                 else {pos[s[$$1]]=$$0}} END \
126                         {for (j=1; j<i; j++) print pos[j]}' \
127                         > $(RTE_OUTPUT)/.config_tmp ; \
128                 if ! cmp -s $(RTE_OUTPUT)/.config_tmp $(RTE_OUTPUT)/.config; then \
129                         cp $(RTE_OUTPUT)/.config_tmp $(RTE_OUTPUT)/.config ; \
130                         cp $(RTE_OUTPUT)/.config_tmp $(RTE_OUTPUT)/.config.orig ; \
131                 fi ; \
132                 rm -f $(RTE_OUTPUT)/.config_tmp ; \
133         else \
134                 $(MAKE) -rRf $(RTE_SDK)/mk/rte.sdkconfig.mk notemplate; \
135         fi
136 endif
137
138 # generate a Makefile for this build directory
139 # use a relative path so it will continue to work even if we move the directory
140 SDK_RELPATH=$(shell $(RTE_SDK)/buildtools/relpath.sh $(abspath $(RTE_SRCDIR)) \
141                                 $(abspath $(RTE_OUTPUT)))
142 OUTPUT_RELPATH=$(shell $(RTE_SDK)/buildtools/relpath.sh $(abspath $(RTE_OUTPUT)) \
143                                 $(abspath $(RTE_SRCDIR)))
144 $(RTE_OUTPUT)/Makefile: | $(RTE_OUTPUT)
145         $(Q)$(RTE_SDK)/buildtools/gen-build-mk.sh $(SDK_RELPATH) $(OUTPUT_RELPATH) \
146                 > $(RTE_OUTPUT)/Makefile
147
148 # clean installed files, and generate a new config header file
149 # if NODOTCONF variable is defined, don't try to rebuild .config
150 $(RTE_OUTPUT)/include/rte_config.h: $(RTE_OUTPUT)/.config
151         $(Q)rm -rf $(RTE_OUTPUT)/include $(RTE_OUTPUT)/app \
152                 $(RTE_OUTPUT)/lib \
153                 $(RTE_OUTPUT)/hostlib $(RTE_OUTPUT)/kmod $(RTE_OUTPUT)/build
154         $(Q)mkdir -p $(RTE_OUTPUT)/include
155         $(Q)$(RTE_SDK)/buildtools/gen-config-h.sh $(RTE_OUTPUT)/.config \
156                 > $(RTE_OUTPUT)/include/rte_config.h
157
158 # generate the rte_config.h
159 .PHONY: headerconfig
160 headerconfig: $(RTE_OUTPUT)/include/rte_config.h
161         @true
162
163 # check that .config is present, and if yes, check that rte_config.h
164 # is up to date
165 .PHONY: checkconfig
166 checkconfig:
167         @if [ ! -f $(RTE_OUTPUT)/.config ]; then \
168                 echo "No .config in build directory"; \
169                 exit 1; \
170         fi
171         $(Q)$(MAKE) -f $(RTE_SDK)/mk/rte.sdkconfig.mk \
172                 headerconfig NODOTCONF=1
173
174 .PHONY: FORCE
175 FORCE: