New upstream version 18.02
[deb_dpdk.git] / mk / rte.sdkconfig.mk
1 # SPDX-License-Identifier: BSD-3-Clause
2 # Copyright(c) 2010-2014 Intel Corporation
3
4 .PHONY: showversion
5 showversion:
6         @set -- \
7                 $$(sed -rne 's,^#define RTE_VER_[A-Z_]*[[:space:]]+([0-9]+).*,\1,p' \
8                         -e 's,^#define RTE_VER_SUFFIX[[:space:]]+"(.*)",\1,p' \
9                         $(RTE_SRCDIR)/lib/librte_eal/common/include/rte_version.h) ;\
10                 printf '%d.%02d.%d' "$$1" "$$2" "$$3"; \
11                 if [ -z "$$5" ]; then echo; \
12                 else printf '%s' "$$4"; \
13                         if [ $$5 -lt 16 ] ; then echo $$5; \
14                         else echo $$(($$5 - 16)); fi; \
15                 fi
16
17 .PHONY: showversionum
18 showversionum:
19         @set -- \
20                 $$(sed -rne 's,^#define RTE_VER_[A-Z_]*[[:space:]]+([0-9]+).*,\1,p' \
21                         $(RTE_SRCDIR)/lib/librte_eal/common/include/rte_version.h); \
22                 printf '%02d%02d\n' "$$1" "$$2"
23
24 INSTALL_CONFIGS := $(sort $(filter-out %~,\
25         $(patsubst $(RTE_SRCDIR)/config/defconfig_%,%,\
26         $(wildcard $(RTE_SRCDIR)/config/defconfig_*))))
27 INSTALL_TARGETS := $(addsuffix _install,$(INSTALL_CONFIGS))
28
29 .PHONY: showconfigs
30 showconfigs:
31         @$(foreach CONFIG, $(INSTALL_CONFIGS), echo $(CONFIG);)
32
33 .PHONY: notemplate
34 notemplate:
35         @printf "No template specified. Use 'make defconfig' or "
36         @echo "use T=template from the following list:"
37         @$(MAKE) -rR showconfigs | sed 's,^,  ,'
38
39
40 .PHONY: defconfig
41 defconfig:
42         @$(MAKE) config T=$(shell \
43                 uname -m | awk '{ \
44                 if ($$0 == "aarch64") { \
45                         print "arm64-armv8a"} \
46                 else if ($$0 == "armv7l") { \
47                         print "arm-armv7a"} \
48                 else if ($$0 == "ppc64") { \
49                         print "ppc_64-power8"} \
50                 else { \
51                         printf "%s-native", $$0} }')-$(shell \
52                 uname | awk '{ \
53                 if ($$0 == "Linux") { \
54                         print "linuxapp"} \
55                 else { \
56                         print "bsdapp"} }')-$(shell \
57                 ${CC} -v 2>&1 | \
58                 grep " version " | cut -d ' ' -f 1)
59
60 .PHONY: config
61 ifeq ($(RTE_CONFIG_TEMPLATE),)
62 config: notemplate
63 else
64 config: $(RTE_OUTPUT)/include/rte_config.h $(RTE_OUTPUT)/Makefile
65         @echo "Configuration done using" \
66                 $(patsubst defconfig_%,%,$(notdir $(RTE_CONFIG_TEMPLATE)))
67 endif
68
69 $(RTE_OUTPUT):
70         $(Q)mkdir -p $@
71
72 ifdef NODOTCONF
73 $(RTE_OUTPUT)/.config: ;
74 else
75 # Generate config from template, if there are duplicates keep only the last.
76 # To do so the temp config is checked for duplicate keys with cut/sort/uniq
77 # Then for each of those identified duplicates as long as there are more than
78 # just one left the last match is removed.
79 $(RTE_OUTPUT)/.config: $(RTE_CONFIG_TEMPLATE) FORCE | $(RTE_OUTPUT)
80         $(Q)if [ "$(RTE_CONFIG_TEMPLATE)" != "" -a -f "$(RTE_CONFIG_TEMPLATE)" ]; then \
81                 $(CPP) -undef -P -x assembler-with-cpp \
82                 -ffreestanding \
83                 -o $(RTE_OUTPUT)/.config_tmp $(RTE_CONFIG_TEMPLATE) ; \
84                 config=$$(cat $(RTE_OUTPUT)/.config_tmp) ; \
85                 echo "$$config" | awk -F '=' 'BEGIN {i=1} \
86                         /^#/ {pos[i++]=$$0} \
87                         !/^#/ {if (!s[$$1]) {pos[i]=$$0; s[$$1]=i++} \
88                                 else {pos[s[$$1]]=$$0}} END \
89                         {for (j=1; j<i; j++) print pos[j]}' \
90                         > $(RTE_OUTPUT)/.config_tmp ; \
91                 if ! cmp -s $(RTE_OUTPUT)/.config_tmp $(RTE_OUTPUT)/.config; then \
92                         cp $(RTE_OUTPUT)/.config_tmp $(RTE_OUTPUT)/.config ; \
93                         cp $(RTE_OUTPUT)/.config_tmp $(RTE_OUTPUT)/.config.orig ; \
94                 fi ; \
95                 rm -f $(RTE_OUTPUT)/.config_tmp ; \
96         else \
97                 $(MAKE) -rRf $(RTE_SDK)/mk/rte.sdkconfig.mk notemplate; \
98         fi
99 endif
100
101 # generate a Makefile for this build directory
102 # use a relative path so it will continue to work even if we move the directory
103 SDK_RELPATH=$(shell $(RTE_SDK)/buildtools/relpath.sh $(abspath $(RTE_SRCDIR)) \
104                                 $(abspath $(RTE_OUTPUT)))
105 OUTPUT_RELPATH=$(shell $(RTE_SDK)/buildtools/relpath.sh $(abspath $(RTE_OUTPUT)) \
106                                 $(abspath $(RTE_SRCDIR)))
107 $(RTE_OUTPUT)/Makefile: | $(RTE_OUTPUT)
108         $(Q)$(RTE_SDK)/buildtools/gen-build-mk.sh $(SDK_RELPATH) $(OUTPUT_RELPATH) \
109                 > $(RTE_OUTPUT)/Makefile
110
111 # clean installed files, and generate a new config header file
112 # if NODOTCONF variable is defined, don't try to rebuild .config
113 $(RTE_OUTPUT)/include/rte_config.h: $(RTE_OUTPUT)/.config
114         $(Q)rm -rf $(RTE_OUTPUT)/include $(RTE_OUTPUT)/app \
115                 $(RTE_OUTPUT)/lib \
116                 $(RTE_OUTPUT)/hostlib $(RTE_OUTPUT)/kmod $(RTE_OUTPUT)/build
117         $(Q)mkdir -p $(RTE_OUTPUT)/include
118         $(Q)$(RTE_SDK)/buildtools/gen-config-h.sh $(RTE_OUTPUT)/.config \
119                 > $(RTE_OUTPUT)/include/rte_config.h
120
121 # generate the rte_config.h
122 .PHONY: headerconfig
123 headerconfig: $(RTE_OUTPUT)/include/rte_config.h
124         @true
125
126 # check that .config is present, and if yes, check that rte_config.h
127 # is up to date
128 .PHONY: checkconfig
129 checkconfig:
130         @if [ ! -f $(RTE_OUTPUT)/.config ]; then \
131                 echo "No .config in build directory"; \
132                 exit 1; \
133         fi
134         $(Q)$(MAKE) -f $(RTE_SDK)/mk/rte.sdkconfig.mk \
135                 headerconfig NODOTCONF=1
136
137 .PHONY: FORCE
138 FORCE: