summaryrefslogtreecommitdiffstats
path: root/current/gcc/gcc-static.SlackBuild
blob: 431fa626336c4394d1e7976c88e80f9a184e3c48 (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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#!/bin/sh
# GCC package build script (written by volkerdi@slackware.com)
# Updated by Eric Hameleers,
# to only build a static gcc used to bootstrap a multilib compiler suite.
#
# Copyright 2003, 2004  Slackware Linux, Inc., Concord, California, USA
# Copyright 2005, 2006, 2007, 2008, 2009  Patrick J. Volkerding, Sebeka, MN, USA
# All rights reserved.
#
# Redistribution and use of this script, with or without modification, is
# permitted provided that the following conditions are met:
#
# 1. Redistributions of this script must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#
#  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
#  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
#  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
#  EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
#  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
#  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
#  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
#  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
#  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
#  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#

VERSION=4.3.3
ARCH=${ARCH:-x86_64}
TARGET=$ARCH-slackware-linux
BUILD=${BUILD:-4alien}

# How many jobs to run in parallel:
NUMJOB=" -j 4 "

if [ "$ARCH" = "i486" ]; then
  SLKCFLAGS="-O2 -march=i486 -mtune=i686"
  LIBDIRSUFFIX=""
elif [ "$ARCH" = "i586" ]; then
  SLKCFLAGS="-O2 -march=i586 -mtune=i686"
  LIBDIRSUFFIX=""
elif [ "$ARCH" = "i686" ]; then
  SLKCFLAGS="-O2 -march=i686"
  LIBDIRSUFFIX=""
elif [ "$ARCH" = "s390" ]; then
  SLKCFLAGS="-O2"
  LIBDIRSUFFIX=""
elif [ "$ARCH" = "x86_64" ]; then
  SLKCFLAGS="-O2 -fPIC"
  LIBDIRSUFFIX="64"
fi

CWD=$(pwd)
# Temporary build location.  This should *NOT* be a directory
# path a non-root user could create later...
TMP=/gcc-$(mcookie)

# This is the main DESTDIR target:
PKG1=$TMP/package-gcc

# Clear the build locations:
if [ -d $TMP ]; then
  rm -rf $TMP
fi
mkdir -p $PKG1/usr/doc/gcc-$VERSION

# Insert package descriptions:
mkdir -p $PKG1/install
cat $CWD/slack-desc.gcc > $PKG1/install/slack-desc

cd $TMP
tar xvf $CWD/gcc-$VERSION.tar.?z*

# install docs
( cd gcc-$VERSION
  # Smite the fixincludes:
  zcat $CWD/gcc-no_fixincludes.diff.gz | patch -p1 --verbose --backup --suffix=.orig || exit 1
  # Fix perms/owners
  chown -R root:root .
  find . -perm 777 -exec chmod 755 {} \;
  find . -perm 775 -exec chmod 755 {} \;
  find . -perm 754 -exec chmod 755 {} \;
  find . -perm 664 -exec chmod 644 {} \;
  mkdir -p $PKG1/usr/doc/gcc-$VERSION
  # Only the most recent ChangeLog... shouldn't be too big. :)
  cp -a \
    BUGS COPYING* ChangeLog \
    ChangeLog.tree-ssa FAQ INSTALL \
    LAST_UPDATED MAINTAINERS NEWS \
    README* *.html \
  $PKG1/usr/doc/gcc-$VERSION

  mkdir -p $PKG1/usr/doc/gcc-${VERSION}/gcc
  ( cd gcc
    cp -a \
      ABOUT* COPYING* LANG* ONEWS README* SERVICE \
    $PKG1/usr/doc/gcc-$VERSION/gcc

  # Add the SlackBuild:
  cat $0 > $PKG1/usr/doc/gcc-$VERSION/gcc-static.SlackBuild
  chmod 644 $PKG1/usr/doc/gcc-$VERSION/gcc-static.SlackBuild

  ) || exit 1

)
# build gcc
( mkdir gcc.build.lnx;
  cd gcc.build.lnx;

  if [ "$ARCH" != "x86_64" ]; then
    GCC_ARCHOPTS="--with-arch=$ARCH"
  else
    GCC_ARCHOPTS="--enable-multilib"
  fi
 
  # These should not be set:
  unset CFLAGS
  unset CXXFLAGS

  # So that the build does not drag in the non-multilib host headers:
  mkdir -p $TMP/include
  touch $TMP/include/limits.h

  ../gcc-$VERSION/configure \
     --with-local-prefix=$TMP \
     --prefix=/usr \
     --libdir=/usr/lib$LIBDIRSUFFIX \
     --without-headers \
     --with-newlib \
     --disable-shared \
     --disable-nls \
     --disable-decimal-float \
     --disable-libgomp \
     --disable-libmudflap \
     --disable-libssp \
     --disable-threads \
     --enable-languages=c \
     --verbose \
     $GCC_ARCHOPTS \
     --target=${TARGET} \
     --build=${TARGET} \
     --host=${TARGET} || exit 1

  # Start the build:

  make all-gcc all-target-libgcc

  # Set GCCCHECK=something to run the tests
  if [ ! -z $GCCCHECK ]; then
    make $NUMJOB check
  fi

  make install-gcc install-target-libgcc DESTDIR=$PKG1

# Be sure the "specs" file is installed.
if [ ! -r $PKG1/usr/lib${LIBDIRSUFFIX}/gcc/${ARCH}-slackware-linux/${VERSION}/specs ]; then
  cat gcc/specs > $PKG1/usr/lib${LIBDIRSUFFIX}/gcc/${ARCH}-slackware-linux/${VERSION}/specs
fi

  # This is provided by binutils, so delete it here:
  rm -f $PKG1/usr/lib${LIBDIRSUFFIX}/libiberty.a
  rm -f $PKG1/usr/lib/libiberty.a # catch-all

  # Fix stuff up:
  ( cd $PKG1/usr/info ; rm dir ; gzip -9 * )
  ( cd $PKG1
    # *not* ${LIBDIRSUFFIX}
    mkdir -p lib
    cd lib
    ln -sf /usr/bin/cpp .
  )
  ( cd $PKG1/usr/bin
    mv gcc gcc-$VERSION
    ln -sf gcc-$VERSION gcc
    ln -sf gcc cc
    ln -sf gcc-$VERSION ${TARGET}-gcc
    ln -sf gcc-$VERSION ${TARGET}-gcc-$VERSION
  )
  ( cd $PKG1/usr/man
    gzip -9 */*
    cd man1
    ln -sf g++.1.gz c++.1.gz
    ln -sf gcc.1.gz cc.1.gz
  )  

# keep a log
) 2>&1 | tee $TMP/gcc.build.log

# Filter all .la files (thanks much to Mark Post for the sed script):
( cd $TMP
  for file in $(find . -type f -name "*.la") ; do
    cat $file | sed -e 's%-L/gcc-[[:graph:]]* % %g' > $TMP/tmp-la-file
    cat $TMP/tmp-la-file > $file
  done
  rm $TMP/tmp-la-file
)

## Strip bloated binaries and libraries:
for dir in $PKG1; do
  ( cd $dir
    find . -name "lib*so*" -exec strip --strip-unneeded "{}" \;
    find . -name "lib*a" -exec strip -g "{}" \;
    strip --strip-unneeded usr/bin/* 2> /dev/null
    find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
    find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
  )
done

( cd $PKG1
  /sbin/makepkg -l y -c n $TMP/gcc-${VERSION}_static-$ARCH-$BUILD.txz )

echo
echo "Slackware GCC "static" package build complete!"
echo