aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChmouel Boudjnah <chmouel@mandriva.org>2000-02-18 20:00:57 +0000
committerChmouel Boudjnah <chmouel@mandriva.org>2000-02-18 20:00:57 +0000
commit48bff1047b38c3f134a179786438440cc691f227 (patch)
treec3379252ab0d021163a9ba39d3fd52705f62d7d0
parent00a20e122852338baa6d892413f212d30db1da5d (diff)
downloadspec-helper-topic/MandrakeSoft.tar
spec-helper-topic/MandrakeSoft.tar.gz
spec-helper-topic/MandrakeSoft.tar.bz2
spec-helper-topic/MandrakeSoft.tar.xz
spec-helper-topic/MandrakeSoft.zip
Initial revisionCookertopic/MandrakeSoft
-rw-r--r--ChangeLog4
-rw-r--r--Makefile52
-rwxr-xr-xclean_files23
-rwxr-xr-xcompress_files167
-rwxr-xr-xspec-helper46
-rw-r--r--spec-helper.spec42
-rwxr-xr-xstrip_files73
7 files changed, 407 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
new file mode 100644
index 0000000..3590b2b
--- /dev/null
+++ b/ChangeLog
@@ -0,0 +1,4 @@
+2000-02-18 Chmouel Boudjnah <chmouel@mandrakesoft.com>
+ * spec-helper.spec: cvs import.
+ * Makefile: rules for cvs and specs.
+
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..c92de63
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,52 @@
+#---------------------------------------------------------------
+# Project : Linux-Mandrake
+# Module : spec-helper
+# File : Makefile
+# Version : $Id$
+# Author : Frederic Lepied
+# Created On : Fri Feb 18 08:11:21 2000
+#---------------------------------------------------------------
+
+VERSION=0.1
+FILES= spec-helper clean_files compress_files strip_files
+DISTFILES= Makefile $(FILES)
+NAME=spec-helper
+DIST=$(NAME)-$(VERSION)
+
+all:
+ @echo "use make install or make dist"
+
+dist:
+ rm -f $(NAME)-$(VERSION).tar.bz2
+ rm -rf $(DIST)
+ mkdir $(DIST)
+ ln $(DISTFILES) $(DIST)
+ tar cvf $(NAME)-$(VERSION).tar $(DIST)
+ bzip2 -9vf $(NAME)-$(VERSION).tar
+ rm -rf $(DIST)
+
+install:
+ install -d -m 755 $(DESTDIR)/usr/share/spec-helper
+ install -m 755 $(FILES) $(DESTDIR)/usr/share/spec-helper
+
+dis:
+ rm -rf $(NAME)-$(VERSION) ../$(NAME)-$(VERSION).tar*
+ mkdir -p $(NAME)-$(VERSION)
+ find . -not -name "$(NAME)-$(VERSION)"|cpio -pd $(NAME)-$(VERSION)/
+ find $(NAME)-$(VERSION) -type d -name CVS -o -name .cvsignore -o -name unused |xargs rm -rf
+ perl -p -i -e 's|^%define version.*|%define version $(VERSION)|' $(NAME).spec
+ tar cf ../$(NAME)-$(VERSION).tar $(NAME)-$(VERSION)
+ bzip2 -9f ../$(NAME)-$(VERSION).tar
+ rm -rf $(NAME)-$(VERSION)
+
+rpm: dis ../$(NAME)-$(VERSION).tar.bz2 $(RPM)
+ cp -f ../$(NAME)-$(VERSION).tar.bz2 $(RPM)/SOURCES
+ cp -f $(NAME).spec $(RPM)/SPECS/
+ -rpm -ba --clean --rmsource $(NAME).spec
+ rm -f ../$(NAME)-$(VERSION).tar.bz2
+
+# Local variables:
+# mode: makefile
+# End:
+#
+# Makefile ends here
diff --git a/clean_files b/clean_files
new file mode 100755
index 0000000..a1fd235
--- /dev/null
+++ b/clean_files
@@ -0,0 +1,23 @@
+#!/usr/bin/perl -w
+#---------------------------------------------------------------
+# Project : Linux-Mandrake
+# Module : spec-helper
+# File : clean_files
+# Version : $Id$
+# Author : Frederic Lepied
+# Created On : Thu Feb 10 10:29:18 2000
+# Purpose : remove backup files.
+#---------------------------------------------------------------
+
+################################################################################
+$RPM_BUILD_ROOT=$ENV{RPM_BUILD_ROOT};
+chdir($RPM_BUILD_ROOT) || die "Can't cd to $ENV{RPM_BUILD_ROOT}: $!";
+
+system(split(/\s+/,"find . -type f -a
+ ( -name #*# -o -name *~ -o -name DEADJOE
+ -o -name *.orig -o -name *.rej -o -name *.bak
+ -o -name .*.orig -o -name .*.rej -o -name .SUMS
+ -o -name TAGS -o -name core -o ( -path */.deps/* -a -name *.P )
+ ) -exec rm -f {} ;"));
+
+# clean_files ends here
diff --git a/compress_files b/compress_files
new file mode 100755
index 0000000..eaaec0d
--- /dev/null
+++ b/compress_files
@@ -0,0 +1,167 @@
+#!/usr/bin/perl -w
+#---------------------------------------------------------------
+# Project : Linux-Mandrake
+# Module : spec-helper
+# File : compress_files
+# Version : $Id$
+# Author : Frederic Lepied
+# Created On : Thu Feb 10 08:04:11 2000
+# Purpose : compress man and info pages.
+#---------------------------------------------------------------
+
+use Cwd;
+use File::Find;
+
+################################################################################
+# Returns the basename of the argument passed to it.
+sub basename {
+ my $fn=shift;
+ $fn=~s:^.*/(.*?)$:$1:;
+ return $fn;
+}
+
+################################################################################
+# Returns the directory name of the argument passed to it.
+sub dirname {
+ my $fn=shift;
+ $fn=~s:^(.*)/.*?$:$1:;
+ return $fn;
+}
+
+################################################################################
+# Run a command that may have a huge number of arguments, like xargs does.
+# Pass in a reference to an array containing the arguments, and then other
+# parameters that are the command and any parameters that should be passed to
+# it each time.
+sub xargs {
+ my $args=shift;
+
+ # The kernel can accept command lines up to 20k worth of characters.
+ my $command_max=20000;
+
+ # Figure out length of static portion of command.
+ my $static_length=0;
+ foreach (@_) {
+ $static_length+=length($_)+1;
+ }
+
+ my @collect=();
+ my $length=$static_length;
+ foreach (@$args) {
+ if (length($_) + 1 + $static_length > $command_max) {
+ error("This command is greater than the maximum command size allowed by the kernel, and cannot be split up further. What on earth are you doing? \"@_ $_\"");
+ }
+ $length+=length($_) + 1;
+ if ($length < $command_max) {
+ push @collect, $_;
+ }
+ else {
+ system(@_,@collect) if $#collect > -1;
+ @collect=($_);
+ $length=$static_length + length($_) + 1;
+ }
+ }
+ system(@_,@collect) if $#collect > -1;
+}
+
+################################################################################
+# Check if a file is a .so man page, for use by File::Find.
+my @sofiles;
+my @sodests;
+sub find_so_man {
+ # The -s test is becuase a .so file tends to be small. We don't want
+ # to open every man page. 1024 is arbitrary.
+ if (! -f $_ || -s $_ > 1024) {
+ return;
+ }
+
+ # Test first line of file for the .so thing.
+ open (SOTEST,$_);
+ my $l=<SOTEST>;
+ close SOTEST;
+ if ($l=~m/\.so\s+(.*)/) {
+ my $solink=$1;
+ # This test is here to prevent links like ... man8/../man8/foo.8
+ if (basename($File::Find::dir) eq dirname($solink)) {
+ $solink=basename($solink);
+ }
+ else {
+ $solink="../$solink";
+ }
+
+ push @sofiles,"$File::Find::dir/$_";
+ push @sodests,$solink;
+ }
+}
+
+################################################################################
+$RPM_BUILD_ROOT=$ENV{RPM_BUILD_ROOT};
+chdir($RPM_BUILD_ROOT) || die "Can't cd to $ENV{RPM_BUILD_ROOT}: $!";
+
+# Now the .so conversion.
+@sofiles=@sodests=();
+foreach $dir (qw{usr/man usr/X11R6/man usr/lib/perl5/man}) {
+ if (-e "$dir") {
+ find(\&find_so_man, "$dir");
+ }
+}
+foreach $sofile (@sofiles) {
+ my $sodest=shift(@sodests);
+ system "rm","-f",$sofile;
+ system "ln","-sf",$sodest,$sofile;
+}
+
+push @files, split(/\n/,`find usr/info usr/share/info usr/man usr/share/man usr/X11*/man usr/lib/perl5/man -type f ! -name "*.gz" -a ! -name "*.bz2" 2>/dev/null || true`);
+
+# Look for files with hard links. If we are going to compress both,
+# we can preserve the hard link across the compression and save
+# space in the end.
+my @f=();
+my %hardlinks;
+foreach (@files) {
+ ($dev, $inode, undef, $nlink)=stat($_);
+ if ($nlink > 1) {
+ if (! $seen{"$inode.$dev"}) {
+ $seen{"$inode.$dev"}=$_;
+ push @f, $_;
+ }
+ else {
+ # This is a hardlink.
+ $hardlinks{$_}=$seen{"$inode.$dev"};
+ }
+ }
+ else {
+ push @f, $_;
+ }
+}
+
+if (@f) {
+ # Make executables not be anymore.
+ xargs(\@f,"chmod","a-x");
+
+ xargs(\@f,"bzip2","-9f");
+}
+
+
+# Now change over any files we can that used to be hard links so
+# they are again.
+foreach (keys %hardlinks) {
+ # Remove old file.
+ system("rm","-f","$_");
+ # Make new hardlink.
+ system("ln","$hardlinks{$_}.bz2","$_.bz2");
+}
+
+# Fix up symlinks that were pointing to the uncompressed files.
+open (FIND,"find $RPM_BUILD_ROOT -type l |");
+while (<FIND>) {
+ chomp;
+ ($directory)=m:(.*)/:;
+ $linkval=readlink($_);
+ if (! -e "$directory/$linkval" && -e "$directory/$linkval.bz2") {
+ system("rm","-f",$_);
+ system("ln","-sf","$linkval.bz2","$_.bz2");
+ }
+}
+
+# compress_files ends here
diff --git a/spec-helper b/spec-helper
new file mode 100755
index 0000000..29756a9
--- /dev/null
+++ b/spec-helper
@@ -0,0 +1,46 @@
+#!/bin/sh
+#---------------------------------------------------------------
+# Project : Linux-Mandrake
+# Module : bin
+# File : spec-helper
+# Version : $Id$
+# Author : Frederic Lepied
+# Created On : Wed Feb 9 16:25:21 2000
+#---------------------------------------------------------------
+
+if [ -z "$RPM_BUILD_ROOT" ]; then
+ echo "no RPM_BUILD_ROOT variable; exiting." 1>&2
+ exit 1
+fi
+
+SPEC_HELPER_ROOT=${SPEC_HELPER_ROOT=/usr/share/spec-helper}
+PATH=$SPEC_HELPER_ROOT:$PATH
+export PATH
+
+# usage
+usage() {
+ echo "usage: spec-helper [-c|-m|-s]" 1>&2
+ echo "-c don't clean up files" 1>&2
+ echo "-m don't compress files" 1>&2
+ echo "-s don't strip files" 1>&2
+}
+
+# handle options
+while [ $# != 0 ]; do
+ case $1 in
+ -c) DONT_CLEANUP=1;;
+ -m) DONT_COMPRESS=1;;
+ -s) DONT_STRIP=1;;
+ *) usage; exit 1;;
+ esac
+
+ shift
+done
+
+test -z "$DONT_CLEANUP" && echo -n "Cleaning files..." && clean_files && echo "done"
+test -z "$DONT_COMPRESS" && echo -n "Compressing files..." && compress_files && echo "done"
+test -z "$DONT_STRIP" && echo -n "Stripping files..." && strip_files && echo "done"
+
+exit 0
+
+# spec-helper ends here
diff --git a/spec-helper.spec b/spec-helper.spec
new file mode 100644
index 0000000..b85e787
--- /dev/null
+++ b/spec-helper.spec
@@ -0,0 +1,42 @@
+%define name spec-helper
+%define version 0.1
+%define release 1mdk
+
+Summary: Tools to ease the creation of rpm packages
+Name: %{name}
+Version: %{version}
+Release: %{release}
+# get the source from our cvs repository (see
+# http://www.linuxmandrake.com/en/cvs.php3)
+Source0: %{name}-%{version}.tar.bz2
+Copyright: GPL
+Group: Development/Tools
+BuildRoot: %{_tmppath}/%{name}-buildroot
+Prefix: %{_prefix}
+BuildArchitectures: noarch
+
+%description
+Tools to ease the creation of rpm packages for the Linux-Mandrake distribution.
+Compress man pages using bzip2, strip executables, ...
+
+%prep
+%setup
+
+%build
+
+%install
+rm -rf $RPM_BUILD_ROOT
+make install DESTDIR=$RPM_BUILD_ROOT
+
+%clean
+rm -rf $RPM_BUILD_ROOT
+
+%files
+%defattr(-,root,root)
+/usr/share/spec-helper
+
+%changelog
+* Fri Feb 18 2000 Frederic Lepied <flepied@mandrakesoft.com> 0.1-1mdk
+- first version.
+
+# end of file
diff --git a/strip_files b/strip_files
new file mode 100755
index 0000000..fe3ef48
--- /dev/null
+++ b/strip_files
@@ -0,0 +1,73 @@
+#!/usr/bin/perl -w
+#---------------------------------------------------------------
+# Project : Linux-Mandrake
+# Module : spec-helper
+# File : strip_files
+# Version : $Id$
+# Author : Frederic Lepied
+# Created On : Thu Feb 10 09:23:02 2000
+# Purpose : Strip files.
+#---------------------------------------------------------------
+
+use File::Find;
+
+################################################################################
+# Check if a file is an elf binary, shared library, or static library,
+# for use by File::Find. It'll fill the following 3 arrays with anything
+# it finds:
+my (@shared_libs, @executables, @static_libs);
+sub testfile {
+ return if -l $_ or -d $_; # Skip directories and symlinks always.
+
+ $fn="$File::Find::dir/$_";
+
+ # Does its filename look like a shared library?
+ if (m/.*\.so.*?/) {
+ # Ok, do the expensive test.
+ my $type=`file $_`;
+ if ($type=~m/.*ELF.*shared.*/) {
+ push @shared_libs, $fn;
+ return;
+ }
+ }
+
+ # Is it executable? -x isn't good enough, so we need to use stat.
+ (undef,undef,$mode,undef)=stat(_);
+ if ($mode & 0111) {
+ # Ok, expensive test.
+ my $type=`file $_`;
+ if ($type=~m/.*ELF.*executable.*/) {
+ push @executables, $fn;
+ return;
+ }
+ }
+
+ # Is it a static library, and not a debug library?
+ if (m/lib.*\.a/ && ! m/.*_g\.a/) {
+ push @static_libs, $fn;
+ return;
+ }
+}
+
+################################################################################
+$RPM_BUILD_ROOT=$ENV{RPM_BUILD_ROOT};
+chdir($RPM_BUILD_ROOT) || die "Can't cd to $ENV{RPM_BUILD_ROOT}: $!";
+
+@shared_libs=@executables=@static_libs=();
+find(\&testfile,$RPM_BUILD_ROOT);
+
+foreach (@shared_libs) {
+ # Note that all calls to strip on shared libs
+ # *must* inclde the --strip-unneeded.
+ system("strip","--remove-section=.comment","--remove-section=.note","--strip-unneeded",$_);
+}
+
+foreach (@executables) {
+ system("strip","--remove-section=.comment","--remove-section=.note",$_);
+}
+
+# foreach (@static_libs) {
+# system("strip","--strip-debug",$_);
+# }
+
+# strip_files ends here