LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices

Reply
 
Search this Thread
Old 10-24-2008, 01:33 AM   #1
empcrono
Member
 
Registered: Jul 2008
Distribution: Slackware
Posts: 110

Rep: Reputation: 15
Help writing a SlackBuild script please


OK I am comparing SlackBuild scripts from several sources. One of which is Eric's SlackBuild Toolkit. Other sources include, but not limited, are Pats SlackBuilds, SlackBuilds from www.Slackbuild.org and a Wiki on how to write them.


here is what I have written so far.
Code:

# Set initial variables:

PRGNAM=HTTrack
VERSION=3.43
ARCH=${ARCH:-pentium4} 	
BUILD=${BUILD:-1}
# The "TAG" option is the typical way of branding a Slackware package. 
# E.G. a persons initials. I.E. your initials.
TAG=${TAG:-_WGsIII}

CWD=$(pwd)
TMP=${TMP:-/tmp/build}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}

# Exit the script on errors:
set -e
trap 'echo "$0 FAILED at line ${LINENO}" | tee $OUTPUT/error-${PRGNAM}.log' ERR

rm -rf $PKG
mkdir -p $TMP $PKG $OUTPUT
cd $TMP
rm -rf $PRGNAM-$VERSION
tar -xvf $CWD/$PRGNAM-$VERSION.tar.gz
cd $PRGNAM-$VERSION
chown -R root:root
find . \
  \( -perm 777 -o -perm 775 -o -perm 555 -o -perm 511\) \
  -exec chmod 755 {} \; -o \
  \( -perm 666 -o -perm 664 -o -perm 600 -o -perm 444 -o -perm 440 \
  -o -perm 400\) -exec chmod 644 {} \;

if [ "$ARCH" = "i486" ]; then
  SLKCFLAGS="-O2 -march=i486 -mtune=i686"
elif [ "$ARCH" = "pentium4"]; then
  SLKCFLAGS="-02 -march=pentium4"
elif [ "$ARCH" = "i686" ]; then
  SLKCFLAGS="-O2 -march=i686 -mtune=i686"
elif [ "$ARCH" = "x86_64" ]; then
  SLKCFLAGS="-O2 -fPIC"
fi
Well I am going through all of these line by line and trying to figure out what I want to use as a template.

I see some use permissions as I have it written up above however I also see it written like this in two different places

"# Change ownership and permissions if necessary
# This may not be needed in some source tarballs, but it never hurts
chown -R root:root .
chmod -R u+w,go+r-w,a-s ."

Meanwhile I am looking at documentation about chmod and what the flags mean. However if any one could tell me the pros cons of the use of doing the chmod in that manner and the why do it one way or the other? Thank you so much.

Also:

I have noticed that
"VERSION=$" written two ways the way I have it there and this way
"VERSION=${VERSION:-3.43}"

Any light on these would be great thank you so much.

Update:

OK I am starting to get it. This is fun I must say. While comments on the above questions would be nice I have a more important question namely

if I am passing to the compiler -march=pentium4 do I still have to pass to the compiler -mtune=somthing_here or can I leave this flag out and just use -march.

The reason I ask is because I have read some and I get the impression that you ether pick one or the other and that with -march you can specify cpu like I did however with -mtune can only specify architect.

Any light would be nice!

Note: I have tested and I do realize it will compile with out -mtune still I am new to this and reassurance is big for me. Until I get stronger legs You'll most likely see me doing a lot of this.

Last edited by empcrono; 10-25-2008 at 08:32 AM. Reason: Update
 
Old 10-24-2008, 04:49 AM   #2
gegechris99
Member
 
Registered: Oct 2005
Location: France
Distribution: Slackware 14.1 64bit
Posts: 729
Blog Entries: 3

Rep: Reputation: 78
Quote:
I have noticed that
"VERSION=$" written two ways the way I have it there and this way
"VERSION=${VERSION:-3.43}"
Second one means that if variable VERSION is not already defined, it will be initialized with default value 3.43.

This way you can reuse your Slackbuild script with no change if you want to recompile with another version by using the command line

Code:
VERSION=3.45 xxxx.Slackbuild
Of course, this is applicable to all variables.

Last edited by gegechris99; 10-24-2008 at 05:00 AM.
 
Old 10-24-2008, 12:23 PM   #3
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,772

Rep: Reputation: 478Reputation: 478Reputation: 478Reputation: 478Reputation: 478
And to the other question about -march. If you only specify -march, then -mtune is assumed to be the same, so unless you want to build (possible) features compatible with 'greater' arches, then you can leave it alone -I guess in your case there is no greater arch. The standard builds use -march=i486 -mtune=i686 which means that the program should run on an i486, but will be able to use optimzations available with processors up to i686.

And, it makes no difference which syntax you use with chmod as the commands will do the same -it just depends on what you find more readable.
 
Old 10-24-2008, 10:01 PM   #4
empcrono
Member
 
Registered: Jul 2008
Distribution: Slackware
Posts: 110

Original Poster
Rep: Reputation: 15
OK I was having trouble. Originally I was comparing different styles and picking what I felt was the best approach. When I started to have bugs I decided to go with just (for the most part) the style from:
http://slackwiki.org/Writing_A_Slack...ld_environment


I was having trouble and the bugs I get do not make sense to me I get this when I try to run the script.

HTTrack.SlackBuild: line 76: unexpected EOF while looking for matching `''
HTTrack.SlackBuild: line 130: syntax error: unexpected end of file


The thing is line 76 is just a comment and yes it has the comment mark.
And line 130 is the end of the file. Well even if there is not a line 130 it still lists the error there. I deleted white space and only have 129 lines but it still says a problem with line 130


Code:
#! /bin/sh

# (C) William G Soura III <empcrono@gmail.com
# All rights reserved

# Set initial variables:

CWD=$(pwd)
if [ "$TMP" = "" ]; then
  TMP=/tmp
fi


# The version which appears in the application's filename
VERSION=3.43

# If the version conflicts with the Slackware package standard
# The dash character ("-") is not allowed in the VERSION string
# You can set the PKG_VERSION to something else than VERSION
PKG_VERSION=3.43

ARCH=${ARCH:-pentium4} # The architecture on which you want to build your package

# First digit is the build number, which you want to build your package
# The second string is the short form of the authors name, typical three initials:
BUILD=${BUILD:-1_WGsIII}

# The applications name
APP=HTTrack

# The installation directory of the package (where its actual directory
# structure will be created)
PKG=$TMP/package-$APP

##################################################################################
## Tip: Do a Google search on "gcc", "CFLAGS", "CXXFLAGS", "-march" and "-mtune"##
## for a better understanding.							##
## =============================================================================##
## Passes CFLAGS & CXXFLAGS instructions to the compiler.			##
## This passes the instructions according to how you defined the "ARCH=$" value.##  
## This is for optimization purposes.			 	 		##
################################################################################## 

if [ "$ARCH" = "i486" ]; then
  SLKCFLAGS="-O2 -march=i486 -mtune=i686"
elif [ "$ARCH" = "i686" ]; then
  SLKCFLAGS="-O2 -march=i686 -mtune=i686"
elif [ "$ARCH" = "pentium4"]; then
  SLKCFLAGS="-02 -march=pentium4"
elif [ "$ARCH" = "x86_64" ]; then
  SLKCFLAGS="-O2 -fPIC"
fi

# Delete the leftover directories if they exist (due to a previous build
# and (re)create the packaging directory
rm -rf $PKG
mkdir -p $TMP $PKG
rm -rf $TMP/APP-$VERSION

# Change to the TMP directory
cd $TMP || exit 1

# Extract the application source in TMP
# Note: if your application comes as a tar.bz2, you need tar -jxvf
tar -zxvf $CWD/$APP-$VERSION.tar.gz || exit 1

# Change to the application source directory
cd $APP-$VERSION || exit 1

# Change ownership and permissions if necessary
# This may not be needed in some source tarballsm but it never hurts
chown -R root:root
chmod -R u+w.go+r-w,a-s

# Set configure options
# If your app is written in C++, you'll also need to add a line for CXXFLAGS
CFLAGS="$SLKCFLAGS" \
  ./configure \
  --prefix=/usr \
  --sysconfdir=/etc \
  --localstatedir=/var \
  --build=$ARCH-slackware-linux \
  --host=$ARCH-slackware-linux

# Compile the source, but exit if anything goes wrong
make || exit

# Install everything into the package directory, but exit if anything goes wrong
make install DESTDIR=$PKG || exit

# Create a directory for documentation
mkdir -p $PKG/usr/doc/$APP-$VERSION

# Copy documentation to the docs directory and fix permissions
cp -a BUGS Changes FAQ INSTALL LICENSE MANIFEST README TODO docs/ $PKG/usr/doc/$APP-$VERSION
find $PKG/usr/doc/$APP-$VERSION -type f -exec chmod 644 {} \;

# Create the ./install directory and copy the slack-desc into it
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

# Add doinst.sh to package (uf ut exists)
if [ -e $CWD/doinst.sh.gz ]; then
  zcat $CWD/doinst.sh.gz > $PKG/install/doinst.sh
fi

# Strip some libraries and binaries
( cd $PKG
   find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
   find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
)

# Compress man pages if they exist
if [ -d $PKG/usr/man ]; then
  ( cd $PKG/usr/man
  find . -type f -exec gzip -9 {} \;
  for i in $(find . -type l) ; do ln -s $(readlink $i).gz $i.gz ; rm $i ; done
  ) 
fi

# Compress info pages if they exist (and remove the dir file)
if [ -d $PKG/usr/info ]; then
  gzip -9 $PKG/usr/info/*.info
  rm -f $PKG/usr/info/dir
fi

# Build the package
cd $PKG
/sbin/makepkg -l y -c n $TMP/$APP-$PKG_VERSION-$ARCH-$BUILD.tgz
Update:
Fixed a Few commands.
Followed a few peoples advice. Changed the tag around the the code to the CODE tag instead of the QUOTE tag. Changed mousepad to cat because it made sense to do so. Thank you people.

Last edited by empcrono; 10-25-2008 at 08:02 AM. Reason: Updates
 
Old 10-24-2008, 10:59 PM   #5
tramni1980
Member
 
Registered: Jul 2006
Location: Tübingen, Germany
Distribution: Slackware64-13.37
Posts: 737

Rep: Reputation: 37
# The applications name
Code:
APP-HTTrack
must be

Code:
APP=HTTrack
 
Old 10-25-2008, 03:08 AM   #6
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,772

Rep: Reputation: 478Reputation: 478Reputation: 478Reputation: 478Reputation: 478
Please post code inside 'code' tags instead of 'quote' tags. The problem is on line 22. You need this:
ARCH=${ARCH:-pentium4}
Your construction spans mulitple lines before the closing curly brace '}'.
 
Old 10-25-2008, 06:10 AM   #7
keefaz
Senior Member
 
Registered: Mar 2004
Distribution: Slackware
Posts: 4,617

Rep: Reputation: 136Reputation: 136
Code:
mousepad $CWD/slack-desc > $PKG/install/slack-desc
Why not just use cat ? mousepad requires X env (eg a X display) to work
 
Old 10-25-2008, 08:40 AM   #8
empcrono
Member
 
Registered: Jul 2008
Distribution: Slackware
Posts: 110

Original Poster
Rep: Reputation: 15
#########################
## Thanks you every one##
#########################

Thanks to every one I compiled my first Slackware package from a SlackBuild that I wrote, albeit, it was almost a copy of a template. Still I learned a lot and I will keep at it. Below is what was going on ----> before <---- I finally did it. So any thoughts would be nice. Thanks agian!!!!

---------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------

Thank you guys so much. I fixed the errors you guys pointed out. The above code reflects this.
But now I am getting a new error.

Code:
HTTrack.SlackBuild: line 67: cd: HTTrack-3.43: No such file or directory

Of course line 67 is:

Code:
cd $APP-$VERSION || exit 1

Please keep in mind this is my first SlackBuild I have attempted to make. For the most part I have
forgone doing this and opted to go with a template. I have written the template line by line my self
I am doing this so I can figure out the inner. So I still do not understand the purpose of all the code.
Yet I must say that I get enough to have my appetite whetted. The more I learn about slack packages etc
The more I fall in love with them. This is indeed powerful. While I am unsure how much further I need to
go to get real mastery I feel its in reach.


All that said: I am still unsure of and am seeking advice on how does the SlackBuild know ware to grab the source.
Ware in the SlackBuild does it assign the source file to be working with.


############
## Update:##
############

Okay I paid closer attention to how things were going. And I noticed that when the compressed file with all the source code and stuff that I got from HTTrack website. well when it got un tarred it chaged name. And so the naming system was messed up.
e.g. HTTrack-3.43.tar.gz is the name of the tar file but when it got un tarred it changed its name to httrack-3.43.1 Any advice on how to deal with that. I got it working because I changed the name of the tar to mach that of when it un tarred. But is there a better way to script this?

Last edited by empcrono; 10-25-2008 at 09:27 AM.
 
Old 10-25-2008, 09:43 AM   #9
GazL
Senior Member
 
Registered: May 2008
Posts: 3,481

Rep: Reputation: 1016Reputation: 1016Reputation: 1016Reputation: 1016Reputation: 1016Reputation: 1016Reputation: 1016Reputation: 1016
Quote:
Originally Posted by empcrono View Post

############
## Update:##
############

Okay I paid closer attention to how things were going. And I noticed that when the compressed file with all the source code and stuff that I got from HTTrack website. well when it got un tarred it chaged name. And so the naming system was messed up.
e.g. HTTrack-3.43.tar.gz is the name of the tar file but when it got un tarred it changed its name to httrack-3.43.1 Any advice on how to deal with that. I got it working because I changed the name of the tar to mach that of when it un tarred. But is there a better way to script this?
Yep, sometimes the directory name in the tar file isn't in the prognam-version format. The best thing to do in this case is use an extra variable to keep the internal name in and use that at the appropriate places in your slackbuild.

Wait till you find one, who's makefile isn't set up to support DESTDIR=. Things start to get really interesting then.


Congrats on your first successful slackbuild. You are hereby promoted from Novice to Journeyman slacker.


Gaz.
 
Old 10-25-2008, 11:10 AM   #10
titopoquito
Senior Member
 
Registered: Jul 2004
Location: Ruhr Area, Germany
Distribution: Slackware64 14.0
Posts: 1,525

Rep: Reputation: 94
Quote:
Originally Posted by empcrono View Post
But now I am getting a new error.

Code:
HTTrack.SlackBuild: line 67: cd: HTTrack-3.43: No such file or directory

Of course line 67 is:

Code:
cd $APP-$VERSION || exit 1

############
## Update:##
############

Okay I paid closer attention to how things were going. And I noticed that when the compressed file with all the source code and stuff that I got from HTTrack website. well when it got un tarred it chaged name. And so the naming system was messed up.
e.g. HTTrack-3.43.tar.gz is the name of the tar file but when it got un tarred it changed its name to httrack-3.43.1 Any advice on how to deal with that. I got it working because I changed the name of the tar to mach that of when it un tarred. But is there a better way to script this?
I'm not a bash master, but one little idea on this:

Code:
# get first archive entry and isolate the folder name
SRCDIR=$(tar -tvf $CWD/$APP-$VERSION.tar.gz | head -1 | rev | cut -d " " -f 1 | rev | sed "s:/::")

if test -d $APP-VERSION; then
# other test possible:
# if test $APP-VERSION = $SRCDIR; then
    cd $APP-$VERSION || exit 1
else
    mv $SRCDIR $APP-$VERSION && cd $APP-$VERSION || exit 1 
fi
 
Old 10-25-2008, 12:19 PM   #11
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,772

Rep: Reputation: 478Reputation: 478Reputation: 478Reputation: 478Reputation: 478
titopoquito's idea will work most of the time, except there are some tar archives out there which are like slack tgzpackages -that is the first directory entry in the tar archive is '.' and not the name of the tarball or the directory it was created from. I mean archives which are made with a command like:
Code:
# this
'tar -cf name.tar .'
# or:
'tar -cf name.tar *'
# instead of
'tar -cf name.tar name'
Source archives converted from rpm's using rpm2tgz may also be kinda strange internally compared to regular tarballs. You can work it out manually by testing your tarball unpack first in an empty directory and adjusting the script accordingly. Repacking the tarball is an easy way to fix it, but is not usually the best way to do it if your are re-distributing the script. My src2pkg deals with these strange cases with a rather tortured-looking routine of over 200 lines -but it works with rpm and deb archives directly at the same time.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Swiftfox slackbuild script shadowsnipes Slackware 23 10-24-2008 11:52 PM
Generic Slackbuild script C-Sniper Slackware 4 06-16-2008 06:05 PM
write a SlackBuild script for qc-usb-messenger-1.8 tramni1980 Slackware 2 06-05-2008 12:30 PM
SlackBuild.org nvidia kernel build script bug Woodsman Slackware 3 04-06-2008 08:48 PM
Trouble with my first SlackBuild script Yalla-One Slackware 6 06-10-2006 03:03 PM


All times are GMT -5. The time now is 12:29 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration