Wed, 30 Mar 2011 19:35:16 +0200
Finally correct packaging logic enough to allow for successful building:
Force Java dependency to C++ and POSIX threads to satisfy buildtime
requirements of GCJ, add conditional java dependency to infozip as
required by libjava/configure, remove outdated fortran conditions,
correct buildconf causing jcf-dump target to fail, add and improve
warnings regarding profile feedback, build duration, and parallel
make, correct make environment when building C++ dependent languages,
and introduce new helpful comments.
1 ##
2 ## gcc.spec -- OpenPKG RPM Package Specification
3 ## Copyright (c) 2000-2010 OpenPKG Foundation e.V. <http://openpkg.net/>
4 ##
5 ## Permission to use, copy, modify, and distribute this software for
6 ## any purpose with or without fee is hereby granted, provided that
7 ## the above copyright notice and this permission notice appear in all
8 ## copies.
9 ##
10 ## THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
11 ## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
12 ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
13 ## IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
14 ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
15 ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
16 ## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
17 ## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
18 ## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
19 ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
20 ## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
21 ## SUCH DAMAGE.
22 ##
24 # package version
25 %define V_full 4.6.0
26 %define V_comp %nil
28 # package information
29 Name: gcc
30 Summary: GNU Compiler Collection
31 URL: http://gcc.gnu.org/
32 Vendor: Free Software Foundation
33 Packager: OpenPKG Foundation e.V.
34 Distribution: OpenPKG Community
35 Class: CORE
36 Group: Compiler
37 License: GPL
38 Version: %{V_full}
39 Release: 20110330
41 # package options
42 %option with_binutils yes
43 %option with_cxx yes
44 %option with_objc no
45 %option with_java no
46 %option with_fortran no
47 %option with_optimize yes
48 %option with_profile no
49 %option with_threads yes
50 %option with_multilib no
52 # fix intermodule dependencies implicitly
53 %if "%{with_java}" == "yes"
54 %define with_cxx yes
55 %define with_threads yes
56 %endif
58 # list of sources
59 Source0: ftp://gcc.gnu.org/pub/gcc/releases/gcc-%{V_full}/gcc-core-%{V_full}.tar.bz2
60 Source1: ftp://gcc.gnu.org/pub/gcc/releases/gcc-%{V_full}/gcc-g++-%{V_full}.tar.bz2
61 Source2: ftp://gcc.gnu.org/pub/gcc/releases/gcc-%{V_full}/gcc-objc-%{V_full}.tar.bz2
62 Source3: ftp://gcc.gnu.org/pub/gcc/releases/gcc-%{V_full}/gcc-java-%{V_full}.tar.bz2
63 Source4: ftp://gcc.gnu.org/pub/gcc/releases/gcc-%{V_full}/gcc-fortran-%{V_full}.tar.bz2
64 Patch0: gcc.patch
66 # build information
67 Prefix: %{l_prefix}
68 BuildRoot: %{l_buildroot}
69 BuildPreReq: OpenPKG, openpkg >= 20060823, make
70 PreReq: OpenPKG, openpkg >= 20060823
71 BuildPreReq: mpc, mpfr, gmp
72 PreReq: mpc, mpfr, gmp
73 %if "%{with_binutils}" == "yes"
74 BuildPreReq: binutils >= 2.14
75 PreReq: binutils >= 2.14
76 %endif
77 %if "%{with_cxx}" == "yes"
78 BuildPreReq: libiconv
79 PreReq: libiconv
80 %endif
81 %if "%{with_java}" == "yes"
82 BuildPreReq: zlib, infozip
83 PreReq: zlib
84 %endif
85 AutoReq: no
86 AutoReqProv: no
88 %description
89 The GNU Compiler Collection (GCC) provides standard conforming and
90 highly portable compilers for the ISO C, ISO C++, Objective-C,
91 Fortran and Java languages.
93 %track
94 prog gcc = {
95 version = %{V_full}
96 url = ftp://gcc.gnu.org/pub/gcc/releases/
97 regex = gcc-(4\.\d+\.\d+)
98 url = ftp://gcc.gnu.org/pub/gcc/releases/gcc-__NEWVER__/
99 regex = gcc-core-(\d+\.\d+\.\d+)\.tar\.bz2
100 }
102 %prep
103 %setup -q
104 %if "%{with_cxx}" == "yes"
105 %setup -q -T -D -b 1
106 %endif
107 %if "%{with_objc}" == "yes"
108 %setup -q -T -D -b 2
109 %endif
110 %if "%{with_java}" == "yes"
111 %setup -q -T -D -b 3
112 %endif
113 %if "%{with_fortran}" == "yes"
114 %setup -q -T -D -b 4
115 %endif
116 %patch -p0
117 %{l_shtool} subst \
118 -e 's;\(instname="\$dir/\$name"\)i;\1;' \
119 ltmain.sh
120 %{l_shtool} subst -v -s \
121 -e 's;\(gmplibs="-lmpc\) \(-lmpfr -lgmp\);\1 -lm \2;' \
122 configure
123 %{l_shtool} subst -v -s \
124 -e 's;\(LDEXP_LIB=\)"$LIBS";\1"$LDFLAGS";' \
125 -e 's;PREFIX_INCLUDE_DIR;PREFIX_INCLUDE_DIR_DISABLED;g' \
126 gcc/configure
127 %{l_shtool} subst \
128 -e 's;[ \t]*-W[a-zA-Z0-9_\-][a-zA-Z0-9_\-]*,*;;g' \
129 lto-plugin/Makefile.in
130 %{l_shtool} subst \
131 -e 's;-rpath *[^ \t][^ \t]*;;g' \
132 -e 's;--tag=disable-static;--tag=disable-shared;g' \
133 -e 's;\.\./libiberty/libiberty\.a;-L../libiberty -liberty;g' \
134 -e 's;\.\./libiberty/pic/libiberty\.a;-L../libiberty/pic -liberty;g' \
135 lto-plugin/Makefile.in
136 if [ ".%{V_comp}" != . ]; then
137 %{l_shtool} subst -v -s \
138 -e 's;(libdir)/gcc/;(libdir)/gcc%{V_comp}/;' \
139 `find . -name Makefile.in -type f -print`
140 fi
141 %{l_shtool} subst \
142 -e 's;^\(do-compare\) *\(=.*\);#\1-shouldnt-be-defined-here \2;' \
143 config/*.mk
144 case "%{l_platform -t}" in
145 amd64-linux* )
146 %{l_shtool} subst \
147 -e 's/GLIBCXX_IS_NATIVE=false/GLIBCXX_IS_NATIVE=true/g' \
148 -e 's/test x.gcc_no_link = xyes/false/g' \
149 libstdc++-v3/configure
150 ;;
151 esac
152 %{l_shtool} subst \
153 -e 's;<iconv\.h>;"%{l_prefix}/include/iconv.h";' \
154 libstdc++-v3/include/ext/codecvt_specializations.h
156 %build
157 # create build subdirectory
158 %{l_shtool} mkdir -p obj
159 cd obj
161 # locate ld(1) and as(1) accordingly
162 %if "%{with_binutils}" == "yes"
163 # allow OpenPKG binutils
164 LD=%{l_tool_locate ld ld}
165 AS=%{l_tool_locate as as}
166 %else
167 # ignore OpenPKG binutils
168 LD=`PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/ccs/bin:/opt/bin:/opt/sbin:/usr/local/bin:/usr/local/sbin which ld`
169 AS=`PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/ccs/bin:/opt/bin:/opt/sbin:/usr/local/bin:/usr/local/sbin which as`
170 %endif
171 l_with_gnu_ld_as=""
172 echo $LD | grep '^/' >/dev/null && l_with_gnu_ld_as="--with-ld=$LD"
173 echo $AS | grep '^/' >/dev/null && l_with_gnu_ld_as="${l_with_gnu_ld_as} --with-as=$AS"
174 $LD --version </dev/null 2>/dev/null | grep "^GNU ld " >/dev/null && l_with_gnu_ld_as="${l_with_gnu_ld_as} --with-gnu-ld" || l_with_gnu_ld_as="${l_with_gnu_ld_as} --without-gnu-ld"
175 $AS --version </dev/null 2>/dev/null | grep "^GNU assembler " >/dev/null && l_with_gnu_ld_as="${l_with_gnu_ld_as} --with-gnu-as" || l_with_gnu_ld_as="${l_with_gnu_ld_as} --without-gnu-as"
177 # determine threads use
178 %if "%{with_threads}" == "yes"
179 l_enable_threads="posix"
180 %else
181 l_enable_threads="single"
182 %endif
184 # determine language use
185 l_enable_languages="c"
186 %if "%{with_cxx}" == "yes"
187 l_enable_languages="${l_enable_languages},c++"
188 %endif
189 %if "%{with_objc}" == "yes"
190 l_enable_languages="${l_enable_languages},objc"
191 %endif
192 %if "%{with_java}" == "yes"
193 l_enable_languages="${l_enable_languages},java"
194 %endif
195 %if "%{with_fortran}" == "yes"
196 l_enable_languages="${l_enable_languages},f95"
197 %endif
199 # disable GNU iconv use
200 ( echo "am_cv_func_iconv=no"
201 echo "am_cv_lib_iconv=no"
202 ) >config.cache
203 # platforms failing 'compare' make target (see prep as well)
204 case "%{l_platform -t}" in
205 *i?86-sunos* ) echo "gcc_cv_prog_cmp_skip=true" >>config.cache ;;
206 *amd64-linux* ) echo "gcc_cv_prog_cmp_skip=true" >>config.cache ;;
207 esac
209 # configure the package
210 LD="$LD" \
211 AS="$AS" \
212 CC="%{l_cc}" \
213 CFLAGS="%{l_cflags}" \
214 %if "%{with_cxx}" == "yes"
215 CPPFLAGS="%{l_cppflags}" \
216 LDFLAGS="%{l_ldflags}" \
217 %endif
218 CONFIG_SHELL="%{l_bash}" \
219 GREP="%{l_bash}" \
220 ../configure \
221 --with-bugurl="http://openpkg.org/" \
222 --with-pkgversion="%{l_openpkg_release -F "OpenPKG-%%t"}" \
223 --cache-file=./config.cache \
224 --srcdir=`pwd`/.. \
225 --prefix=%{l_prefix} \
226 --exec-prefix=%{l_prefix} \
227 --mandir=%{l_prefix}/man \
228 --infodir=%{l_prefix}/info \
229 --includedir=%{l_prefix}/include/gcc%{V_comp} \
230 --libexecdir=%{l_prefix}/libexec/gcc%{V_comp} \
231 --with-gxx-include-dir=%{l_prefix}/include/g++%{V_comp} \
232 --with-local-prefix=%{l_prefix}/lib/gcc%{V_comp} \
233 --enable-languages="${l_enable_languages}" \
234 --enable-threads="${l_enable_threads}" \
235 --disable-maintainer-mode \
236 --disable-shared \
237 --disable-nls \
238 %if "%{with_java}" == "yes"
239 --with-system-zlib \
240 %endif
241 %if "%{with_multilib}" == "yes"
242 --enable-multilib \
243 %else
244 --disable-multilib \
245 %endif
246 %if "%{with_cxx}" == "yes"
247 --with-libiconv-prefix=%{l_prefix} \
248 %endif
249 --with-gmp=%{l_prefix} \
250 --with-mpfr=%{l_prefix} \
251 --with-mpc=%{l_prefix} \
252 ${l_with_gnu_ld_as}
254 # determine build flags
255 l_ccisgcc=no
256 if [ ".`(%{l_cc} -v; %{l_cc} --version) </dev/null 2>&1 | grep -i 'gcc'`" != . ]; then
257 l_ccisgcc=yes
258 fi
259 l_cflags=""
260 l_cxxflags=""
261 l_boot_cflags=""
262 l_libcflags="-g"
263 l_libcxxflags="-g"
264 # at least GNU as from GNU binutils supports -pipe always
265 "$AS" --version </dev/null 2>/dev/null | grep "^GNU assembler" >/dev/null && {
266 l_boot_cflags="$l_boot_cflags -pipe"
267 l_libcxxflags="$l_libcxxflags -pipe"
268 }
269 %if "%{with_optimize}" == "yes"
270 # GCC authors are not keeping up with optimized portability expectations
271 ( echo "As GCC advances its optimization logic becomes increasingly complex (and"
272 echo "buggy?) Since at least GCC 4.5, problems have been reported using arguments"
273 echo "-O, -mtune, or -march implicitly or explicitly during different bootstrap"
274 echo "stages as well as stage comparison and even the final installation."
275 echo ""
276 echo "Pay attention when building on one computer and installing on another as"
277 echo "problems may be platform specific. If in doubt, disable optimization."
278 ) | %{l_rpmtool} msg -b -t warn
279 if [ ".$l_ccisgcc" = .yes ]; then
280 l_archia32=native; l_archia64=native; l_archamd64=native
281 else
282 # CPU native detection only works with GCC (see driver-i386.c)
283 ( echo "Platform specific optimization is enabled, but detection of appropriate"
284 echo "native architecture is only possible when bootstrapping GCC using a pre-"
285 echo "installed GCC. The current build is using a different compiler, so to"
286 echo "provide any optimization at all a wild guess is made and a CPU type"
287 echo "hardcoded instead of using accurate native detection."
288 echo ""
289 echo "To achieve accurate optimization of GCC please install GCC first. Then"
290 echo "build this package a second time which will use GCC to bootstrap itself."
291 ) | %{l_rpmtool} msg -b -t notice
293 # guess lowest common denominator CPU types
294 # http://en.wikipedia.org/wiki/(X86|X64-64)
295 # http://gcc.gnu.org/onlinedocs/gcc/i386-and-x86_002d64-Options.html
296 l_archia32=pentium3; l_archia64=nocona; l_archamd64=k8
297 fi
298 # this optimization logic is unportable and could cause problems
299 # if installing the resulting binary package on a different host!
300 case "%{l_platform -t}" in
301 *sun4[uv]-* ) l_boot_cflags="$l_boot_cflags -mtune=v9" ;;
302 *sun-* ) l_boot_cflags="$l_boot_cflags -mtune=v8" ;;
303 *i?86-* ) l_boot_cflags="$l_boot_cflags -march=$l_archia32" ;;
304 *ia64-* ) l_boot_cflags="$l_boot_cflags -march=$l_archia64" ;;
305 *amd64-* ) l_boot_cflags="$l_boot_cflags -march=$l_archamd64" ;;
306 * ) l_boot_cflags="$l_boot_cflags -mtune=generic" ;;
307 esac
308 l_cflags="$l_cflags -O"
309 l_boot_cflags="$l_boot_cflags -O3 -fomit-frame-pointer"
310 l_libcxxflags="$l_libcxxflags -O3 -fno-implicit-templates"
311 %else
312 # don't optimize at all to avoid problems
313 l_boot_cflags="$l_boot_cflags -O0"
314 l_libcxxflags="$l_libcxxflags -O0"
315 %endif
316 %if "%{with_profile}" == "yes"
317 # generate profile feedback
318 maketarget="profiledbootstrap"
319 loc_makeflags="%{l_mflags}"
321 # warn about exceptional build duration for profile feedback
322 ( echo "Building profile feedback on some hosts can take many days to complete!"
323 echo "Now continuing to build a profiled bootstrap with parallel make logic"
324 echo "disabled according to profiling requirements..."
325 ) | %{l_rpmtool} msg -b -t warn
327 # warn about profiled bootstrap requirement of 64-bit arithmetic
328 if [ ".$l_ccisgcc" != .yes ]; then
329 ( echo "A preinstalled GCC was not detected although one is recommended for"
330 echo "building a profiled bootstrap. Buildtime or runtime errors can occur if"
331 echo "the compiler used to build profile feedback doesn't support 64-bit math."
332 echo ""
333 echo "If in doubt, stop now and start the build again with profiling disabled."
334 ) | %{l_rpmtool} msg -b -t warn
335 fi
336 %else
337 # build in three stages
338 maketarget="bootstrap"
339 loc_makeflags="%{l_mflags -O}"
340 %endif
341 case "%{l_platform -t}" in
342 *64-* ) l_cflags="$l_cflags -fPIC"; l_cxxflags="$l_cxxflags -fPIC" ;;
343 esac
344 %if "%{with_cxx}" == "yes"
345 l_cflags="$l_cflags %{l_cppflags}"
346 l_cxxflags="$l_cxxflags %{l_cppflags}"
347 l_libcflags="$l_libcflags %{l_cppflags}"
348 l_libcxxflags="$l_libcxxflags %{l_cppflags}"
349 %endif
351 # build the package
352 MAKE="%{l_make} ${loc_makeflags}" \
353 %{l_make} ${loc_makeflags} \
354 GREP="grep" \
355 MAKE="%{l_make} ${loc_makeflags}" \
356 BOOT_CFLAGS="${l_boot_cflags}" \
357 CFLAGS="${l_cflags}" \
358 CXXFLAGS="${l_cxxflags}" \
359 %if "%{with_cxx}" == "yes"
360 CPPFLAGS="%{l_cppflags}" \
361 LDFLAGS="%{l_ldflags}" \
362 BOOT_LDFLAGS="%{l_ldflags}" \
363 %endif
364 LIBCFLAGS="${l_libcflags}" \
365 LIBCXXFLAGS="${l_libcxxflags}" \
366 $maketarget
368 %install
369 rm -rf $RPM_BUILD_ROOT
371 # fetch GNU platform triple
372 triple=`./config.guess`
374 # perform the standard installation procedure
375 ( cd obj
376 %{l_make} %{l_mflags} install DESTDIR=$RPM_BUILD_ROOT
377 ) || exit $?
379 # cleanup installation tree
380 mv $RPM_BUILD_ROOT%{l_prefix}/lib/{lib*.a,*.spec} \
381 $RPM_BUILD_ROOT%{l_prefix}/lib/gcc%{V_comp}/${triple}/[0-9]*/ \
382 >/dev/null 2>&1 || true
383 mv $RPM_BUILD_ROOT%{l_prefix}/lib64/{lib*.a,*.spec} \
384 $RPM_BUILD_ROOT%{l_prefix}/lib/gcc%{V_comp}/${triple}/[0-9]*/ \
385 >/dev/null 2>&1 || true
386 dirs=""
387 for multilib in `$RPM_BUILD_ROOT%{l_prefix}/bin/gcc --print-multi-lib`; do
388 subdir=`echo "$multilib" | sed -e 's/;.*$//'`
389 [ ".$subdir" = .. ] && continue
390 mv $RPM_BUILD_ROOT%{l_prefix}/lib/$subdir/lib*.a \
391 $RPM_BUILD_ROOT%{l_prefix}/lib/gcc%{V_comp}/${triple}/[0-9]*/$subdir/ \
392 >/dev/null 2>&1 || true
393 mv $RPM_BUILD_ROOT%{l_prefix}/lib64/$subdir/lib*.a \
394 $RPM_BUILD_ROOT%{l_prefix}/lib/gcc%{V_comp}/${triple}/[0-9]*/$subdir/ \
395 >/dev/null 2>&1 || true
396 dirs="$dirs $subdir"
397 done
398 for subdir in $dirs; do
399 rm -rf $RPM_BUILD_ROOT%{l_prefix}/lib/$subdir >/dev/null 2>&1 || true
400 done
401 mv $RPM_BUILD_ROOT%{l_prefix}/${triple}/include/* \
402 $RPM_BUILD_ROOT%{l_prefix}/lib/gcc%{V_comp}/${triple}/[0-9]*/include/ \
403 >/dev/null 2>&1 || true
405 # correct hardcoded paths
406 %{l_shtool} subst \
407 -e "s;\(dependency_libs='[ \t]*-L\).*;\1%{l_prefix}/lib -L%{l_prefix}/lib/gcc%{V_comp}/${triple}/[0-9]* -liberty';" \
408 $RPM_BUILD_ROOT%{l_prefix}/lib/gcc%{V_comp}/${triple}/[0-9]*/liblto_plugin.la
410 # strip installation tree
411 rm -rf $RPM_BUILD_ROOT%{l_prefix}/${triple}
412 rm -f $RPM_BUILD_ROOT%{l_prefix}/info/dir
413 rm -rf $RPM_BUILD_ROOT%{l_prefix}/man/man7 >/dev/null 2>&1 || true
414 rm -f $RPM_BUILD_ROOT%{l_prefix}/lib/*.la >/dev/null 2>&1 || true
415 rm -rf $RPM_BUILD_ROOT%{l_prefix}/lib64 >/dev/null 2>&1 || true
416 rm -f $RPM_BUILD_ROOT%{l_prefix}/bin/*-gcc* >/dev/null 2>&1 || true
417 %if "%{with_cxx}" == "yes"
418 rm -f $RPM_BUILD_ROOT%{l_prefix}/bin/*-c++ >/dev/null 2>&1 || true
419 rm -f $RPM_BUILD_ROOT%{l_prefix}/bin/*-g++ >/dev/null 2>&1 || true
420 %endif
421 strip $RPM_BUILD_ROOT%{l_prefix}/bin/* >/dev/null 2>&1 || true
422 for prog in cc1 cc1plus collect2 cpp; do
423 strip $RPM_BUILD_ROOT%{l_prefix}/lib/gcc%{V_comp}/${triple}/[0-9]*/${prog} \
424 >/dev/null 2>&1 || true
425 done
427 # bump up installation tree
428 ln $RPM_BUILD_ROOT%{l_prefix}/bin/gcc \
429 $RPM_BUILD_ROOT%{l_prefix}/bin/cc
430 ln $RPM_BUILD_ROOT%{l_prefix}/man/man1/gcc.1 \
431 $RPM_BUILD_ROOT%{l_prefix}/man/man1/cc.1
432 %if "%{with_cxx}" == "yes"
433 ln $RPM_BUILD_ROOT%{l_prefix}/man/man1/g++.1 \
434 $RPM_BUILD_ROOT%{l_prefix}/man/man1/c++.1
435 %endif
437 # determine installation file list
438 %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT %{l_files_std}
440 %files -f files
442 %clean
443 rm -rf $RPM_BUILD_ROOT