mk: use linux and freebsd in config names
[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 %app-icc,$(filter-out %app-clang,\
25         $(filter-out %app-gcc,$(filter-out %~,\
26         $(patsubst $(RTE_SRCDIR)/config/defconfig_%,%,\
27         $(wildcard $(RTE_SRCDIR)/config/defconfig_*)))))))
28 INSTALL_TARGETS := $(addsuffix _install,$(INSTALL_CONFIGS))
29
30 .PHONY: showconfigs
31 showconfigs:
32         @$(foreach CONFIG, $(INSTALL_CONFIGS), echo $(CONFIG);)
33
34 .PHONY: notemplate
35 notemplate:
36         @printf "No template specified. Use 'make defconfig' or "
37         @echo "use T=template from the following list:"
38         @$(MAKE) -rR showconfigs | sed 's,^,  ,'
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 if ($$0 == "amd64") { \
51                         print "x86_64-native"} \
52                 else { \
53                         printf "%s-native", $$0} }' \
54                 )-$(shell \
55                 uname | awk '{ \
56                 if ($$0 == "Linux") { \
57                         print "linux"} \
58                 else { \
59                         print "freebsd"} }' \
60                 )-$(shell \
61                 ${CC} --version | grep -o 'cc\|gcc\|icc\|clang' | awk \
62                 '{ \
63                 if ($$1 == "cc") { \
64                         print "gcc" } \
65                 else { \
66                         print $$1 } \
67                 }' \
68                 )
69
70 .PHONY: config
71 ifeq ($(RTE_CONFIG_TEMPLATE),)
72 config: notemplate
73 else
74 config: $(RTE_OUTPUT)/include/rte_config.h $(RTE_OUTPUT)/Makefile
75         @echo "Configuration done using" \
76                 $(patsubst defconfig_%,%,$(notdir $(RTE_CONFIG_TEMPLATE)))
77 endif
78
79 $(RTE_OUTPUT):
80         $(Q)mkdir -p $@
81
82 ifdef NODOTCONF
83 $(RTE_OUTPUT)/.config: ;
84 else
85 # Generate config from template, if there are duplicates keep only the last.
86 # To do so the temp config is checked for duplicate keys with cut/sort/uniq
87 # Then for each of those identified duplicates as long as there are more than
88 # just one left the last match is removed.
89 $(RTE_OUTPUT)/.config: $(RTE_CONFIG_TEMPLATE) FORCE | $(RTE_OUTPUT)
90         $(Q)if [ "$(RTE_CONFIG_TEMPLATE)" != "" -a -f "$(RTE_CONFIG_TEMPLATE)" ]; then \
91                 $(CPP) -undef -P -x assembler-with-cpp \
92                 -ffreestanding \
93                 -o $(RTE_OUTPUT)/.config_tmp $(RTE_CONFIG_TEMPLATE) ; \
94                 config=$$(cat $(RTE_OUTPUT)/.config_tmp) ; \
95                 echo "$$config" | awk -F '=' 'BEGIN {i=1} \
96                         /^#/ {pos[i++]=$$0} \
97                         !/^#/ {if (!s[$$1]) {pos[i]=$$0; s[$$1]=i++} \
98                                 else {pos[s[$$1]]=$$0}} END \
99                         {for (j=1; j<i; j++) print pos[j]}' \
100                         > $(RTE_OUTPUT)/.config_tmp ; \
101                 if ! cmp -s $(RTE_OUTPUT)/.config_tmp $(RTE_OUTPUT)/.config; then \
102                         cp $(RTE_OUTPUT)/.config_tmp $(RTE_OUTPUT)/.config ; \
103                         cp $(RTE_OUTPUT)/.config_tmp $(RTE_OUTPUT)/.config.orig ; \
104                 fi ; \
105                 rm -f $(RTE_OUTPUT)/.config_tmp ; \
106         else \
107                 $(MAKE) -rRf $(RTE_SDK)/mk/rte.sdkconfig.mk notemplate; \
108         fi
109 endif
110
111 # generate a Makefile for this build directory
112 # use a relative path so it will continue to work even if we move the directory
113 SDK_RELPATH=$(shell $(RTE_SDK)/buildtools/relpath.sh $(abspath $(RTE_SRCDIR)) \
114                                 $(abspath $(RTE_OUTPUT)))
115 OUTPUT_RELPATH=$(shell $(RTE_SDK)/buildtools/relpath.sh $(abspath $(RTE_OUTPUT)) \
116                                 $(abspath $(RTE_SRCDIR)))
117 $(RTE_OUTPUT)/Makefile: | $(RTE_OUTPUT)
118         $(Q)$(RTE_SDK)/buildtools/gen-build-mk.sh $(SDK_RELPATH) > $@
119
120 # clean installed files, and generate a new config header file
121 # if NODOTCONF variable is defined, don't try to rebuild .config
122 $(RTE_OUTPUT)/include/rte_config.h: $(RTE_OUTPUT)/.config
123         $(Q)rm -rf $(RTE_OUTPUT)/include $(RTE_OUTPUT)/app \
124                 $(RTE_OUTPUT)/lib \
125                 $(RTE_OUTPUT)/hostlib $(RTE_OUTPUT)/kmod $(RTE_OUTPUT)/build
126         $(Q)mkdir -p $(RTE_OUTPUT)/include
127         $(Q)$(RTE_SDK)/buildtools/gen-config-h.sh $(RTE_OUTPUT)/.config \
128                 > $(RTE_OUTPUT)/include/rte_config.h
129
130 # generate the rte_config.h
131 .PHONY: headerconfig
132 headerconfig: $(RTE_OUTPUT)/include/rte_config.h
133         @true
134
135 # check that .config is present, and if yes, check that rte_config.h
136 # is up to date
137 .PHONY: checkconfig
138 checkconfig:
139         @if [ ! -f $(RTE_OUTPUT)/.config ]; then \
140                 echo "No .config in build directory"; \
141                 exit 1; \
142         fi
143         $(Q)$(MAKE) -f $(RTE_SDK)/mk/rte.sdkconfig.mk \
144                 headerconfig NODOTCONF=1
145
146 .PHONY: FORCE
147 FORCE: