Home | History | Annotate | Download | only in core
      1 # Copyright (C) 2009 The Android Open Source Project
      2 #
      3 # Licensed under the Apache License, Version 2.0 (the "License");
      4 # you may not use this file except in compliance with the License.
      5 # You may obtain a copy of the License at
      6 #
      7 #      http://www.apache.org/licenses/LICENSE-2.0
      8 #
      9 # Unless required by applicable law or agreed to in writing, software
     10 # distributed under the License is distributed on an "AS IS" BASIS,
     11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 # See the License for the specific language governing permissions and
     13 # limitations under the License.
     14 #
     15 
     16 # These definitions contain a few host-specific functions. I.e. they are
     17 # typically used to generate shell commands during the build and their
     18 # implementation will depend on the value of the HOST_OS variable.
     19 #
     20 
     21 # -----------------------------------------------------------------------------
     22 # Function : host-path
     23 # Arguments: 1: file path
     24 # Returns  : file path, as understood by the host file system
     25 # Usage    : $(call host-path,<path>)
     26 # Rationale: This function is used to translate Cygwin paths into
     27 #            Cygwin-specific ones. On other platforms, it will just
     28 #            return its argument.
     29 # -----------------------------------------------------------------------------
     30 ifeq ($(HOST_OS),cygwin)
     31 host-path = $(if $(strip $1),$(call cygwin-to-host-path,$1))
     32 else
     33 host-path = $1
     34 endif
     35 
     36 # -----------------------------------------------------------------------------
     37 # Function : host-rm
     38 # Arguments: 1: list of files
     39 # Usage    : $(call host-rm,<files>)
     40 # Rationale: This function expands to the host-specific shell command used
     41 #            to remove some files.
     42 # -----------------------------------------------------------------------------
     43 ifeq ($(HOST_OS),windows)
     44 host-rm = \
     45     $(eval __host_rm_files := $(foreach __host_rm_file,$1,$(subst /,\,$(wildcard $(__host_rm_file)))))\
     46     $(if $(__host_rm_files),del /f/q $(__host_rm_files) >NUL 2>NUL)
     47 else
     48 host-rm = rm -f $1
     49 endif
     50 
     51 # -----------------------------------------------------------------------------
     52 # Function : host-rmdir
     53 # Arguments: 1: list of files or directories
     54 # Usage    : $(call host-rm,<files>)
     55 # Rationale: This function expands to the host-specific shell command used
     56 #            to remove some files _and_ directories.
     57 # -----------------------------------------------------------------------------
     58 ifeq ($(HOST_OS),windows)
     59 host-rmdir = \
     60     $(eval __host_rmdir_files := $(foreach __host_rmdir_file,$1,$(subst /,\,$(wildcard $(__host_rmdir_file)))))\
     61     $(if $(__host_rmdir_files),del /f/s/q $(__host_rmdir_files) >NUL 2>NUL)
     62 else
     63 host-rmdir = rm -rf $1
     64 endif
     65 
     66 # -----------------------------------------------------------------------------
     67 # Function : host-mkdir
     68 # Arguments: 1: directory path
     69 # Usage    : $(call host-mkdir,<path>
     70 # Rationale: This function expands to the host-specific shell command used
     71 #            to create a path if it doesn't exist.
     72 # -----------------------------------------------------------------------------
     73 ifeq ($(HOST_OS),windows)
     74 host-mkdir = md $(subst /,\,"$1") >NUL 2>NUL || rem
     75 else
     76 host-mkdir = mkdir -p $1
     77 endif
     78 
     79 # -----------------------------------------------------------------------------
     80 # Function : host-cp
     81 # Arguments: 1: source file
     82 #            2: target file
     83 # Usage    : $(call host-cp,<src-file>,<dst-file>)
     84 # Rationale: This function expands to the host-specific shell command used
     85 #            to copy a single file
     86 # -----------------------------------------------------------------------------
     87 ifeq ($(HOST_OS),windows)
     88 host-cp = copy /b/y $(subst /,\,"$1" "$2") > NUL
     89 else
     90 host-cp = cp -f $1 $2
     91 endif
     92 
     93 # -----------------------------------------------------------------------------
     94 # Function : host-install
     95 # Arguments: 1: source file
     96 #            2: target file
     97 # Usage    : $(call host-install,<src-file>,<dst-file>)
     98 # Rationale: This function expands to the host-specific shell command used
     99 #            to install a file or directory, while preserving its timestamps
    100 #            (if possible).
    101 # -----------------------------------------------------------------------------
    102 ifeq ($(HOST_OS),windows)
    103 host-install = copy /b/y $(subst /,\,"$1" "$2") > NUL
    104 else
    105 host-install = install -p $1 $2
    106 endif
    107 
    108 # -----------------------------------------------------------------------------
    109 # Function : host-c-includes
    110 # Arguments: 1: list of file paths (e.g. "foo bar")
    111 # Returns  : list of include compiler options (e.g. "-Ifoo -Ibar")
    112 # Usage    : $(call host-c-includes,<paths>)
    113 # Rationale: This function is used to translate Cygwin paths into
    114 #            Cygwin-specific ones. On other platforms, it will just
    115 #            return its argument.
    116 # -----------------------------------------------------------------------------
    117 ifeq ($(HOST_OS),cygwin)
    118 host-c-includes = $(patsubst %,-I%,$(call host-path,$1))
    119 else
    120 host-c-includes = $(1:%=-I%)
    121 endif
    122 
    123 # -----------------------------------------------------------------------------
    124 # Function : host-copy-if-differ
    125 # Arguments: 1: source file
    126 #            2: destination file
    127 # Usage    : $(call host-copy-if-differ,<src-file>,<dst-file>)
    128 # Rationale: This function copy source file to destination file if contents are
    129 #            different.
    130 # -----------------------------------------------------------------------------
    131 ifeq ($(HOST_OS),windows)
    132 host-copy-if-differ = $(HOST_CMP) -s $1 $2 > NUL || copy /b/y $(subst /,\,"$1" "$2") > NUL
    133 else
    134 host-copy-if-differ = $(HOST_CMP) -s $1 $2 > /dev/null 2>&1 || cp -f $1 $2
    135 endif
    136 
    137