[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.
> https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fraysan5%2Fraylib%2Fblob%2Fmaster%2Fsrc%2FMakefile&data=04%7C01%7Cthutt%40vmware.com%7C94bfbd5076e74e217f3808d9ecf84394%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C0%7C1%7C637801373333085947%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=PGZlG3XNgbWY%2BPZt9ebcCAJU848kQOHAU7ggfiNV8G4%3D&reserved=0
>
> 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.
Try the following:
$(if $(filter $(HOSTOS),linux windows),,$(error HostOS not set to (linux |
windows)))
clean: clean_$(HOSTOS)
@echo "Cleaned";
clean_windows: SHELL:=cmd.exe
clean_windows:
@echo "$@: SHELL is set to '$(SHELL)'"
clean_linux:
@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.