[Top][All Lists]

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

Running specific part of a Makefile under a specific shell

From: thutt
Subject: Running specific part of a Makefile under a specific shell
Date: Fri, 11 Feb 2022 06:46:48 -0800

peter0x44 writes:
 > Hi all,
 > I have a Makefile that is intended for running under both Windows and 
 > Linux, for the raylib library.
 > This Makefile, under Windows, for the `make clean` target uses the del 
 > builtin command of cmd.exe to delete files.
 > clean:
 >          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.

Try the following:

$(if $(filter $(HOSTOS),linux windows),,$(error HostOS not set to (linux | 

clean:  clean_$(HOSTOS)
        @echo "Cleaned";

clean_windows:  SHELL:=cmd.exe

        @echo "$@: SHELL is set to '$(SHELL)'"

        @echo "$@: SHELL is set to '$(SHELL)'"

It's a good general pattern for removing conditionalization in
Makefiles -- making them easier to read, IMHO.

 > 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.

The TIA-232 is way better than the RS-232.

reply via email to

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