help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Running specific part of a Makefile under a specific shell


From: peter0x44
Subject: Running specific part of a Makefile under a specific shell
Date: Thu, 10 Feb 2022 23:15:43 +0000

Hi all,
I have a Makefile that is intended for running under both Windows and Linux, for the raylib library.
https://github.com/raysan5/raylib/blob/master/src/Makefile

This Makefile, under Windows, for the `make clean` target uses the del builtin command of cmd.exe to delete files.

clean:
ifeq ($(PLATFORM_OS),WINDOWS)
        del *.o /s
        cd $(RAYLIB_RELEASE_PATH)
        del lib$(RAYLIB_LIB_NAME).a /s
        del lib$(RAYLIB_LIB_NAME)dll.a /s
        del $(RAYLIB_LIB_NAME).dll /s
else

However, that the shell is always cmd.exe is a bad assumption on Windows, as this won't be true if GNU Make finds sh.exe in the PATH, so this target will fail in those circumstances. I am aware I can change the shell used to run build rules with the variable SHELL, `make clean SHELL=cmd` always works. But I would rather not have to enforce this under those situations, and allow the same command to work by default regardless of whether the shell is sh.exe or cmd.exe.

Is there a way I can change the shell *right before* running the del command? inserting SHELL = cmd before it will result in it being interpreted as a shell command, that obviously fails. I'm not experienced enough with Makefiles to know the proper syntax to do this, or if it is even possible, so that is why I am asking here.

The reason I only wish to do this for the `make clean` target, and not run the entire Makefile under cmd.exe is because this same Makefile is also used to cross-compile the library from another OS, so this will cause the entire Makefile to fail on those operating systems.

Thanks for your time,
Peter D.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]