Okay -- I've come to this point:

%install
DESTDIR=%{buildroot} \
LIBEXEC=%{_libexecdir} \
PERLLIB=%{perl_sitelib} \
INITDIR=%{_initddir} \
HOST=%{_vendor} \
 ./install.sh%install

[etc]


I've got a better idea!

I am attaching 4 files (hope they'll pass through the ML, if not let me know and I'll attach them privately):

"shorewall-configure.patch", "shorewall-spec.patch" - these are applied against the latest shorewall version available for *Fedora* SRPM (4.5.0-RC2). If you don't have it, or can't find it, I am attaching the original files as a separate archive called "shorewall-4.5.0-RC2.tar.xz"

The "shorewall-configure.patch" patch is the most important as it creates a new file called "configure" in the root BUILD tree (i.e. ~/rpmbuild/BUILD/shorewall-4.5.0). As you can see from the modified spec file, you use the distribution's own %configure so that all distro-dependent directories are passed as parameters - *automatically* - to that "configure" file. This configure file then scans all these parameters and sets the appropriate values as required - you don't have to do a thing!

There is another little nugget I included for your benefit - forcing the stupid Fedora RPM system to spill out its proper host/target triplet (i.e. "<arch>-redhat-linux-gnu") - as you can see, this is done by the %{_target_platform} RPM macro.

The last file I am attaching is an example output from "configure". As you can see from that file, I have attached a commented out screen dump of what I get as environment variables passed automatically from the %configure script line in the modified .spec file when all this is executed - this is just an example for you to see what is going on. The "configure" executable dumps, by default, its configuration parameters on the screen, which, I think, is a must to be shown to the end user, just in case something goes awry!

So, the whole process goes like this:

%configure is executed in the %prep section, sniffing out the desired distro-specific values, placing them in a separate file called "config" and when the various "install.sh" scripts execute later on, they *source* this file to acquire these values. How you treat these variables in your install.sh scripts is up to you really, but this is how I see it working without messing about with rpm macro scripts and other such nonsense.

In case the install.sh is executed "manually" from the command line (i.e. during "normal" build - without the .spec file) then you may modify the logic in your install.sh script to source the "config" file only if it exist, ignoring it otherwise - that should be simple enough for you, even with your bash-scripting skills. ;-)

Let me know how you are getting on.

--- shorewall-org.spec  2012-02-09 16:54:31.000000000 +0000
+++ shorewall.spec      2012-02-23 02:35:36.784132308 +0000
@@ -20,9 +20,15 @@
 Source3:        %{baseurl}/%{name}6-lite-%{version}-RC2.tar.bz2
 Source4:        %{baseurl}/%{name}-init-%{version}-RC2.tar.bz2
 Source5:        %{baseurl}/%{name}-core-%{version}-RC2.tar.bz2
-
+Patch1:                %{name}-configure.patch
 BuildRequires:  perl
+
+# There is more to it than that, but it is up to the 
+# Fedora shorewall maintainer to fix the mess in
+# %preun, %postun and %triggerun sections below
+%if 0%{?fedora} >= 16
 BuildRequires:  systemd-units
+%endif
 
 BuildArch:      noarch
 
@@ -129,6 +135,11 @@
 
 %prep
 %setup -q -c -n %{name}-%{version} -T -a0 -a1 -a2 -a3 -a4 -a5
+%patch1 -p1
+
+# make sure ./configure can be executed
+%{__chmod} ug+x ./configure 
+%configure --host=%{_target_platform} --perl-lib=%{perl_privlib} 
--destdir=%{buildroot} --initdir=%{_initrddir}
 
 # Remove hash-bang from files which are not directly executed as shell
 # scripts. This silences some rpmlint errors.
@@ -137,10 +148,6 @@
 %build
 
 %install
-export PREFIX=$RPM_BUILD_ROOT
-export DEST=%{_initrddir}
-export LIBEXEC=%{_libexecdir}
-export PERLLIB=%{perl_privlib}
 
 targets="shorewall shorewall-core shorewall-lite shorewall6 shorewall6-lite 
shorewall-init"
 
