aboutsummaryrefslogtreecommitdiff
path: root/development/pcc/pcc.SlackBuild
blob: 2d24b68b6148268d6150e5b83e763c003dbb30f5 (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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/bin/bash

# Slackware build script for pcc (Portable C Compiler)

# Originally written by Armin Besirovic <email removed>
# Modified by B. Watson <urchlay@slackware.uk>

# Licensed under the WTFPL. See http://www.wtfpl.net/txt/copying/ for details.

# 20230108 bkw: updated for 1.2.0.DEVEL+20230108.

# 20210906 bkw:
# - updated for 1.2.0.DEVEL+20210905. Putting the .DEVEL in VERSION
#   is a bit unsightly, but it matches the output of "pcc --version"
#   and also Debian's version numbering scheme.
# - compiling with gcc no longer works, use clang or pcc. actually,
#   compiling with gcc gives us a pcc that seems to compile stuff OK,
#   but anything compiled with that pcc will segfault on startup.
# - add WTPL (since there was no license at all).

# 20141031 bkw:
# - took over maintentance.
# - upgraded for 1.1.0 beta series.
# - combined pcc and pcc-libs into one build, since either one is
#   useless without the other.
# - removed pcc-lib's 002-build-libpcc-with-pcc.patch as it's been
#   applied upstream in the 1.1.0 branch.
# - use private /usr/libexec/pcc/ dir instead of installing stuff
#   directly in /usr/libexec. Probably just paranoia.
# - rename cpp-pcc man page to pcpp, since the beta installs a
#   /usr/bin/pcpp.
# - get rid of -j1 in make command, seems to no longer be needed.
# - add logic to choose which compiler to use if CC not set.
# - extract license from source, install to /usr/doc

# 20150126 bkw:
# - upgraded for pcc-1.1.0 release, no more beta
# - add seddery to fix typo in cc.c (ifdef => ifndef)

# Note to self: when updating to a new CVS snapshot, first download
# the latest: http://pcc.ludd.ltu.se/ftp/pub/pcc/pcc-current.tgz Then
# look at the file DATESTAMP inside that tarball, and use that date's
# snapshot. This is because the CVS snap tarballs are generated
# nightly, whether or not there actually were any code changes,
# and we want VERSION to be the date of the last actual code change.
# For pcc-libs, just use the same snapshot date as pcc.

cd $(dirname $0) ; CWD=$(pwd)

PRGNAM=pcc
VERSION=${VERSION:-1.2.0.DEVEL+20230108}
BUILD=${BUILD:-1}
TAG=${TAG:-_SBo}
PKGTYPE=${PKGTYPE:-tgz}

if [ -z "$ARCH" ]; then
  case "$( uname -m )" in
    i?86) ARCH=i586 ;;
    arm*) ARCH=arm ;;
    *) ARCH=$( uname -m ) ;;
  esac
fi

if [ ! -z "${PRINT_PACKAGE_NAME}" ]; then
  echo "$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE"
  exit 0
fi

TMP=${TMP:-/tmp/SBo}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}

TARVER=${VERSION/*+}

# non-standard stanza here: we're not going to use -march= or -mtune=
# on 32-bit Slackware, because doing so prevents pcc from being used
# to compile itself. I could add logic to use those flags only if
# CC is gcc, but the extra complexity isn't worth the dubious benefit.
SLKCFLAGS="-O2 -fPIC"
if [ "$ARCH" = "x86_64" ]; then
  LIBDIRSUFFIX="64"
else
  LIBDIRSUFFIX=""
fi

set -e

# which compiler shall we use?
if [ "$CC" = "" ]; then
  # user didn't specify, autodetect.
  if pcc --version &>/dev/null; then
    CC=pcc
  elif clang --version &>/dev/null; then
    CC=clang
    SLKCFLAGS+=" -fcommon"
  else
    echo "Can't find pcc or clang in \$PATH. Giving up." 1>&2
  fi
fi

# let the user shoot himself in the foot if he insists, but at least
# warn him how much it's going to hurt.
if [ "$CC" = "gcc" ]; then
  echo
  echo "!!! CC is gcc, this will produce a non-working pcc. You asked for it..."
  echo
  sleep 3
fi

export CC
WITHCC="$( basename $CC )"
[ "$CC" = "pcc" ] && WITHCC="pcc itself"

# enable TLS? upstream disables it by default.
TLSOPT="--disable-tls"
if [ "${TLS:-no}" = "yes" ]; then
  TLSOPT="--enable-tls"
fi

rm -rf $PKG $TMP/$PRGNAM
mkdir -p $TMP/$PRGNAM $PKG $OUTPUT
cd $TMP/$PRGNAM
tar xvf $CWD/$PRGNAM-$TARVER.tgz
tar xvf $CWD/$PRGNAM-libs-$TARVER.tgz
chown -R root:root .
find -L .  -perm /111 -a \! -perm 755 -a -exec chmod 755 {} \+ -o \
        \! -perm /111 -a \! -perm 644 -a -exec chmod 644 {} \+

# first, the compiler itself:
cd $PRGNAM-$TARVER

CFLAGS="$SLKCFLAGS" \
./configure \
  $TLSOPT \
  --prefix=/usr \
  --mandir=/usr/man \
  --libdir=/usr/lib${LIBDIRSUFFIX} \
  --libexecdir=/usr/libexec/$PRGNAM \
  --build=$ARCH-slackware-linux

# no install-strip, but binaries are already stripped by default.
make
make install DESTDIR=$PKG

gzip -9 $PKG/usr/man/man?/*.?
# Don't overwrite Slackware's man page.
mv $PKG/usr/man/man1/cpp.1.gz $PKG/usr/man/man1/pcpp.1.gz

# why are there no docs in the @##!$^ tarball?!
mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild

# license is BSD-style, in comments in the code.
sed -n '/Copyright/,/^ *$/s,^...,,p' cc/cc/cc.c \
  > $PKG/usr/doc/$PRGNAM-$VERSION/LICENSE

# now, build the libs. we don't attempt to build them with the just-built
# pcc (maybe possible, but not worth the effort).
cd $TMP/$PRGNAM/$PRGNAM-libs-$TARVER

CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
./configure \
  --prefix=/usr \
  --libdir=/usr/lib${LIBDIRSUFFIX} \
  --build=$ARCH-slackware-linux

# pcc-libs installs nothing we can strip.
make
make install DESTDIR=$PKG

# there is a bit of documentation included with pcc-libs, but nothing
# really relevant unless you're hacking on pcc itself, not gonna bother.

mkdir -p $PKG/install
sed -e "s,@WITHCC@,$WITHCC," \
    -e "s,@TLSOPT@,$TLSOPT," \
	$CWD/slack-desc > $PKG/install/slack-desc

cd $PKG
/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE