summaryrefslogtreecommitdiffstats
path: root/makepkg
blob: 8f7beb6446f8ebc0ba96b88b39a131eef3d62ddc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/bin/bash

myver='1.23'
startdir=`pwd`

[ -f /etc/makepkg.conf ] && . /etc/makepkg.conf

strip_url() {
  echo $1 | sed 's|^.*://.*/||g'
}

if [ "$1" = "--help" -o "$1" = "-h" ]; then
  shift
  echo "makepkg version $myver"
  echo "usage: $0 [build_script]"
  echo
  echo "  if build_script is not specified, makepkg will look for a PKGBUILD"
  echo "  file in the current directory."
  echo
  exit 1
fi

BUILDSCRIPT="`pwd`/PKGBUILD"
if [ "$1" != "" ]; then
  BUILDSCRIPT=$1
fi

if [ ! -f $BUILDSCRIPT ]; then
  echo "==> ERROR:  $BUILDSCRIPT does not exist!" >&2
  exit 1
fi

. $BUILDSCRIPT

# check for no-no's
if [ `echo $pkgver | grep '-'` ]; then
	echo "==> ERROR:  pkgver is not allowed to contain hyphens." >&2
	exit 1
fi

echo
d=`date`
echo "==> Building package $pkgname  ($d)" >&2

# extract source
echo "==> Acquiring/Extracting Sources..." >&2
mkdir -p src pkg
cd $startdir/src
for netfile in ${source[@]}; do
  file=`strip_url $netfile`
  if [ -f ../$file ]; then
    echo "==> Found $file in build dir" >&2
    cp ../$file .
  elif [ -f /var/cache/pacman/src/$file ]; then
    echo "==> Using local copy of $file" >&2
    cp /var/cache/pacman/src/$file .
  else
    proto=`echo $netfile | sed 's|://.*||'`
    if [ "$proto" != "ftp" -a "$proto" != "http" ]; then
      echo "==> ERROR:  $netfile was not found in the build directory and is not a proper URL."
      echo "==> Aborting..." >&2
      exit 1
    fi
    # check for a download utility
    if [ -x /usr/bin/snarf ]; then
    	ftpagent="/usr/bin/snarf"
    elif [ -x /usr/bin/lftpget -a "$proto" = "ftp" ]; then
    	ftpagent="/usr/bin/lftpget"
    elif [ -x /usr/bin/wget ]; then
    	ftpagent="/usr/bin/wget --passive-ftp --tries=3 --waitretry=3"
    else
    	echo "==> ERROR:  You need an ftp client installed (snarf/lftp/wget) in /usr/bin" >&2
    	exit 1
    fi
    echo "==> Downloading $file" >&2
    $ftpagent $netfile 2>&1
    if [ ! -f $file ]; then
      echo "==> ERROR: Failed to download $file" >&2
      echo "==> Aborting..." >&2
      exit 1
    fi
    mkdir -p /var/cache/pacman/src && cp $file /var/cache/pacman/src
  fi
  case $file in
	    *.tar.gz|*.tar.Z|*.tgz)
    cmd="tar --use-compress-program=gzip -xf $file" ;;
	    *.tar.bz2)
    cmd="tar --use-compress-program=bzip2 -xf $file" ;;
	    *.zip)
    cmd="unzip -qq $file" ;;
	    *)
    cmd="cp ../$file ." ;;
	esac
	echo "==> $cmd" >&2
	$cmd
done

# build
echo "==> Building Package..." >&2
build 2>&1
if [ $? -gt 0 ]; then
  echo "==> Build Failed.  Aborting..." >&2
  exit 2
fi

# write the .PKGINFO file
echo "==> Generating .PKGINFO file..." >&2
cd $startdir/pkg
echo "# Generated by makepkg $myver" >.PKGINFO
echo -n "# " >>.PKGINFO
date >>.PKGINFO
echo "pkgname = $pkgname" >>.PKGINFO
echo "pkgver = $pkgver-$pkgrel" >>.PKGINFO
for bakfile in "${backup[@]}"; do
  echo "backup = $bakfile" >>.PKGINFO
done

# remove info/doc files
cd $startdir
rm -rf pkg/usr/info pkg/usr/share/info
rm -rf pkg/usr/doc pkg/usr/share/doc

# strip binaries
cd $startdir
echo "==> Stripping debugging symbols from libraries..." >&2
find pkg/{,usr,usr/local}/lib -type f \
   -exec /usr/bin/strip --strip-debug '{}' ';' 2>&1
echo "==> Stripping symbols from binaries..." >&2
find pkg/{,usr,usr/local}/{bin,sbin} -type f \
   -exec /usr/bin/strip '{}' ';' 2>&1

# tar it up
echo "==> Compressing package..." >&2
cd $startdir/pkg
tar czvf $startdir/$pkgname-$pkgver-$pkgrel.pkg.tar.gz .PKGINFO * >../filelist

cd $startdir
d=`date`
echo "==> Finished  ($d)" >&2
exit 0