4

I am using MinGW for compiling some stuff on Windows. I call mingw32-make directly from cmd.exe and everything (I need) works fine. However I found out I will need to be able to compile from the MSYS environment and I run in problems with copy and del commands not beeing recognized. I know it is only matter of replacing them with cp and rm, but I would like to use single makefile for both cases.

Is there a way to force msys environment to call system del and cp commands?

Or better yet, is there a way to distinguish whether the makefile is called from cmd.exe or msys? Than I could set appropriate variables for the commands. This would be quite helpfull, because I could then remove some other duplicate makefiles.

Any help is appreciated.

Thanks

EDIT: And to make things more difficult: mingw32-make seems to be using sh.exe if found in PATH when run from cmd.exe. This has completely different set of environment variables.

EDIT: OK, if anyone is still interested, I ended up with the following file, which I include to my other Makefiles:

ifeq ($(OS),Windows_NT) 
RM = del /Q /F
CP = copy /Y
ifdef ComSpec
SHELL := $(ComSpec)
endif
ifdef COMSPEC
SHELL := $(COMSPEC)
endif
else
RM = rm -rf
CP = cp -f
endif

If not, and you still think this is a duplicate question I can of course delete this question.

For reasons unknown to me ComSpec and COMPSPEC make a difference.

Zdenek Prusa
  • 181
  • 1
  • 10
  • You can probably check some environment variable(s) that are unique to each environment, and then call one makefile for the `cmd.exe` environment and one for the `MSYS`. – Some programmer dude Nov 12 '13 at 12:20
  • Yes, but I would like to avoid having to deal with two makefiles, since they differ only in the del/rm, cp/copy. But the environment variable can be probably checked inside of the makefile. – Zdenek Prusa Nov 12 '13 at 12:24
  • possible duplicate of [OS detecting makefile](http://stackoverflow.com/questions/714100/os-detecting-makefile) – user694733 Nov 12 '13 at 12:25
  • In that case use these checks to set e.g. `CP` and `RM` variables, which does the right thing. – Some programmer dude Nov 12 '13 at 12:30
  • @user694733: Yes, thanks, it is similar, but I am talking about Windows only. – Zdenek Prusa Nov 12 '13 at 12:32
  • @Joachim Pileborg The problem is now which enviroment variable..I see that cmd has SystemRoot and msys has SYSTEMROOT :) – Zdenek Prusa Nov 12 '13 at 12:35
  • Did you try setting the SHELL makefile variable to the command processor you want (probably the full path to cmd.exe). If the make program is not too different from what is used under Unix, that should work in both environment. – AProgrammer Nov 12 '13 at 15:47
  • Setting the SHELL to the full path to cmd.exe seems to be working. Thanks. Now I need to figure out how to include it in my build system and not to break much ;) – Zdenek Prusa Nov 12 '13 at 16:38

2 Answers2

1

I met the same condition with you. I add MSYS directory to PATH environment virable, and it works well.

eastdys
  • 11
  • 3
-4

Add msys to the path as in the picture:

enter image description here

Floern
  • 33,559
  • 24
  • 104
  • 119