##
##  @l_prefix@/etc/openpkg/rpmmacros -- RPM macros for @l_prefix@ hierarchy
##  Copyright (c) 2000-2001 Cable & Wireless Deutschland GmbH
##  Copyright (c) 2000-2001 Ralf S. Engelschall <rse@engelschall.com>
##
##  The purpose of this macro set is to override the default
##  macros in the RPM installation for the @l_prefix@ hierarchy.
##

#   the OpenPKG identification 
#   OpenPKG -CURRENT -> "YYYYMMDD"
#   OpenPKG -STABLE  -> "X.Y"
%l_branch                %(date '+%Y%m%d')

#   the platform identification
%l_target                %{_target}
%l_location              @LOC@

#   the user/group name/id pair for installed files
#   (because of bootstrapping issues the l_fs[ug]id cannot be cleanly pre-determined) 
%l_fsusr                 @FSUSR@
%l_fsuid                 %((cat /etc/passwd; ypcat passwd) 2>/dev/null | grep "^%{l_fsusr}:" | head -1 | awk -F: '{ print $3; }')
%l_fsgrp                 @FSGRP@
%l_fsgid                 %((cat /etc/group; ypcat group) 2>/dev/null | grep "^%{l_fsgrp}:" | head -1 | awk -F: '{ print $3; }')

#   the user/group name/id pair for non-priviledged operations
%l_npusr                 @NPUSR@
%l_npuid                 @NPUID@
%l_npgrp                 @NPGRP@
%l_npgid                 @NPGID@

#   the two root directories
%l_root_install          @l_prefix@
%l_root_rpm              @l_prefix@/RPM

#   define the installation hierarchy
%l_prefix                %{l_root_install}
%l_exec_prefix           %{l_root_install}
%l_bindir                %{l_root_install}/bin
%l_sbindir               %{l_root_install}/sbin
%l_libexecdir            %{l_root_install}/libexec
%l_datadir               %{l_root_install}/share
%l_sysconfdir            %{l_root_install}/etc
%l_sharedstatedir        %{l_root_install}/com
%l_localstatedir         %{l_root_install}/var
%l_libdir                %{l_root_install}/lib
%l_includedir            %{l_root_install}/include
%l_infodir               %{l_root_install}/info
%l_mandir                %{l_root_install}/man
%l_docdir                %{l_root_install}/doc

#   override the internal RPM hierarchy variables
%_usr                    %{l_root_rpm}
%_var                    %{l_root_rpm}
%_usrsrc                 %{l_root_rpm}
%_topdir                 %{l_root_rpm}
%_dbpath                 %{l_root_rpm}/DB
%_builddir               %{l_root_rpm}/TMP
%_tmppath                %{l_root_rpm}/TMP
%_sourcedir              %{l_root_rpm}/SRC/%{name}
%_specdir                %{l_root_rpm}/SRC/%{name}
%_rpmdir                 %{l_root_rpm}/PKG
%_srcrpmdir              %{l_root_rpm}/PKG
%_defaultdocdir          %{l_docdir}

#   complement the %{SOURCE<n>} and %{PATCH<n>} with %{SOURCE <file>} and %{PATCH <file>}
%SOURCE()                %(f="%1"; if [ -f "%{_specdir}/$f" ]; then echo "%{_specdir}/$f"; else echo "%{_sourcedir}/$f"; fi)
%PATCH()                 %(f="%1"; if [ -f "%{_specdir}/$f" ]; then echo "%{_specdir}/$f"; else echo "%{_sourcedir}/$f"; fi)

#   override RPM's absolute tool paths with relative ones
#   (because if you upgrade RPM it would hard-code tools in own hierarchy, too)
%__awk                   awk
%__bzip2                 %{_bzip2bin}
%__cat                   cat
%__chgrp                 chgrp
%__chmod                 chmod
%__chown                 chown
%__cp                    cp
%__cpio                  cpio
%__grep                  grep
%__gzip                  %{_gzipbin}
%__id                    id
%__install               install
%__ln_s                  ln -s
%__make                  make
%__mkdir                 mkdir
%__mkdir_p               %{l_prefix}/lib/openpkg/shtool mkdir -p
%__mv                    mv
%__patch                 %{_patchbin}
%__perl                  perl
%__pgp                   %{_pgpbin}
%__rm                    rm
%__rsh                   rsh
%__sed                   sed
%__ssh                   ssh
%__tar                   %{_tarbin}