--- a/configure 1970-01-01 01:00:00.000000000 +0100
+++ b/configure 2012-02-23 02:31:51.768149171 +0000
@@ -0,0 +1,64 @@
+#!/bin/sh
+
+# file name where we set all variables to be used in install.sh later on
+log_file=config
+declare -A params
+
+# pretty printing vars go here
+table_length=102
+table_first_col_length=28
+table_second_col_length=67
+table_char="-"
+
+rm -f $log_file
+
+
+# Two passes needed just in case there are input parameters specified more 
than once
+# Pass 1
+for _p in $@; do
+  # slice ...
+  p=${_p:2}
+  [ -n "${p}" ] && {
+    # ... and dice
+    pn=${p%=*}
+    pv=${p#*=}
+    [ -n ${pn} ] && [ -n ${pv} ] && params[${pn}]="${pv}"
+  }
+done
+
+# some pretty printing to see what's what
+printf -v line '%*s' "$table_length"
+echo ${line// /$table_char}
+printf "| %-${table_first_col_length}s | %-${table_second_col_length}s |\n" 
"Parameter Name" "Parameter Value" 
+echo ${line// /$table_char}
+
+# Pass 2
+for _p in ${!params[@]}; do
+  printf "| %-${table_first_col_length}s | %-${table_second_col_length}s |\n" 
${_p} ${params[${_p}]}
+  # set the appropriate parameter
+  case ${_p} in
+       build) # build triplet
+               echo "BUILD=${params[${_p}]}" >> $log_file
+               ;;
+        host) # host triplet
+               echo "HOST=${params[${_p}]}" >> $log_file
+               ;;
+     destdir) # destination directory
+               echo "DESTDIR=${params[${_p}]}" >> $log_file
+               ;;
+     libexec) # libexec directory
+               echo "LIBEXEC=${params[${_p}]}" >> $log_file
+               ;;
+     initdir) # init.d script directory
+               echo "INITDIR=${params[${_p}]}" >> $log_file
+               ;;
+    perl-lib) # perllib directory
+               echo "PERLLIB=${params[${_p}]}" >> $log_file
+               ;;
+              *) # anything else not specified above, not strictly necessary!
+               echo "${_p//-/_}=${params[${_p}]//-/_}" >> $log_file
+               ;;
+  esac
+done
+echo ${line// /$table_char}
+
diff -NurBb a/shorewall-4.5.0-RC2/install.sh b/shorewall-4.5.0-RC2/install.sh
--- a/shorewall-4.5.0-RC2/install.sh    2012-02-05 21:54:26.000000000 +0000
+++ b/shorewall-4.5.0-RC2/install.sh    2012-02-23 01:26:25.900443367 +0000
@@ -24,6 +24,9 @@
 
 VERSION=4.5.0-RC2
 
+# import pre-set variables
+. ../config
+
 #
 # Change to the directory containing this script
 #
diff -NurBb a/shorewall6-4.5.0-RC2/install.sh b/shorewall6-4.5.0-RC2/install.sh
--- a/shorewall6-4.5.0-RC2/install.sh   2012-02-05 21:54:26.000000000 +0000
+++ b/shorewall6-4.5.0-RC2/install.sh   2012-02-23 01:15:59.098490340 +0000
@@ -24,6 +24,9 @@
 
 VERSION=4.5.0-RC2
 
+# import pre-set variables
+. ../config
+
 #
 # Change to the directory containing this script
 #
diff -NurBb a/shorewall6-lite-4.5.0-RC2/install.sh 
b/shorewall6-lite-4.5.0-RC2/install.sh
--- a/shorewall6-lite-4.5.0-RC2/install.sh      2012-02-05 21:54:26.000000000 
+0000
+++ b/shorewall6-lite-4.5.0-RC2/install.sh      2012-02-23 01:16:37.768487442 
+0000
@@ -24,6 +24,9 @@
 
 VERSION=4.5.0-RC2
 
+# import pre-set variables
+. ../config
+
 usage() # $1 = exit status
 {
     ME=$(basename $0)
diff -NurBb a/shorewall-core-4.5.0-RC2/install.sh 
b/shorewall-core-4.5.0-RC2/install.sh
--- a/shorewall-core-4.5.0-RC2/install.sh       2012-02-05 21:54:26.000000000 
+0000
+++ b/shorewall-core-4.5.0-RC2/install.sh       2012-02-23 01:16:59.304485828 
+0000
@@ -24,6 +24,9 @@
 
 VERSION=4.5.0-RC2
 
+# import pre-set variables
+. ../config
+
 usage() # $1 = exit status
 {
     ME=$(basename $0)
diff -NurBb a/shorewall-init-4.5.0-RC2/install.sh 
b/shorewall-init-4.5.0-RC2/install.sh
--- a/shorewall-init-4.5.0-RC2/install.sh       2012-02-05 21:54:26.000000000 
+0000
+++ b/shorewall-init-4.5.0-RC2/install.sh       2012-02-23 01:17:16.874484509 
+0000
@@ -25,6 +25,9 @@
 
 VERSION=4.5.0-RC2
 
+# import pre-set variables
+. ../config
+
 usage() # $1 = exit status
 {
     ME=$(basename $0)
diff -NurBb a/shorewall-lite-4.5.0-RC2/install.sh 
b/shorewall-lite-4.5.0-RC2/install.sh
--- a/shorewall-lite-4.5.0-RC2/install.sh       2012-02-05 21:54:26.000000000 
+0000
+++ b/shorewall-lite-4.5.0-RC2/install.sh       2012-02-23 01:17:29.343483540 
+0000
@@ -24,6 +24,9 @@
 
 VERSION=4.5.0-RC2
 
+# import pre-set variables
+. ../config
+
 usage() # $1 = exit status
 {
     ME=$(basename $0)

Attachment: shorewall-4.5.0-RC2.tar.xz
Description: Binary data

# Console output on my Fedora system:
#------------------------------------------------------------------------------------------------------
#| Parameter Name               | Parameter Value                               
                      |
#------------------------------------------------------------------------------------------------------
#| disable-dependency-tracking  | disable-dependency-tracking                   
                      |
#| build                        | x86_64-unknown-linux-gnu                      
                      |
#| sbindir                      | /usr/sbin                                     
                      |
#| sysconfdir                   | /etc                                          
                      |
#| host                         | noarch-redhat-linux-gnu                       
                      |
#| bindir                       | /usr/bin                                      
                      |
#| includedir                   | /usr/include                                  
                      |
#| program-prefix               |                                               
                      |
#| perl-lib                     | /usr/share/perl5                              
                      |
#| mandir                       | /usr/share/man                                
                      |
#| libdir                       | /usr/lib64                                    
                      |
#| infodir                      | /usr/share/info                               
                      |
#| localstatedir                | /var                                          
                      |
#| datadir                      | /usr/share                                    
                      |
#| exec-prefix                  | /usr                                          
                      |
#| destdir                      | 
/home/mr-4/rpmbuild/BUILDROOT/shorewall-4.5.0-0.2.RC2.fc13.x86_64   |
#| initdir                      | /etc/rc.d/init.d                              
                      |
#| libexecdir                   | /usr/libexec                                  
                      |
#| prefix                       | /usr                                          
                      |
#| sharedstatedir               | /var/lib                                      
                      |
#------------------------------------------------------------------------------------------------------

disable_dependency_tracking=disable_dependency_tracking
BUILD=x86_64-unknown-linux-gnu
sbindir=/usr/sbin
sysconfdir=/etc
HOST=noarch-redhat-linux-gnu
bindir=/usr/bin
includedir=/usr/include
program_prefix=
PERLLIB=/usr/share/perl5
mandir=/usr/share/man
libdir=/usr/lib64
infodir=/usr/share/info
localstatedir=/var
datadir=/usr/share
exec_prefix=/usr
DESTDIR=/home/mr-4/rpmbuild/BUILDROOT/shorewall-4.5.0-0.2.RC2.fc13.x86_64
INITDIR=/etc/rc.d/init.d
libexecdir=/usr/libexec
prefix=/usr
sharedstatedir=/var/lib
------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Shorewall-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/shorewall-devel

Reply via email to