I'm currently in the process of porting a C project that I originally developed on Linux to a Windows environment using Mingw. I've successfully compiled and run the project on Linux after making some necessary code changes. To test its compatibility on Windows, I used Wine and ran it on an actual Windows machine, where it worked flawlessly.
Now, my goal is to compile the project directly on a Windows machine. I've installed Mingw on the Windows system, and I'm attempting to use the mingw32-make command. The compiler is being called successfully, and I've managed to create folders exchanging the following rule
$(RELEASE_ODIRS) $(RELEASE_DDIRS):
mkdir -p $@
by the this new cross-platform rule:
$(RELEASE_ODIRS) $(RELEASE_DDIRS):
ifeq ($(PLATFORM), Windows)
if not exist $(subst /,\,$@) mkdir $(subst /,\,$@)
else
mkdir -p $@
endif
Hovewer, I've encountered an issue when trying to replace the mv -f command in my Makefile with move. Specifically, the make process fails with the following error:
process_begin: CreateProcess(NULL, move release\.deps\input_stream.Td release\.deps\input_stream.d, ...) failed.
make (e=2): The system cannot find the file specified.
Interestingly, if I run the move command directly in the Windows Command Prompt (cmd), it works without any issues. My question is twofold: Why can't Make find the move utility, while it can locate mkdir successfully? Additionally, I'd appreciate any tips or insights on how to streamline the porting process without creating a separate build script specifically for Windows. My aim is to use the same Makefile for both environments.
If I open a Command Prompt and type
where moveto tell me wheremove.exeis located in thePATHit can't find it.But if I run
move /?I do get the help.So it looks like it's a built-in command, not an external application, so you can't call it from
Makefile, unless you use it from the shell with something likeCMD /C move.Solution
When porting to Windows using tools like autoconf and make it's a lot easier to use MSYS2 shell, which provides a bash shell for native Windows allowing you to use your unmodified build files (like
Makefileor even./configure).Alternative
An alternative solution could be to move away from make and use another cross-platform build system. A good candidate is CMake in combination with Ninja, which both work well on Windows.