LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   [HELP] Script for automated compiling (https://www.linuxquestions.org/questions/programming-9/%5Bhelp%5D-script-for-automated-compiling-474529/)

hbinded 08-16-2006 05:02 PM

[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 :mad:
Thanks in advance

Tinkster 08-16-2006 06:18 PM

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

unSpawn 08-16-2006 06:52 PM

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)

Tinkster 08-16-2006 06:57 PM

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


Cheers,
Tink

unSpawn 08-16-2006 07:53 PM

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

hbinded 08-17-2006 12:36 PM

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 :p (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.

unSpawn 08-17-2006 03:57 PM

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.

hbinded 08-19-2006 05:24 AM

I'll do exactly that ;) . Thanks once again.

gnashley 08-20-2006 02:03 PM

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

http://distro.ibiblio.org/pub/linux/...2-noarch-1.tgz

hbinded 08-20-2006 09:42 PM

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!

gnashley 08-22-2006 03:30 AM

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.


All times are GMT -5. The time now is 04:40 PM.