You are not logged in.

#1 2004-08-22 09:59:50

gs
Member
From: UK
Registered: 2004-03-06
Posts: 147

Worked example using 'patch' and 'sed' to make a pkg

I would like this to be reviewed, please. The methododology may need to be standardized a bit more. Also, of course, the way I have used scripts may be a bit controversial. Certainly, anyone who knows what they are doing could easily do without these scripts, but maybe also they are stepping stones to acquiring that sort of proficiency! Also, I would not rule out that the PKGBUILD, itself, can be criticised/ improved with guidance.

Introduction

Here is a method for creating patches for Makefiles which uses sed to convert #PREFIX# to $Startdir/pkg in literal path form, so that the build is fully portable. I asked a while back on the forum whether this was possible. Xentac held my hand, while I picked up the method from him. What follows also incorporates some of his cautions about retaining md5sum integrity. (A point about which I earlier had a weak understanding!) My thanks also to dp who sorted me out on the use of $pkgname and $origname.

Description

The PKGBUILD method is an example of automation, which these scripts follow in that variables are assigned values and then a template-like feel follows on. Despite this resemblance, you will need to make these two files executable by applying

$ chmod +x FILENAME

You will need to execute them in a terminal with the commands

$ cd YOUR_WORKING_DIRECTORY_PATH
$ ./Makefiles_ready

or

$ ./PATCHMAKER

This will all work under fakeroot, provided the files have 'user users' permissions. The attached scripts are annotated examples; and enough is provided so that the reader can fabricate his/her own Makefile_new and test out the method for his(her)self.

I reckon this might be useful practice for learning the technique. I need to mention that for full functionality postfix needs to be installed and set up so that sendmail can work, but a lot of the functionality can be tested without doing this.

The command for starting the application is

$ FaxMail

You can, of course, run it for testing purposes from $startdir/pkg/usr/bin. Note the distinction between $origname and $pkgname, which you will see in the following files.

Getting Directory and Files Ready

You could start by making a new directory in $HOME, possibly called 'TESTBED' and by creating empty files named as per the following, ready for copying and pasting. It could also be useful to create a file called HOWTO and paste these notes into it. You will then need to check the 'user users' permissions and to make the two new scripts exucutable.

Then, you are ready to roll -- completing the whole process with a straight 'makepkg' in the terminal.

File Contents

Makefiles_ready

#! /bin/sh
# Makefiles_ready... generates two clean copies of the Makefile.
origname=FaxMail
pkgver=2.3


### RESULTS:-- two appropriately named copies of clean Makefile. 
### 'Makefile_new.scratch' is so named as a safeguard against 
### inadvertently overwriting any earlier 'Makefile_new'. So, if you just
### want a clean 'Makefile_pristine' with which to make a new patch, 
### delete the generated 'Makefile_new.scratch'.
### REQUIREMENTS:-- Either a downloaded and compressed source file 
### in the main directory, and appropriate source array in PKGBUILD. 
### Or just the latter.

### NOTES: If there is already a ./src_old, it should first be deleted by 
### hand. If there is already a $pkgname-$pkgver.pkg.tar.gz, it will need
### to be removed or deleted. This script will produce a failed make
### but will produce the results we are looking for. 

mv ./src ./src_old

makepkg -o
# downloads and extracts files; does not build.

cp ./src/$origname-$pkgver/Makefile Makefile_new.scratch
cp Makefile_new.scratch Makefile_pristine 

echo ">> When and if ammended, Makefile_new.scratch "
echo ">> needs to be renamed as Makefile_new. If you do this"
echo ">> and you want to retain your earlier Makefile_new, you "
echo "   should first rename it to something like Makefile_prev_new."

PATCHMAKER

#! /bin/sh
# PATCHMAKER... makes a patch file
origname=FaxMail
pkgname=faxmail
pkgver=2.3

### RESULTS:-- $pkgname-$pkgver.patch; md5sums
### REQUIREMENTS:-- Clean Makefile_pristine; Edited Makefile_new; 
###     PKGBUILD ammended to include $pkgname-$pkgver.patch in source array.

