Changeset 56

Show
Ignore:
Timestamp:
12/17/05 07:35:41 (3 years ago)
Author:
athomas
Message:
  • Refactored build section so it's cleaner.
  • Fixed self-packaging so it should actually work if you don't already have installwatch installed.
  • Added --build-with option.
  • By using --skip-build and --install-with, bpkg effectively has the same functionality as checkinstall.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • bpkg/trunk/bpkg

    r54 r56  
    3333# Where to store built packages 
    3434PKGDIR=$PWD 
    35 # Skip configure phase by default? 
    36 SKIPCONFIGURE=0 
     35# Skip build phase by default? 
     36SKIPBUILD=0 
    3737# Program used to download source 
    3838DOWNLOADER='wget -c' 
     
    4747# Load system config 
    4848test -r /etc/bpkg.conf && . /etc/bpkg.conf 
     49# Load per-user config 
     50test -r ~/.bpkgrc && . ~/.bpkgrc 
    4951 
    5052# 
    5153# XXXXXXXXXXXXXX Not really user-modifiable below here XXXXXXXXXXXXX 
    5254# 
    53 VERSION="0.4
     55VERSION="0.5
    5456PACKAGER=auto 
    5557SELF=`basename $0` 
     
    6365DESTROOT=/tmp/$SELF.$PACKAGE.$$.pkg 
    6466TMPFILES="$TMPDIR $DESTROOT $INSTALLLOG" 
    65 MAKEINSTALL='make install' 
     67BUILDER=auto 
     68INSTALLER='make install' 
     69CUSTOMBUILDER='' 
    6670EXPLICIT_PACKAGE=0 
    6771REQUIRED_PROGRAMS='installwatch cpio perl tar bzip2 unzip gzip' 
     
    135139                export INSTALLWATCH_BACKUP_PATH=$SRCDIR/backup-`date +%Y%m%d%H%M%S-backup` 
    136140        fi 
    137         installwatch -o $INSTALLLOG $MAKEINSTALL || error "package installation failed" 
     141        installwatch -o $INSTALLLOG $INSTALLER || error "package installation failed" 
    138142        if [ $BACKUP = 1 -a -d $INSTALLWATCH_BACKUP_PATH ]; then 
    139143                notice "Archiving backup to $INSTALLWATCH_BACKUP_PATH.tar.gz" 
     
    152156} 
    153157 
     158# Builders 
     159build_xmkmf() 
     160{ 
     161        notice "running xmkmf on Imakefile" 
     162        xmkmf || error "xmkmf failed" 
     163} 
     164 
     165build_autoconf() 
     166{ 
     167        if ! grep -i autoconf ./configure > /dev/null; then 
     168                notice "./configure does not seem to be generated by autoconf, running anyway" 
     169        fi 
     170        notice "running './configure --prefix=$PREFIX --sysconfdir=$SYSCONFDIR --localstatedir=$LOCALSTATEDIR --datadir=$DATADIR $@'" 
     171        ./configure --prefix=$PREFIX --sysconfdir=$SYSCONFDIR --localstatedir=$LOCALSTATEDIR --datadir=$DATADIR "$@" || error "configure failed" 
     172        make 
     173} 
     174 
     175build_autogen() 
     176{ 
     177        notice "no ./configure, but we have ./autogen.sh - running it" 
     178        ./autogen.sh --prefix=$PREFIX --sysconfdir=$SYSCONFDIR --localstatedir=$LOCALSTATEDIR --datadir=$DATADIR "$@" || error "./autogen.sh failed" 
     179        if test ! -r Makefile; then 
     180                notice "./autogen.sh did not run configure, running it now" 
     181                build_autoconf 
     182        fi 
     183        make 
     184} 
     185 
     186build_make() 
     187{ 
     188        notice "source doesn't appear to use autoconf or Imake, trying standard make" 
     189        test -r $MAKEFILE || MF=makefile 
     190        test -r $MAKEFILE || MF=GNUmakefile 
     191        test -r $MAKEFILE || error "can't determine makefile (tried Makefile, makefile and GNUmakefile)" 
     192        # Change /usr/local to $PREFIX 
     193        if grep /usr/local $MAKEFILE > /dev/null; then 
     194                notice "Changing all instances of /usr/local in $MAKEFILE to $PREFIX" 
     195                sed -e "s,/usr/local,$PREFIX,g" $MAKEFILE > $MAKEFILE~ && mv $MAKEFILE~ $MAKEFILE 
     196        fi 
     197        make 
     198} 
     199 
     200build_jam() 
     201{ 
     202        jam 
     203} 
     204 
     205build_python() 
     206{ 
     207        python setup.py build -f 
     208} 
     209 
     210build_perl() 
     211{ 
     212        perl Makefile.PL || error "Makefile generation failed" 
     213        make 
     214} 
     215 
     216build_qmake() 
     217{ 
     218        qmake $PACKAGE.pro || error "qmake failed" 
     219        make 
     220} 
     221 
     222build_custom() 
     223{ 
     224        eval "$CUSTOMBUILDER" || error "custom builder failed" 
     225} 
     226 
     227# Packagers 
    154228packager_slackware() 
    155229{ 
     
    302376quitloop=0 
    303377while [ $quitloop = 0 -a $# != 0 ]; do 
    304 #       if [[ "$1" = cpan://* ]]; then 
    305 #               CPAN="${1#cpan://}" 
    306 #               PACKAGE=perl-`echo ${CPAN/::/-} | tr A-Z a-z` 
    307 #               notice "Pre-installing Perl module before packaging" 
    308 #               perl -MCPAN -e "install '$CPAN'" || error "CPAN install failed" 
    309 #               PACKAGEVER=`perl -MExtUtils::Installed -e "print ExtUtils::Installed->new()->version('$CPAN')" 2> /dev/null` 
    310 #               CPANTMP="/tmp/$SELF.$PACKAGE.$$.cpan" 
    311 #               TMPFILES="$TMPFILES $CPANTMP" 
    312 #               mkdir -p $CPANTMP 
    313 #               cd "$CPANTMP" 
    314 #               SRCDIR=$PWD 
    315 #               test -z "$PACKAGEVER" && error "could not determine version of Perl module $CPAN" 
    316 #               perl -MExtUtils::Installed -e "print join(\"\n\", ExtUtils::Installed->new()->files('$CPAN')) . \"\n\"" | duplicate_paths "$CPANTMP" || error "failed to extract PERL module content list" 
    317 #               cat <<EOF > Makefile 
    318 #all: 
    319 # 
    320 #install: 
    321 #       find ./ | cpio -pdm / 
    322 #       rm -f /Makefile 
    323 #EOF 
    324 #               notice "packaging perl module $CPAN as $PACKAGE-$PACKAGEVER" 
    325378        if [[ -f "$1" || "$1" = ftp://* || "$1" = http://* ]]; then 
    326379                AUTOEXTRACT="$1" 
     
    396449    Display the O/S that bpkg thinks you are running. 
    397450  --version 
    398     Show $SELF version. 
    399   --skip-configure 
    400     Do not perform the configure phase of bpkg. Useful for already configured 
    401     source. 
     451    Show bpkg version. 
    402452  --packager=arch|slackware|rpm|deb|gentoo|redhat|suse|auto 
    403453    Generate packages using the specified packaging system. 'auto' is the 
     
    412462    --localstatedir=/var/state/<package> and --datadir=/usr/share/<package>). 
    413463    The base directories are used if this option is not given. 
     464  --skip-build 
     465    Do not perform the build phase of bpkg. 
     466  --build-with=<command> 
     467    Use the given command to build, rather than the default 'make'. 
    414468  --install-with=<command> 
    415     Use the given command to install rather than the default 'make install'. 
     469    Use the given command to install, rather than the default 'make install'. 
    416470  --md5=<md5sum> 
    417471    Verify that the source file has the given MD5 checksum. 
     
    421475                                exit 0 
    422476                        ;; 
    423                   --install-with=*) 
    424                         MAKEINSTALL=`echo "$1" | cut -d= -f2-` 
    425                   ;; 
    426                         --skip-configure) 
    427                                 SKIPCONFIGURE=1 
     477                        --install-with=*) 
     478                                INSTALLER=`echo "$1" | cut -d= -f2-` 
     479                        ;; 
     480                        --build-with=*) 
     481                                CUSTOMBUILDER=`echo "$1" | cut -d= -f2-` 
     482                                BUILDER=custom 
     483                        ;; 
     484                        --skip-build) 
     485                                SKIPBUILD=1 
    428486                        ;; 
    429487                        --prefix=*) 
     
    480538fi 
    481539 
    482 if [ $SKIPCONFIGURE = 0 ]; then 
     540if [ $BUILDER = auto ]; then 
    483541        if [ -x ./configure ]; then 
    484                 if ! grep -i autoconf ./configure > /dev/null; then 
    485                         notice "./configure does not seem to be generated by autoconf, running anyway" 
    486                 fi 
    487                 notice "running './configure --prefix=$PREFIX --sysconfdir=$SYSCONFDIR --localstatedir=$LOCALSTATEDIR --datadir=$DATADIR $@'" 
    488                 ./configure --prefix=$PREFIX --sysconfdir=$SYSCONFDIR --localstatedir=$LOCALSTATEDIR --datadir=$DATADIR "$@" || error "configure failed" 
     542                BUILDER=autoconf 
    489543        elif [ -x autogen.sh ]; then 
    490                 notice "no ./configure, but we have ./autogen.sh - running it" 
    491                 ./autogen.sh --prefix=$PREFIX --sysconfdir=$SYSCONFDIR --localstatedir=$LOCALSTATEDIR --datadir=$DATADIR "$@" || error "./autogen.sh failed" 
    492                 if test ! -r Makefile; then 
    493                         notice "./autogen.sh did not run configure, running" 
    494                         ./configure --prefix=$PREFIX --sysconfdir=$SYSCONFDIR --localstatedir=$LOCALSTATEDIR --datadir=$DATADIR "$@" || error "configure failed" 
    495                 fi 
     544                BUILDER=autogen 
    496545        elif [ -r Imakefile ]; then 
    497                 notice "running xmkmf on Imakefile" 
    498                 xmkmf || error "xmkmf failed" 
     546                BUILDER=xmkmf 
    499547        elif [ -r GNUmakefile -o -r makefile -o -r Makefile ]; then 
    500                 notice "source doesn't appear to use autoconf or Imake, trying standard make" 
    501                 test -r $MAKEFILE || MF=makefile 
    502                 test -r $MAKEFILE || MF=GNUmakefile 
    503                 test -r $MAKEFILE || error "can't determine makefile (tried Makefile, makefile and GNUmakefile)" 
    504                 # Change /usr/local to $PREFIX 
    505                 if grep /usr/local $MAKEFILE > /dev/null; then 
    506                         notice "changing all instances of /usr/local in $MAKEFILE to /usr" 
    507                         sed -e "s,/usr/local,$PREFIX,g" $MAKEFILE > $MAKEFILE~ && mv $MAKEFILE~ $MAKEFILE 
    508                 fi 
     548                BUILDER=make 
    509549        elif [ -r Jamfile ]; then 
    510                 which jam > /dev/null 2>&1 || error "found Jamfile, but didn't find jam" 
    511                 notice "generating stub Makefile for jam" 
    512                 cat << EOF > Makefile 
    513 build: 
    514         jam 
    515  
    516 install: 
    517         jam install 
    518 EOF 
     550                BUILDER=jam 
     551                INSTALLER='jam install' 
    519552        elif [ -r setup.py ]; then 
    520                 which python > /dev/null 2>&1 || error "found setup.py, but didn't find python" 
    521                 notice "generating stub Makefile for python" 
    522                 cat <<EOF > Makefile 
    523 build: 
    524         python setup.py build -f 
    525  
    526 install: 
    527         python setup.py install -f 
    528 EOF 
     553                BUILDER=python 
     554                INSTALLER='python setup.py install -f' 
    529555        elif [ -r Makefile.PL ]; then 
    530                 perl Makefile.PL 
     556                BUILDER=perl 
    531557        elif [ -r $PACKAGE.pro ]; then 
    532                 qmake $PACKAGE.pro || error "qmake failed" 
     558                BUILDER=qmake 
    533559        else 
    534560                error "couldn't auto-detect build mechanism" 
     
    536562fi 
    537563 
    538 make || error "'make failed'" 
     564if [ $SKIPBUILD = 0 ]; then 
     565        eval build_$BUILDER || error "build failed" 
     566fi 
    539567 
    540568eval packager_$PACKAGER 
  • bpkg/trunk/Makefile

    r48 r56  
    55OS=$(shell ./bpkg --detect-os) 
    66 
    7 .PHONY: $(OS)-build $(OS)-install 
     7.PHONY: $(OS)-build $(OS)-pre-install $(OS)-install real-install all install 
    88 
    99all: $(OS)-build 
    1010 
    11 install: 
     11install: all $(OS)-pre-install 
    1212        @if ! ./bpkg --install-with='make install-raw' --package=bpkg-`./bpkg --version`; then \ 
    1313                echo; \ 
     
    2020                exit 1; \ 
    2121        fi 
     22        @cat README 
    2223 
    2324install-raw: all $(OS)-install 
    2425        mkdir -p $(DESTDIR)$(PREFIX)/bin 
    2526        install -m755 bpkg $(DESTDIR)$(PREFIX)/bin 
    26         @cat README 
    2727 
    2828$(INSTALLWATCH): $(INSTALLWATCH).tgz 
     
    4646        @exit 1 
    4747 
    48 arch-install: 
    49         @echo  
    50         @echo "Run 'pacman -S installwatch' to install installwatch." 
    51         @echo 
     48unknown-install: 
     49        @echo "FATAL: Unknown operating system/distribution. Need detection and" 
     50        @echo "       backend code in bpkg." 
     51        @exit 1 
    5252 
     53install-installwatch: 
     54        $(MAKE) -C $(INSTALLWATCH) PREFIX=$(PREFIX) BINDIR=$(DESTDIR)$(PREFIX)/bin LIBDIR=$(DESTDIR)$(PREFIX)/lib install 
     55 
     56# Arch 
     57arch-pre-install: 
     58        @if ! pacman -Q installwatch > /dev/null 2>&1; then \ 
     59                echo "Installwatch is required by bpkg, attempting to install"; \ 
     60                pacman -S installwatch; \ 
     61                pacman -Q installwatch > /dev/null 2>&1 || exit 1; \ 
     62        fi 
     63 
     64# Gentoo 
    5365gentoo-build: $(INSTALLWATCH) 
    5466        $(MAKE) -C $(INSTALLWATCH) PREFIX=/usr 
    5567 
    56 gentoo-install: 
    57         $(MAKE) -C $(INSTALLWATCH) PREFIX=$(PREFIX) BINDIR=$(DESTDIR)$(PREFIX)/bin LIBDIR=$(DESTDIR)$(PREFIX)/lib install 
     68gentoo-pre-install: install-installwatch 
    5869 
     70gentoo-install: gentoo-pre-install 
     71 
     72# Slackware 
    5973slackware-build: 
    6074        @if ! ls /var/log/packages/checkinstall* > /dev/null 2>&1; then \ 
     
    6882        fi 
    6983 
    70 slackware-install: 
    71         @ls /var/log/packages/checkinstall* > /dev/null 2>&1 || $(MAKE) -C $(INSTALLWATCH) PREFIX=$(PREFIX) BINDIR=$(DESTDIR)$(PREFIX)/bin LIBDIR=$(DESTDIR)$(PREFIX)/lib install 
     84slackware-pre-install: 
     85        @ls /var/log/packages/checkinstall* > /dev/null 2>&1 || $(MAKE) install-installwatch 
     86 
     87slackware-install: slackware-pre-install