I’m trying to add functionality to a makefile that currently runs under both Windows and Linux. The functionality I want to add is creating the object and bin directories in the directory tree, if they don’t exist, and just continue if they do.
With Linux it’s easy. If the directories are already there, Linux shuts up and there is no error. In Windows, cmd spits out an error code of 1 which causes make to recognize an error. I’m stuck as to makefile code I could use for the windows side to either ignore the error completely, or only create the directories if they are not there. As an example, here is some code I have to detect which platform, and to deal with the “/” vs. “”. The first time through it works on Windows, but only the first time.
#convert from '/' to '' for windows targets
# Use '$/' in make directives for proper path substitutions to ''
/ := $(if $(filter Windows_NT, $(OS)),,/)
export /
#Example: BINPATH=OFC$/obj$/bin
# result: BINPATH=OFCobjbin
ifeq ($(OS),Windows_NT)
OSFLAG=win
EXT=.exe
ENABLEEXT=setlocal enableextensions
MKDIR=$(ENABLEEXT) & mkdir
WIN=true
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
OSFLAG=lnx
MKDIR=mkdir -p
endif
ifeq ($(UNAME_S),Darwin)
OSFLAG=mac
MKDIR=mkdir -p
endif
endif
SRCDIR=src
OBJDIR=$(OSFLAG)obj
BINDIR=$(OSFLAG)bin
MANDIR=man
BUILDTREE := $(SRCDIR) $(OBJDIR) $(MANDIR) $(BINDIR)
.PHONY: all
all: dirs
.PHONY:dirs
dirs:
$(MKDIR) $(BUILDTREE)
Can one of you be kind enough to give me a little push as to something that would work?