### '#PREFIX#' stands in for '$startdir/pkg' -- see the sed command
### in PKGBUILD which inserts the required literal path, prior to making
### for real.

### It is a good idea to look at the patchfile produced here, and checkout by 
### eye that the lines set for deletion are really from the Makefile_pristine. 
### The two scripts have worked consistently, according to my tests.
### Makefiles_ready can be used to ensure you have clean makefile copies 
### to start from. 

diff -aur Makefile_pristine Makefile_new >$pkgname-$pkgver.patch

makepkg -go
## tests sources and produce md5sums; does not start the build process.

echo ">> Check $pkgname-$pkgver.patch"
echo ">> If it is OK, paste md5sums into PKGBUILD"

PKGBUILD

# $Id: PKGBUILD, $
# Maintainer: 
origname=FaxMail
pkgname=faxmail
pkgver=2.3
pkgrel=1
pkgdesc="A front end for sending faxes via email."
url="http://wol.ra.phy.cam.ac.uk/FaxMail/"
depends=('tcl' 'tk' 'imagemagick' 'postfix')
makedepends=('tcl' 'tk')
conflicts=()
replaces=()
backup=()
install=


source=(ftp://sunsite.unc.edu/pub/Linux/apps/serialcomm/fax/$origname-$pkgver.tar.gz 
                           ./$pkgname-$pkgver.patch)
md5sums=('55dc96aee65ccd3bee2ec38bb6ca0ffd' 'b419add4472576a2a4fc4272e8c7da48')

build() {
cd $startdir/src/$origname-$pkgver
patch Makefile $startdir/src/$pkgname-$pkgver.patch
sed -i "s%#PREFIX#%$startdir/pkg%g" Makefile
mkdir -p $startdir/pkg/usr/bin/ $startdir/pkg/usr/man/man1/ 
                $startdir/pkg/usr/info/

make 

make install

}

faxmail-2.3.patch

--- Makefile_pristine    2004-08-21 20:12:23.000000000 +0100
+++ Makefile_new    2004-08-20 12:28:29.000000000 +0100
@@ -3,19 +3,19 @@
 # --------------------------------------------------------------------
 
 # where can I put the FaxMail wrapper and the tryfax executable
-INSTALLBINPATH = /usr/local/bin
+INSTALLBINPATH = #PREFIX#/usr/bin
 
 # where can I put the FaxMail manual
-INSTALLMANPATH = /usr/local/man
+INSTALLMANPATH = #PREFIX#/usr/man
 
 # where can I put the FaxMail info page.  If you don't have gnu info,
 # you can set this to /tmp or something.  If you do, remember to add
 # in an entry to the `dir' file.
-INSTALLINFOPATH = /usr/info
+INSTALLINFOPATH = #PREFIX#/usr/info
 
 # what is the toplevel FaxMail directory. 
 # Contains the coverage list and FaxMail.tcl script.
-FAXMAIL_DIR = /usr/local/lib/FaxMail
+FAXMAIL_DIR = #PREFIX#/usr/lib/FaxMail
 
 # external program locations
 
@@ -23,7 +23,7 @@
 WISH_CMD = /usr/bin/wish
 
 # where can I find smail or sendmail
-MAIL_CMD = /usr/lib/sendmail
+MAIL_CMD = /usr/sbin/sendmail
 
 # where can I store temporary files
 TMP_DIR = /tmp
@@ -39,7 +39,7 @@
 CFLAGS  = 
 LDFLAGS =
 # Uncomment the following line if linking of tryfax fails.
-#LDFLAGS = -lresolv
+LDFLAGS = -lresolv
 
 
 # --------------------------------------------------------------------

What the beep was that?

Offline

#2 2004-08-22 12:44:31

gs
Member
From: UK
Registered: 2004-03-06
Posts: 147

Re: Worked example using 'patch' and 'sed' to make a pkg

I have looked at possibilities for executing

$ makepkg -o -p Makefiles_ready

and

$ makepkg -go -p PATCHMAKER

The second is a serious candidate for doing it that sort of way. The first, however, needs the embedded makepkg and encasing with makepkg therefore executes that process a second time.


What the beep was that?

Offline

Board footer

Powered by FluxBB