Makefile that distincts between Windows and Unix-like systems Makefile that distincts between Windows and Unix-like systems windows windows

Makefile that distincts between Windows and Unix-like systems


I solved this by looking for an env variable that will only be set on windows.

ifdef OS   RM = del /Q   FixPath = $(subst /,\,$1)else   ifeq ($(shell uname), Linux)      RM = rm -f      FixPath = $1   endifendifclean:    $(RM) $(call FixPath,objs/*)

Because %OS% is the type of windows, it should be set on all Windows computers but not on Linux.

The blocks then setups up variables for the different programs as well as a function for converting the forward slashes into backslashes.

You to have to use $(call FixPath,path) when you call an outside command (internal commands work fine). You could also use something like:

/ := /

and then

objs$(/)*

if you like that format better.


The SystemRoot trick didn't work for me on Windows XP but this did:

ifeq ($(OS),Windows_NT)    #Windows stuff    ...else    #Linux stuff    ....endif


You should probably use the $(RM) variable to remove some files.