Subversion Repositories DevTools

Rev

Rev 261 | Rev 321 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

# -*- mode: mak; tabs: 8; -*-
#
##############################################################################
# Compat for older (embedded) makefiles
##############################################################################
#

SCM_ROOT        = $(GBE_ROOT)
SCM_TYPE        = $(GBE_TYPE)
SCM_BIN         = $(GBE_BIN)
SCM_PLATFORM    = $(GBE_PLATFORM)

#
###############################################################################
# Common definitions extracted from OPTIONS
##############################################################################
#
CC_PRE      := @
XX_PRE      := @
AA_PRE      := @

SHOWARGS    := NONE

USE_FILTER  := 1
LEAVETMP    :=
SHOWENV     :=

ifdef OPTIONS

ifneq "$(findstring args,$(OPTIONS))" ""        # Show arguments (default)
CC_PRE :=
XX_PRE :=
SHOWARGS := ARGS
endif

ifneq "$(findstring noargs,$(OPTIONS))" ""      # Show no arguments
CC_PRE := @
XX_PRE := @
SHOWARGS := NONE
endif

ifneq "$(findstring allargs,$(OPTIONS))" ""     #  Show ALL arguments
AA_PRE :=
SHOWARGS := ALL
endif

ifneq "$(findstring filter,$(OPTIONS))" ""      # Use filter (Default)
USE_FILTER := 1
endif

ifneq "$(findstring nofilter,$(OPTIONS))" ""    # Don't use filter
USE_FILTER  :=
endif

ifneq "$(findstring leavetmp,$(OPTIONS))" ""    # Leave temp files
LEAVETMP := 1
endif

ifneq "$(findstring noleavetmp,$(OPTIONS))" ""  # Don't leave temp files (Default)
LEAVETMP :=
endif

ifneq "$(findstring showenv,$(OPTIONS))" ""     # Display env before commands
SHOWENV := 1
endif

ifneq "$(findstring noshowenv,$(OPTIONS))" ""   # Don't display env before commands
SHOWENV :=
endif

endif

#
###############################################################################
# Brain hurts stuff... $(space) becomes a macro containing 1 space
# other aren't so bad.  These are used to make argument lists is a few 
# places where we have to translate from a space seperated list to a 
# something else seperated list (or vicky verka).
###############################################################################
#
comma           := ,
plus            := +
semicolon       := ;
empty           := 
space           := $(empty) $(empty)
spacealt        := %20

