Annotation of pkgsrc/mk/pkgformat/pkg/scripts.mk, revision 1.5

1.5     ! jperkin     1: # $NetBSD: scripts.mk,v 1.4 2017/06/07 20:24:09 jlam Exp $
1.1       jlam        2: #
                      3: # Copyright (c) 2017 The NetBSD Foundation, Inc.
                      4: # All rights reserved.
                      5: #
                      6: # This code is derived from software contributed to The NetBSD Foundation
                      7: # by Johnny C. Lam.
                      8: #
                      9: # Redistribution and use in source and binary forms, with or without
                     10: # modification, are permitted provided that the following conditions
                     11: # are met:
                     12: # 1. Redistributions of source code must retain the above copyright
                     13: #    notice, this list of conditions and the following disclaimer.
                     14: # 2. Redistributions in binary form must reproduce the above copyright
                     15: #    notice, this list of conditions and the following disclaimer in the
                     16: #    documentation and/or other materials provided with the distribution.
                     17: #
                     18: # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
                     19: # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
                     20: # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
                     21: # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
                     22: # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
                     23: # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
                     24: # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
                     25: # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
                     26: # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
                     27: # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
                     28: # POSSIBILITY OF SUCH DAMAGE.
                     29: 
                     30: # This Makefile fragment provides the targets to make the +DEINSTALL
                     31: # and +INSTALL scripts and hooks into metadata.mk to automatically
                     32: # generate them as needed.
                     33: 
                     34: # HEADER_TEMPLATES
                     35: #      List of package-provided template files to be concatenated
                     36: #      into a header for the install and deinstall scripts.  The
                     37: #      concatenated files are placed after the main header template
                     38: #      file.
                     39: #
                     40: # DEINSTALL_TEMPLATES
                     41: #      List of package-provided template files to be concatenated
                     42: #      to form the body of the deinstall script.  The concatenated
                     43: #      files are placed before the main deinstall template file.
                     44: #      The script templates should exit with a code >0 if an error
                     45: #      occurs.
                     46: #
                     47: # INSTALL_TEMPLATES
                     48: #      List of package-provided template files to be concatenated
                     49: #      to form the body of the install script.  The concatenated
                     50: #      files are placed after the main install template file.  The
                     51: #      script templates should exit with a code >0 if an error
                     52: #      occurs.
                     53: #
                     54: _HEADER_TMPL=          ${PKGSRCDIR}/mk/pkgformat/pkg/templates/header
                     55: HEADER_TEMPLATES?=     # empty
                     56: .for _file_ in ${PKGDIR}/HEADER
                     57: .  if exists(${_file_}) && empty(HEADER_TEMPLATES:M${_file_})
                     58: HEADER_TEMPLATES+=     ${_file_}
                     59: .  endif
                     60: .endfor
                     61: _DEINSTALL_TMPL=       ${PKGSRCDIR}/mk/pkgformat/pkg/templates/deinstall
                     62: DEINSTALL_TEMPLATES?=  # empty
                     63: .for _file_ in ${PKGDIR}/DEINSTALL
                     64: .  if exists(${_file_}) && empty(DEINSTALL_TEMPLATES:M${_file_})
                     65: DEINSTALL_TEMPLATES+=  ${_file_}
                     66: .  endif
                     67: .endfor
                     68: _INSTALL_TMPL=         ${PKGSRCDIR}/mk/pkgformat/pkg/templates/install
                     69: INSTALL_TEMPLATES?=    # empty
                     70: .for _file_ in ${PKGDIR}/INSTALL
                     71: .  if exists(${_file_}) && empty(INSTALL_TEMPLATES:M${_file_})
                     72: INSTALL_TEMPLATES+=    ${_file_}
                     73: .  endif
                     74: .endfor
                     75: _FOOTER_TMPL?=         ${PKGSRCDIR}/mk/pkgformat/pkg/templates/footer
                     76: 
                     77: # DEINSTALL_SRC
                     78: # INSTALL_SRC
                     79: #      List of source files that are concatenated to form the
                     80: #      deinstall and install scripts.
                     81: #
                     82: .if ( "${USE_PKGTASKS:tl}" == "yes" ) || !empty(HEADER_TEMPLATES) ||   \
                     83:     !empty(DEINSTALL_TEMPLATES) || !empty(INSTALL_TEMPLATES)
1.2       jlam       84: USE_PKGTASKS=          yes     # script templates use pkgtasks
1.1       jlam       85: DEINSTALL_SRC?=                ${_HEADER_TMPL} ${HEADER_TEMPLATES}             \
                     86:                        ${DEINSTALL_TEMPLATES} ${_DEINSTALL_TMPL}       \
                     87:                        ${_FOOTER_TMPL} ${PKGTASKS_DATAFILE}
                     88: INSTALL_SRC?=          ${_HEADER_TMPL} ${HEADER_TEMPLATES}             \
                     89:                        ${_INSTALL_TMPL} ${INSTALL_TEMPLATES}           \
                     90:                        ${_FOOTER_TMPL} ${PKGTASKS_DATAFILE}
                     91: .else
                     92: DEINSTALL_SRC?=                # empty
                     93: INSTALL_SRC?=          # empty
                     94: .endif
                     95: 
                     96: # _DEINSTALL_FILE
                     97: #      The location of the file to be added as the deinstall script
                     98: #      for the package.
                     99: #
                    100: #      Possible: any valid path
                    101: #      Default: ${PKG_DB_TMPDIR}/+DEINSTALL
                    102: #
                    103: # _INSTALL_FILE
                    104: #      The location of the file to be added as the install script
                    105: #      for the package.
                    106: #
                    107: #      Possible: any valid path
                    108: #      Default: ${PKG_DB_TMPDIR}/+INSTALL
                    109: #
                    110: # _pkgformat-generate-install-scripts (PRIVATE)
                    111: #      Convenience target to generate the deinstall and install
                    112: #      scripts for the package.
                    113: #
                    114: 
                    115: .if !empty(DEINSTALL_SRC)
                    116: _DEINSTALL_FILE=       ${PKG_DB_TMPDIR}/+DEINSTALL
                    117: 
                    118: ${_DEINSTALL_FILE}: ${DEINSTALL_SRC}
