我在两个不同的操作系统上使用相同的用户目录。是否可以根据操作系统指定一组条件的Makevars规则?我的一个操作系统较旧,无法支持另一个操作系统的所有功能。如果是这样,您能举个例子吗?
我想这会是:
os = $(uname -a | awk '{print $2}')
ifeq(os, "redhat7")
CC=/opt/rh/devtoolset-7/root/usr/bin/gcc
CXX=/opt/rh/devtoolset-7/root/usr/bin/g++
...
endif
但是我不确定如何使变量os。
答案 0 :(得分:1)
似乎没人在乎,我敢于提出gmtt,一个GNUmake帮助器库。在设计时就考虑到了这种用例。您可以使用选项标志定义表,并通过一列(或其组合)select
来定义表,这与SQL select的适度形式非常相似:
include gmtt-master/gmtt-master/gmtt.mk
# Table with two (indicator "2" as first element) columns. First column is a glob which matches the OS, second is option string
# Warning! No spaces in either column are allowed - use $(call spc-mask,...options...) if there are.
define CC_OPTIONS_TBL
2
redhat[!7]* /opt/rh/devtoolset-6/root/usr/bin/gcc
redhat7 /opt/rh/devtoolset-7/root/usr/bin/gcc
suse* /opt/bin/rh/devtoolset-7/root/usr/bin/gcc
endef
CC_OPT := $(call select,2,$(CC_OPTIONS_TBL),$$(call glob-match,$(MY_OS),$$1))
$(info CC_OPT = $(CC_OPT))
define CXX_OPTIONS_TBL
2
redhat[!7]* $(call spc-mask, /opt/rh/devtoolset-6/root/usr/bin/gcc -DREDHAT -O2)
redhat7 $(call spc-mask, /opt/rh/devtoolset-7/root/usr/bin/gcc -DREDHAT_7 -O3)
suse* $(call spc-mask, /opt/bin/rh/devtoolset-7/root/usr/bin/gcc -DSUSE -O0)
suse8 $(call spc-mask, -DFOO -DBAR)
endef
CXX_OPT := $(call spc-unmask,$(call select,2,$(CXX_OPTIONS_TBL),$$(call glob-match,$(MY_OS),$$1)))
$(info CXX_OPT = $(CXX_OPT))
输出:
mark@zws103 ~
$ make MY_OS=suse
CC_OPT = /opt/bin/rh/devtoolset-7/root/usr/bin/gcc
CXX_OPT = /opt/bin/rh/devtoolset-7/root/usr/bin/gcc -DSUSE -O0
make: *** Keine Ziele. Schluss.
mark@zws103 ~
$ make MY_OS=redhat6.1
CC_OPT = /opt/rh/devtoolset-6/root/usr/bin/gcc
CXX_OPT = /opt/rh/devtoolset-6/root/usr/bin/gcc -DREDHAT -O2
make: *** Keine Ziele. Schluss.
mark@zws103 ~
$ make MY_OS=redhat7
CC_OPT = /opt/rh/devtoolset-7/root/usr/bin/gcc
CXX_OPT = /opt/rh/devtoolset-7/root/usr/bin/gcc -DREDHAT_7 -O3
make: *** Keine Ziele. Schluss.
mark@zws103 ~
$ make MY_OS=redhat7.1
CC_OPT =
CXX_OPT =
make: *** Keine Ziele. Schluss.
请注意,最后一个OS字符串“ redhat7.1”与表中的任何glob都不匹配。
还要注意,select
返回匹配的所有行:
$ make MY_OS=suse8
CC_OPT = /opt/bin/rh/devtoolset-7/root/usr/bin/gcc
CXX_OPT = /opt/bin/rh/devtoolset-7/root/usr/bin/gcc -DSUSE -O0 -DFOO -DBAR
make: *** Keine Ziele. Schluss.