【背景】
折腾:
【已解决】在makefile中判断是cygwin还是Linux系统
期间,需要去把得到的Cygwin字符串转换为小写,以便更靠谱的去判断是否是cygwin系统。
【解决过程】
1.参考:
In GNU Make, how do I convert a variable to lower case?
感觉很是麻烦。
2.参考:
Bug 747206 – makefiles: add pure make uppercase/lowercase functions
看到其有建议,
在make中添加uc()和lc()
以便取代:
$(shell echo $(var) | tr '[A-Z]' '[a-z]')
3.开始以为lc是Linux下的工具呢,结果通过:
Administrator@PC-20130611GART /cygdrive/e/Dev_Root/docbook/tools/docbook-xsl-ns-1.78.1/webhelp $ which lc which: no lc in (/usr/local/bin:/usr/bin:/cygdrive/c/Program Files (x86)/AMD APP/bin/x86_64:/cygdrive/c/Program Files (x86)/AMD APP/bin/x86:/cygdrive/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common:/cygdrive/c/Program Files/Common Files/Microsoft Shared/Windows Live:/cygdrive/c/Program Files (x86)/Common Files/Microsoft Shared/Windows Live:/cygdrive/c/Windows/system32:/cygdrive/c/Windows:/cygdrive/c/Windows/System32/Wbem:/cygdrive/c/Windows/System32/WindowsPowerShell/v1.0:/cygdrive/c/Program Files (x86)/ATI Technologies/ATI.ACE/Core-Static:/cygdrive/c/Program Files/Microsoft/Web Platform Installer:/cygdrive/c/Program Files (x86)/Microsoft ASP.NET/ASP.NET Web Pages/v1.0:/cygdrive/c/Program Files (x86)/Windows Kits/8.0/Windows Performance Toolkit:/cygdrive/c/Program Files/Microsoft SQL Server/110/Tools/Binn:/cygdrive/c/Program Files (x86)/Microsoft SQL Server/100/Tools/Binn:/cygdrive/c/Program Files/Microsoft SQL Server/100/Tools/Binn:/cygdrive/c/Program Files/Microsoft SQL Server/100/DTS/Binn:/cygdrive/c/Program Files (x86)/Windows Live/Shared:/cygdrive/c/Program Files/Java/jdk1.7.0_25/bin:/usr/bin:/cygdrive/e/Dev_Root/docbook/tools/ant/apache-ant-1.8.4/bin:/cygdrive/e/Dev_Root/docbook/tools/fop-1.0:/cygdrive/e/dev_install_root/HTML Help Workshop:/cygdrive/e/dev_install_root/TortoiseSVN/bin:/cygdrive/e/dev_install_root/Go/bin:/cygdrive/e/Dev_Root/go/bin:/cygdrive/e/dev_install_root/Mercurial:/cygdrive/e/dev_install_root/IDM Computer Solutions/UltraEdit:/usr/lib/lapack:/opt/crosstool-ng/bin)
得知,不是。
4.然后,就可以去makefile中,去测试看看当前make是否支持lc了:
去测试:
OS_NAME = $(shell uname -o) LC_OS_NAME = lc($(OS_NAME)) checkcygwin: echo "OS_NAME=" $(OS_NAME) echo "LC_OS_NAME=" $(LC_OS_NAME)
结果还出现“/bin/sh: -c: line 0: syntax error near unexpected token `(‘”的错误了:
【已解决】makefile运行出错:/bin/sh: -c: line 0: syntax error near unexpected token `(‘,以及makefile中如何调用内置函数
5.结果是不支持lc。
所以,去换用那个tr操作var的试试:
OS_NAME = $(shell uname -o) #LC_OS_NAME = $(lc $(OS_NAME)) LC_OS_NAME = $(shell echo $(OS_NAME) | tr '[A-Z]' '[a-z]') checkcygwin: echo "OS_NAME=" $(OS_NAME) echo "LC_OS_NAME=" $(LC_OS_NAME)
结果是:
可以的:
Administrator@PC-20130611GART /cygdrive/e/Dev_Root/docbook/tools/docbook-xsl-ns-1.78.1/webhelp $ make checkcygwin echo "OS_NAME=" Cygwin OS_NAME= Cygwin echo "LC_OS_NAME=" cygwin LC_OS_NAME= cygwin
【总结】
makefile中,将字符串从大写转换为小写的,可以用:
$(shell echo $(someVariable) | tr '[A-Z]' '[a-z]')
相反,makefile中,把字符串从小写转换为大写则用:
$(shell echo $(someVariable) | tr '[a-z]' '[A-Z]')
转载请注明:在路上 » 【已解决】makefile中把字符串转换为小写或大写