#   provide fixed paths to tools (standard)
%_gzipbin                %{l_prefix}/lib/openpkg/gzip
%_bzip2bin               %{l_prefix}/lib/openpkg/bzip2
%_patchbin               %{l_prefix}/lib/openpkg/patch
%_tarbin                 %{l_prefix}/lib/openpkg/tar
%_buildshell             %{l_prefix}/lib/openpkg/bash

#   provide fixed paths to tools (additional)
%l_rpmtool               %{l_prefix}/sbin/rpmtool
%l_shtool                %{l_prefix}/lib/openpkg/shtool
%l_curl                  %{l_prefix}/lib/openpkg/curl
%l_bash                  %{l_prefix}/lib/openpkg/bash

#   provide smart paths to tools
%l_tool_check            test -f %{l_bindir}/$tool && tool="%{l_bindir}/$tool"; echo $tool
%l_gzip                  %(tool=gzip;     %{l_tool_check})
%l_bzip2                 %(tool=bzip2;    %{l_tool_check})
%l_tar                   %(tool=tar;      %{l_tool_check})
%l_cc                    %(tool=cc;       %{l_tool_check})
%l_cxx                   %(tool=c++;      %{l_tool_check})
%l_make                  %(tool=make;     %{l_tool_check})
%l_patch                 %(tool=patch;    %{l_tool_check})
%l_sed                   %(tool=sed;      %{l_tool_check})
%l_grep                  %(tool=grep;     %{l_tool_check})
%l_awk                   %(tool=awk;      %{l_tool_check})
%l_autoconf              %(tool=autoconf; %{l_tool_check})
%l_automake              %(tool=automake; %{l_tool_check})
%l_libtool               %(tool=libtool;  %{l_tool_check})
%l_flex                  %(tool=flex;     %{l_tool_check})
%l_bison                 %(tool=bison;    %{l_tool_check})
%l_perl                  %(tool=perl;     %{l_tool_check})
%l_xmkmf                 %(tool=xmkmf;    %{l_tool_check})

#   tool options
%l_mflags(O)             %(%{l_rpmtool} flags -m %{-O:-O} %{l_make})
%l_cflags(O)             %(%{l_rpmtool} flags -c %{-O:-O} %{l_cc})

#   determine the current username
%l_whoami                %((id -un) 2>/dev/null || (whoami) 2>/dev/null || (who am i | cut "-d " -f1) 2>/dev/null || echo $LOGNAME)

#   macros for dynamically generating a %files list
%l_files_defattr         '%defattr(-,%{l_fsusr},%{l_fsgrp})'
%l_files_all             '%{l_prefix}'
%l_files_noshared        '%not %dir {%{l_prefix},%{l_prefix}/*,%{l_prefix}/etc/rc.d,%{l_prefix}/man/*}'
%l_files_std(o:g:)       %l_files_defattr %l_files_all %l_files_noshared

#   path to local build root
%l_buildroot             %{_tmppath}/%{name}-%{version}-root

#   executable path for %post/%pre
%_install_script_path    @l_prefix@/bin:@l_prefix@/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin

#   override the name scheme for RPM files
%_rpmfilename            %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}-%%{OS}-@LOC@.rpm

#   override the payload compression for the CPIO parts of an RPM 
#   (we use the equivalent of "bzip2 -9")
%_source_payload         w9.bzdio
%_binary_payload         w9.bzdio

#   package signature type is OpenPGP via GnuPG
%_signature              gpg

#   the default repository list
%l_repo_cache            %{l_root_rpm}/PKG/
%l_repo_0                %{l_root_rpm}/PKG/
%l_repo_1                -
%l_repo_2                -
%l_repo_3                -
%l_repo_4                ftp://ftp.openpkg.org/current/SRC/
%l_repo_5                -
%l_repo_6                -
%l_repo_7                -
%l_repo_8                -
%l_repo_9                -

