Windows下的GNU Make:在PATH中检查cygwin [英] GNU Make Under Windows: Check for cygwin in PATH

查看:66
本文介绍了Windows下的GNU Make:在PATH中检查cygwin的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在Windows环境中整理一个makefile供我的团队使用.我决定将MinGW的make版本用于Windows.我将该可执行文件及其相关性放入每个人的PATH变量中的存储库位置.为了简单起见,该可执行文件被重命名为"make.exe".

I have been putting together a makefile in a Windows environment for my team to use. I decided to use MinGW's version of make for Windows. I put that executable with its dependencies into a repository location that should be in everyone's PATH variable. The executable was renamed "make.exe" for simplicity.

然后我意识到我必须考虑到某人的路径中有cygwin的bin文件夹的情况.诸如echo,rmdir和mkdir之类的命令将从cygwin的bin文件夹中调用echo.exe,rmdir.exe和mkdir.exe.这意味着我需要适当地抓住这种情况,并对每个命令使用不同的标志.

Then I realized that I have to account for the case when someone has cygwin's bin folder in their path. Commands like echo, rmdir, and mkdir will call echo.exe, rmdir.exe, and mkdir.exe from cygwin's bin folder. This means that I need to appropriately catch this scenario and use different flags for each command.

我在这里看到三种情况:

I see three cases here:

  1. Cygwin的bin路径位于存储库中make.exe所在路径之前.当团队成员执行make.exe时,他们将执行cygwin的make.必须使用Unix风格的命令.
  2. Cygwin的bin路径位于存储库中make.exe所在路径的后面.正确的make.exe将被执行,但是我仍然必须使用Unix风格的命令.
  3. Cygwin未安装或未在PATH中.在这种情况下,我可以使用所有Windows命令.

我可以将病例1和2相同地治疗.由于MinGW的品牌和cygwin的品牌都是基于GNU Make的,所以除了GNU Make版本之间的不兼容问题之外,我认为这不是一个大问题.让我们假设这现在不是问题.

I am fine with treating cases 1 and 2 the same. Since MinGW's make and cygwin's make are both based on GNU Make, then I don't see this being much of an issue other than incompatibility issues between versions of GNU Make. Let's just assume that isn't a problem for now.

我在我的makefile文件中做了以下检查.

I have come up with the following check in my makefile.

ifneq (,$(findstring cygdrive,$(PATH))$(findstring cygwin,$(PATH))$(findstring Cygwin,$(PATH)))
    #Use Unix style command variables
else
    #Use Windows style command variables
endif

在路径变量中找到"cygdrive"意味着我们很可能在情况1中.在路径变量中找到"cygwin"或"Cygwin"很可能意味着我们在情况2中.在路径中找不到任何一个字符串最有可能意味着我们处于情况3.

Finding "cygdrive" in the path variable means that we are most likely in case 1. Finding "cygwin" or "Cygwin" in the path variable most likely means that we are in case 2. Not finding either string in the path most likely means that we are in case 3.

我不完全喜欢这种解决方案,因为可以重命名cygwin的文件夹,或者可以在不安装cygwin的情况下将字符串"cygwin"或"cygdrive"放入PATH变量中.一名团队成员仍存在问题,因为他在PATH变量中包含了cygwin的bin路径,但以上内容未能解决该问题.我以为他已将该文件夹重命名为其他名称,但我无法对其进行检查.

I am not completely fond of this solution because the cygwin's folder can be renamed or the string "cygwin" or "cygdrive" can be put in the PATH variable without having cygwin installed. One team member is still having issues as he has cygwin's bin path in the PATH variable, but the above does not catch that. I am assuming that he renamed the folder to something else, but I haven't been able to check on that.

那么有更好的方法来弄清楚我应该使用哪种语法?

So is there a better way to figure out what syntax that I should be using?

推荐答案

Cygwin make诉MinGW make:mingw make是否支持作业服务器,就像您可以执行 make -j5 一样吗?如果不是,则 $ {.FEATURES} 具有用于cygwin make的 jobserver .也许 load 也是很好的测试.

Cygwin make v. MinGW make: Does mingw make support the jobserver, as in can you do make -j5? If not, ${.FEATURES} has jobserver for cygwin make. Maybe load is a good test too.

在路径上非Cygwin之前的Cygwin: cygpath.exe 对于cygwin是唯一的.您可以在 $ {PATH} 中查找.不幸的是,Windows用户喜欢在文件夹名称中使用空格,并且无法纯粹地处理此问题. $(shell make)将返回cygwin的/usr/bin/make ,尽管每次make运行的shell调用都非常臭.

Cygwin before non-cygwin on path: cygpath.exe is unique to cygwin. You could just look for this in ${PATH}. Unfortunately, Windows users like using spaces in folder names, and there's no way of dealing with this in pure make. $(shell which make) will return /usr/bin/make for cygwin, though a shell invocation on every make run is very smelly.

您不是从存储库中安装编译器, make 是否不是类似情况?只需让您的用户安装cygwin并完成安装即可.

You don't install a compiler from a repository, is not make a similar case? Just get your users to install cygwin and be done with it.

这篇关于Windows下的GNU Make:在PATH中检查cygwin的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