#
###############################################################################
# Macros to assist in the handling of paths with spaces
#       encodepath - Uses spacealt, uses /, space-sep-list
#                    Used to conatins lists of paths that may contain
#                    spaces. Used for INCLUDE and LIB paths
#
#       decodepath - Decodes an encoded path-list.
#                    User specifies the item prefix and suffix.
#                    Return list uses \ and may have spaces in pathnames
#                    Prefix items with 1st-arg
#                    Join items with 2nd arg
#
# Usage:
#       aa = $(call encodepath,c:\Program Files)
#       $(call decodepath,-I,;,$(aa))
#
###############################################################################
#
encodepath = $(subst //,/,$(subst \,/,$(subst $(space),$(spacealt),$(strip $(1)))))
decodepath = $(subst $(spacealt),$(space),$(subst $(space),$(empty),$(patsubst %,$(1)%$(2),$(subst /,\,$(3)))))

#
###############################################################################
#
#  Macros to convert relative to absolute paths
#
#   Work around for a bug in make 3.81 where abspath assumes that the input
#   is a relative path. The work around checks for paths that have a : or start
#   with a '/ - and assumes these are absolute.
#   It will only call makes 'abspath' for relative paths.
#
###############################################################################
#
myabspath = $(foreach dir,$1,$(call myabs1path,$(dir)))
myabs1path = $(if $(or $(findstring :,$1),$(filter /%,$1)),$1,$(abspath $1))

#
###############################################################################
# A little macro used within each of the rules for translating a file from 
# one type to another to print the environment if the variable SHOWENV has 
# been defined.
###############################################################################
#
ifdef SHOWENV
define show_environment
                $(printenv)
endef
else
define show_environment
endef
endif

#
################################################################################
# A macro to dump out command files if the ARGS or ALLARGS option is set
# Usage: $(call show_cmdfile,<PathOfCommandFile>)
################################################################################
#
ifeq ($(SHOWARGS),NONE)
show_cmdfile =
else
show_cmdfile = echo "Using command file: $(1)";cat $(1);echo "End of Command file"
endif

#
###############################################################################
# Support macros
###############################################################################
#

#.. Remove files contained within the specified list
#
#   Usage:      $(call RmFiles,VARIABLE_NAME)
#
define RmFiles
        $(AA_PRE)(if [ "$(GBE_VERBOSE)" -gt 0 ]; then \
                echo Removing $($(1)); fi; \
        CHOWNS=; \
        RMS=; \
        for file in $($(1)); do \
                if [ -f $$file -o -h $$file ]; then \
                        if [ ! -w $$file ]; then \
                                CHOWNS="$$CHOWNS $$file"; \
                        fi; \
                        RMS="$$RMS $$file"; \
                fi; \
        done; \
        if [ -n "$$RMS" ]; then \
                if [ -n "$$CHOWNS" ]; then \
                        $(chmod) -f +w $$CHOWNS; \
                fi; \
                $(rm) -f $$RMS; \
        fi);
endef

#.. Install/uninstall the specified file
#
#   Usage:      $(call InstallFile,dest,file,path,fmode)
#               $(call UninstallFile,file)
#
define InstallFile
    $(call CopyFile,installing,$1,$2,$3,$4)
endef

define UninstallFile
    $(call UncopyFile,uninstalling,$1)
endef

#.. Package/Unpackage the specified file
#
#   Usage:      $(call PackageFile,dest,file,path,fmode)
#               $(call UnpackageFile,file)
#
define PackageFile
    $(call CopyFile,packaging,$1,$2,$3,$4)
endef

define UnpackageFile
    $(call UncopyFile,unpackaging,$1)
endef

#.. Generic Copy/Remove the specified file
#
#   Usage:      $(call CopyFile,Text,dest,file,path,fmode)
#               $(call UncopyFile,Text,file)
#
#   Notes:
#       dest, file and path
#       May have spaces in them
#               These will have been escaped with a '\' which will
#               need to be removed. The '\ ' is required to keep make
#               happy elsewhere.
#
#       May have '$' in them which we will need to escape
#
#       Windows copy has limitations.
#               Abs path length must < 260
#               Passing a relative path does not solve the problem
#               Moreover, if the relative path contains one or more ../
#               sequences, then the 'cp' command creates a complete path
#               before removing the zzz/.. sequences - and this must not exceed
#               259 characters.
#
#               At the moment we get the most out of the windows 'cp' by
#               passing it a clean absolute pathname, but there is still
#               a limit of ~259 characters. This affects many programs, not just
#               cp but make, rm, chmod ...
#
#
#       Nice Macros
#       AbsName - convert a '\ ' pathname into an absolute path with plain spaces
#                 and $ escaped with a \.
#                 In the process 'spaces' need to be replaced with something to
#                 keep abspath from splitting on space.
#       NiceName - convert a '\ ' pathname into an string with plain spaces
#                 and $ escaped with a \.
#
AbsName = $(subst $$,\$$,$(subst $(spacealt),$(space),$(abspath $(subst \$(space),$(spacealt),$1))))
NiceName = $(subst $$,\$$,$(subst \$(space),$(space),$1))

define CopyFile
        $(AA_PRE)(\
        udest="$(call NiceName,$2)"; \
        dest="$(call AbsName,$2)"; \
        file="$(call NiceName,$3)"; \
        path="$(call AbsName,$4)"; \
        fmode="$(5)"; \
        echo "------ $1 $$udest"; \
        if [ ! -f "$$file" ] ; then echo "$1 source file not found: $$file" ; exit 1; fi;\
        if [ ! -d "$$path" ] ; then $(mkdir) -p "$$path"; fi; \
        if [ -f "$$dest" -a ! -w "$$dest" ]; then $(chmod) -f +w "$$dest"; fi; \
        $(rm) -f "$$dest"; \
        $(cp) "$$file" "$$dest" ;\
        if [ $$? -gt 0 ] ; then echo "$1 copy error" ; exit 1; fi ;\
        $(if $(5),$(chmod) -f $$fmode "$$dest") ; \
        if [ ! -f "$$dest" ] ; then echo "$1 file not found after copy: $$dest" ; exit 1; fi; \
        );
endef

define UncopyFile
        $(AA_PRE)(\
        udest="$(call NiceName,$2)"; \
        file="$(call AbsName,$2)"; \
        echo "------ $1 $$udest"; \
        if [ -f "$$file" ]; then \
                if [ ! -w "$$file" ]; then $(chmod) -f +w "$$file"; fi; \
                $(rm) -f "$$file"; \
        fi);
endef

##