1.5     ! jperkin   119:        ${RUN}                                                          \
        !           120:        ${TEST} -d ${.TARGET:H:Q} || ${MKDIR} ${.TARGET:H:Q};           \
        !           121:        ${SED} ${FILES_SUBST_SED} ${.ALLSRC} > ${.TARGET}.tmp;          \
        !           122:        ${CHMOD} +x ${.TARGET}.tmp;                                     \
        !           123:        ${MV} -f ${.TARGET}.tmp ${.TARGET}
1.1       jlam      124: .endif
                    125: .if !empty(INSTALL_SRC)
                    126: _INSTALL_FILE=         ${PKG_DB_TMPDIR}/+INSTALL
                    127: 
                    128: ${_INSTALL_FILE}: ${INSTALL_SRC}
1.5     ! jperkin   129:        ${RUN}                                                          \
        !           130:        ${TEST} -d ${.TARGET:H:Q} || ${MKDIR} ${.TARGET:H:Q};           \
        !           131:        ${SED} ${FILES_SUBST_SED} ${.ALLSRC} > ${.TARGET}.tmp;          \
        !           132:        ${CHMOD} +x ${.TARGET}.tmp;                                     \
        !           133:        ${MV} -f ${.TARGET}.tmp ${.TARGET}
1.1       jlam      134: .endif
                    135: 
                    136: .PHONY: _pkgformat-generate-install-scripts
                    137: _pkgformat-generate-install-scripts: ${_DEINSTALL_FILE} ${_INSTALL_FILE}
                    138: 
                    139: # Hook into pkgsrc/mk/pkgformat/pkg/metadata.mk to automatically generate
                    140: # the deinstall and install scripts if needed.
                    141: #
                    142: _METADATA_TARGETS+=    ${_DEINSTALL_FILE} ${_INSTALL_FILE}
                    143: 
                    144: ###
                    145: # Variable substitutions for the scripts.
                    146: 
                    147: FILES_SUBST+=  PKGBASE=${PKGBASE:Q}
                    148: 
                    149: # Variables for programs for use by script templates.
                    150: FILES_SUBST+=  BASENAME=${BASENAME:Q}
                    151: FILES_SUBST+=  CHGRP=${CHGRP:Q}
                    152: FILES_SUBST+=  CMP=${CMP:Q}
                    153: FILES_SUBST+=  DIRNAME=${DIRNAME:Q}
                    154: FILES_SUBST+=  ECHO=${ECHO:Q}
                    155: FILES_SUBST+=  ECHO_N=${ECHO_N:Q}
                    156: FILES_SUBST+=  EGREP=${EGREP:Q}
                    157: FILES_SUBST+=  EXPR=${EXPR:Q}
                    158: FILES_SUBST+=  FALSE=${FALSE:Q}
                    159: FILES_SUBST+=  GREP=${GREP:Q}
                    160: FILES_SUBST+=  GTAR=${GTAR:Q}
                    161: FILES_SUBST+=  HEAD=${HEAD:Q}
                    162: FILES_SUBST+=  PERL5=${PERL5:Q}
                    163: FILES_SUBST+=  PWD_CMD=${PWD_CMD:Q}
                    164: FILES_SUBST+=  SETENV=${SETENV:Q}
                    165: FILES_SUBST+=  SH=${SH:Q}
                    166: FILES_SUBST+=  SU=${SU:Q}
                    167: FILES_SUBST+=  TEST=${TEST:Q}
                    168: FILES_SUBST+=  TOUCH=${TOUCH:Q}
                    169: FILES_SUBST+=  TR=${TR:Q}
                    170: FILES_SUBST+=  TRUE=${TRUE:Q}
                    171: FILES_SUBST+=  XARGS=${XARGS:Q}
                    172: 
                    173: # Variables for the pkg_install package tools.
1.4       jlam      174: FILES_SUBST+=  PKG_ADMIN=${PKG_ADMIN_CMD:Q}
                    175: FILES_SUBST+=  PKG_INFO=${PKG_INFO_CMD:Q}
1.1       jlam      176: 
                    177: # Variables for installation prefix references.
1.3       jlam      178: FILES_SUBST+=  CROSSBASE=${CROSSBASE:Q}
1.1       jlam      179: FILES_SUBST+=  LOCALBASE=${LOCALBASE:Q}
                    180: FILES_SUBST+=  X11BASE=${X11BASE:Q}
                    181: FILES_SUBST+=  PREFIX=${PREFIX:Q}
                    182: 
                    183: # Variables for the package configuration directory.
                    184: FILES_SUBST+=  PKG_SYSCONFBASE=${PKG_SYSCONFBASE:Q}
                    185: FILES_SUBST+=  PKG_SYSCONFBASEDIR=${PKG_SYSCONFBASEDIR:Q}
                    186: FILES_SUBST+=  PKG_SYSCONFDIR=${PKG_SYSCONFDIR:Q}
1.3       jlam      187: 
                    188: # Variables for the local state directory.
                    189: FILES_SUBST+=  VARBASE=${VARBASE:Q}

CVSweb <webmaster@jp.NetBSD.org>