Subversion Repositories DevTools

Rev

Rev 245 | Rev 257 | 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

#
###############################################################################
# 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

#
###############################################################################
# Verbose versions of specific commands
###############################################################################
#

ifdef VERBOSE
GBE_RM          =$(rm)
GBE_RMDIR       =$(rmdir)
else
GBE_RM          =@$(rm)
GBE_RMDIR       =@$(rmdir)
endif

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

#.. Remove files contained within the specified list
#
#   Usage:      $(call RmFiles,VARIABLE_NAME)
#
define RmFiles
        @(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)
#
#               Note: dest, file and path
#                   may have spaces in them
#                   These will have been escaped with a'\' which will
#                   need to be removed.
#
#                   May have '$' in themwhich we will need to escape
#
define CopyFile
        @(dest="$(subst \$(space),$(space),$(subst $$,\$$,$(2)))"; \
        file="$(subst \$(space),$(space),$(subst $$,\$$,$(3)))"; \
        path="$(subst \$(space),$(space),$(subst $$,\$$,$(4)))"; \
        fmode="$(5)"; \
        echo ------ "$1 $$dest"; \
        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
        @(file="$(subst \$(space),$(space),$(subst $$,\$$,$(2)))"; \
        echo ------ $1 "$$file"; \
        if [ -f "$$file" ]; then \
                if [ ! -w "$$file" ]; then $(chmod) -f +w "$$file"; fi; \
                $(rm) -f "$$file"; \
        fi);
endef

##