mk/util.mk
2012-07-25 09:03:00 +02:00

133 lines
2.5 KiB
Makefile

ifndef HAS_UTIL_MK
HAS_UTIL_MK := T
MK_DIR := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST))))
ifneq (,$(or $(ComSpec),$(COMSPEC),$(comspec)))
ifneq (Cygwin,$(shell uname -a))
NULL := /dev/null
fixpath = $(1)
emacspath = $(foreach f,$(1),$(shell cygpath -ma $(f)))
else ifneq (,$(MSYSTEM))
fixpath = $(foreach f,$(1),$(if $(subst $(f),,$(subst :,,$(f))),\
$(subst //,/,/$(firstword $(subst :, ,$(f)))$(subst \,/,$(lastword $(subst :, ,$(f))))),$(f)))
ifneq (,$(filter MSYS% MINGW%,$(MSYSTEM)))
#$(info test: $(filter MSYS% MINGW%,$(MSYSTEM)))
emacspath = $(foreach f,$(1),$(subst /,\\\\,$(shell cd $(f)&&pwd -W)))
else
RM := del
DIRSEP := $(if T,\)
SHQ := ^
RD := rmdir /q /s
endif
endif
endif
# define the $(\n) macro which has the value '\n'
# Note: This really requires two empty lines!
ifndef \n
define \n
endef
endif
# define the $, or $(,) macro which has the value ','
ifndef ,
, := ,
endif
ifndef comma
comma := ,
endif
# define the $(sp) macro which has the value ' '
ifndef blank
blank :=
endif
ifndef sp
sp := $(blank) $(blank)
endif
# define the $= or $(=) macro which has the value '='
ifndef equals
equals := =
endif
ifndef $(equals)
$(equals) := =
endif
# define the $# or $(#) macro which has the value '#'
ifndef \#
hash := \#
endif
ifndef $(hash)
$(hash) := \#
endif
# define the $: or $(:) macro which has the value ':'
ifndef colon
colon := :
endif
ifndef $(colon)
$(colon) := :
endif
# define the $($$) macro which has the value '$'
ifndef dollar
dollar := $$
endif
ifndef $(dollar)
$(dollar) := $$
endif
#define macros for '(' and ')'
ifndef oparen
oparen := (
endif
ifndef cparen
cparen := )
endif
dummy :=
sp := $(dummy) $(dummy)
PARENO := (
PARENC := )
DIRSEP ?= /
SHQ ?= $(if T,\)
emacspath ?= $(1)
fixpath ?= $(1)
TEST := test
RD ?= rm -rf
NULL ?= $(or $(wildcard /dev/null),nul)
ifeq (T,$(V))
mk-debug = $(info $1)
mk-debug-lno = $(warning $(\n)$1)
mk-debug-vars = $(foreach _mkv,$1,$(info $(_mkv) := '$($(_mkv))'))
endif
define include-once-helper
ifndef $(subst ?,_,$(subst /,_,$2))-included
ifneq (,$(wildcard $2))
$(subst ?,_,$(subst /,_,$2))-included := T
$$(call mk-debug-lno,+ including '$1')
include $2
else
$$(call mk-debug-lno,[WARN] could not find '$1')
endif
endif
endef
include-once = $(eval $(call include-once-helper,$1,$(subst $(sp),?,$1)))
# END: HAS_UTIL_MK
endif
# Local Variables:
# tab-width: 2
# End: