LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-16-2006, 05:02 PM   #1
hbinded
Member
 
Registered: May 2006
Distribution: Slackware & MyLFScratch
Posts: 37

Rep: Reputation: 15
Question [HELP] Script for automated compiling


Hi, I've been trying to make a script to compile a few softwares but it doesn't seem to work. Here is the script:
Code:
for package in $(cat /source/graphics)
do
  tar xfv $package > unpacked
  packagedir=`head -n 1 /source/unpacked | cut -f1 -d'/'`
  cd $packagedir
  params=`head -n1 /source/$(`sed 's/.tar.*//' graphics`).param`
  ./configure $params
  makeparams=`sed -n '2p;2q' /source/$(head -n 1 /source/unpacked | cut -f1 -d'/').param`
  make $makeparams
  install=`sed -n '3p;3q' /source/$(head -n 1 /source/unpacked | cut -f1 -d'/').param`
  su -c "$install"
  cd /source
  rm -rf $packagedir
  rm -f $(head -n 1 /source/unpacked).param
  rm -rf unpacked
done 2>&1 | tee -a /source/logs/$(head -n 1 unpacked | cut -f1 -d'/').log #log the entire loop
I have a file called graphics in /sources and some 5 tarballs. the content of graphics is as follows;
Code:
jpegsrc.v6b.tar.gz
libpng-1.2.12.tar.bz2
tiff-3.8.2.tar.gz
giflib-4.1.4.tar.bz2
lcms-1.15.tar.gz
libmng-1.0.9.tar.gz
freetype-2.1.10.tar.bz2
fontconfig-2.3.2.tar.gz
so what could be the problem? I've almost ripped my hair out for this
Thanks in advance

Last edited by hbinded; 08-16-2006 at 05:05 PM. Reason: didn't complete post b4 posting
 
Old 08-16-2006, 06:18 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
How about telling us where/how it fails? I'm not inclined to download
those so I can test what your issue might be...


Cheers,
Tink
 
Old 08-16-2006, 06:52 PM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
For instance the tar listing won't work w/o the right decompressor arg and you're listing but not unpacking.
Code:
#set -xe
cd /source && cat /source/graphics|while read pkg; do
 ext=${pkg//-/ }; ext=(${ext//./ }); ext=${ext[$[${#ext[@]}-1]]}
 case "$ext" in 
  *"GNU tar"*) unset ext;; *"gzip compr"*) ext="z";;
  *"bzip2 compr"*) ext="j";; *) exit 127;; 
 esac
 pkgdir=$(tar -t${ext}f "$pkg"|head -1); pkgdir=${pkgdir//\/*}
 tar -t${ext}f "$pkg" && \
  if [ -d "$pkgdir" ]; then cd "$pkgdir"; name="${ext[0]}"
   if [ -f "/source/${name}.param" ]; then paramf="/source/${name}.param"; fi
   log="/source/logs/${name}.log"; params=$(sed -n '1p' "$paramf") && \
   ./configure $params >/dev/null|tee -a "$log" && makeparams=$(sed -n '2p' "$paramf") && \
   make $makeparams >/dev/null|tee -a "$log" && install=$(sed -n '3p' "$paramf")
   su -c "$install"|tee -a "$log" && cd /source && rm -f "$paramf"; rm -rf "$pkgdir"
  fi
done 
exit 0
or something like that. YMMV(VM)
 
Old 08-16-2006, 06:57 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
recent versions of tar (1.15.1 for instance) pick the archive format
automagically ... :}


Cheers,
Tink
 
Old 08-16-2006, 07:53 PM   #5
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
recent versions of tar (1.15.1 for instance) pick the archive format automagically ... :}
Awesome.
 
Old 08-17-2006, 12:36 PM   #6
hbinded
Member
 
Registered: May 2006
Distribution: Slackware & MyLFScratch
Posts: 37

Original Poster
Rep: Reputation: 15
First of all, thanks to all those speedy replies. I gave up on that script after realising that a Makefile does the job
2x better (I mean with the logs and output redirection). If anyone is interested,
I will post later a sample of my makefile.

Once again thanks a million.
 
Old 08-17-2006, 03:57 PM   #7
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
If anyone is interested, I will post later a sample of my makefile.
Since you've been given help here the least you can try to "repay"* with would be doing just that.


* OK, we have no concept of "paying" for "services" but you know what I mean.
 
Old 08-19-2006, 05:24 AM   #8
hbinded
Member
 
Registered: May 2006
Distribution: Slackware & MyLFScratch
Posts: 37

Original Poster
Rep: Reputation: 15
I'll do exactly that . Thanks once again.
 
Old 08-20-2006, 02:03 PM   #9
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
Here's a little project I whipped up for doing that:

http://distro.ibiblio.org/pub/linux/...2-noarch-1.tgz
 
Old 08-20-2006, 09:42 PM   #10
hbinded
Member
 
Registered: May 2006
Distribution: Slackware & MyLFScratch
Posts: 37

Original Poster
Rep: Reputation: 15
gee, thanks alot! The tool you've linked above is A1. btw, here is a portion of
my Makefile:


Code:
PKGDIR=`head -n 1 /source/packed | cut -f1 -d'/'`
UNPACKED=/source/packed
SRC=/source
X=/bin/unpack
HOME=/home/build
START=echo -e "\nNAME $(@)\n" >>$(HOME)/fin/$(@).fin
FINFILE=$(HOME)/fin/$(@).fin
LOG=echo -e "\nSTART $(PKGDIR): `date`\n" >>$(HOME)/made/$(PKGDIR).log
UNLOG=echo -e "\nSTOP $(PKGDIR): `date`\n" >>$(HOME)/made/$(PKGDIR).log
# echo -e "\nSTART: `date`\n"



include makefile-functions


all:
    make tiff-3.8.2 libpng-1.2.12 giflib-4.1.4 lcms-1.15 libmng-1.0.9 \
    freetype-2.1.10 fontconfig-2.3.2


tiff-3.8.2:
    $(call echo_message, Building)
    $(START) && \
    $(X) $(SRC)/tiff-3.8.2.tar.gz > $(UNPACKED) && \
    cd $(PKGDIR) && \
    $(LOG) && \
    \
    ./configure --prefix=/usr >>$(HOME)/made/$(PKGDIR).log && \
    make >>$(HOME)/made/$(PKGDIR).log && \
    su -c "pacco 'make install'" >>$(HOME)/made/$(PKGDIR).log && \
    $(UNLOG)


    rm -rf $(PKGDIR) && \
    rm -rf $(UNPACKED)
    touch $(@)

libpng-1.2.12:
    $(call echo_message, Building)
    $(START) && \
    $(X) $(SRC)/libpng-1.2.12.tar.bz2 > $(UNPACKED) && \
    cd $(PKGDIR) && \
    $(LOG) && \
    \
    ./configure --prefix=/usr >>$(HOME)/made/$(PKGDIR).log && \
    make >>$(HOME)/made/$(PKGDIR).log && \
    su -c "pacco 'make install && install -v -m755 -d /usr/share/doc/libpng-1.2.12 && install \
    -v -m644 README libpng.txt /usr/share/doc/libpng-1.2.12'" >>$(HOME)/made/$(PKGDIR).log && \
    $(UNLOG)

    rm -rf $(PKGDIR) && \
    rm -rf $(UNPACKED)
    touch $(@)
Just one question though: how could I make the Makefile work recursively? I've read the manpage of make, but all that's explained there is relevant to programs with c.

what I actually want to do is to make different Makefiles for the different tarballs and use the top-level Makefile to call the "other" Makefiles.

Thanks in advance.

p.s. I've used pkgbuild to create some packages for my zenwalk, and it works like a charm. thanks!
 
Old 08-22-2006, 03:30 AM   #11
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
Each package needs to be handled individually or things get way complicated. I have some pkgbuild scripts which make mega-packages or multiple pks from one or two source-dirs, but it really gets complicated. You should only do this where it's really necessary like for glibc or util-linux.

What pkgbuild does is put all the repetitive code out of the way in functions. This leaves the script very brief for normal autoconf pkgs which compile okay, with only pkg name and version details which distinguish it from another script.
Any special options or added code between functions is easily added and seen.
You'll also find examples for group and chain build scripts which will build all the pkgs from a text-file list or in the current working dir.
 
  


Reply



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
Automated user setup script Oxagast Linux - General 3 10-11-2005 01:25 PM
Help with automated filename script lhoff Programming 2 09-07-2004 10:46 AM
Creating an automated installation script Kaze13d Slackware 2 11-30-2003 12:08 AM
Install script for Automated RH mac_casey Linux - General 3 11-11-2002 02:41 PM
Automated su script? elmetald00d Linux - General 5 04-08-2002 11:17 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:29 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration