summaryrefslogtreecommitdiffstats
path: root/scripts/gccnewlib/gccnewlib.add
blob: 5fc6e2fe4f0fd25a3a765588aa235f9edbb2d087 (plain) (blame)
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389

%define gcc_version	@gcc_version@
%define newlib_version	@newlib_version@

%define gcc_target	@target_alias@

Name:           %{rpmprefix}%{gcc_target}-gcc-newlib
Summary:        gcc and newlib C Library for %{gcc_target}.
Group:          %{rpmgroup}
Release:        @Release@
License:        gcc is GPL/LGPL ; newlib no has restrictions on run-time usage

Packager:     	ralf.corsepius@rtems.org and joel@OARcorp.com

Version:      	gcc%{gcc_version}newlib%{newlib_version}

Source0:	ftp://ftp.gnu.org/pub/gnu/gcc/gcc-%{gcc_version}/gcc-%{gcc_version}@gcc_suffix@
Source1:	ftp://sources.redhat.com/pub/newlib/newlib-%{newlib_version}@newlib_suffix@
@PATCH0@
@PATCH1@
Source98:	brp-rtems-strip.in
Source99:	brp-rtems-compress.in

%define __os_install_post ./brp-rtems-compress && ./brp-rtems-strip

BuildRequires:	texinfo >= 4.2
BuildRequires:	%{rpmprefix}%{gcc_target}-binutils


#
# The original sources are not included in the source RPM.
# If we included them, then the source RPMs for each target
# would duplicate MBs of source unnecessarily.  This is 
# a duplication of over 30 MBs of source for each of
# the more than 10 targets it is possible to build.
#
# You can get them yourself from the Internet and copy them to
# your /usr/src/redhat/SOURCES directory ($RPM_SOURCE_DIR).
# Or you can try the ftp options of rpm :-)
#
%{?!_with_sources:NoSource:	0}
%{?!_with_sources:NoSource:	1}

# default languages to build
%define _cxx		1
%define _fortran	0
%define _gcj		0
%define _gnat		0
%define _objc		0
%define _libgcj 	0


# custom defaults for specific targets
%if "%{gcc_target}" == "arm-rtems@osversion@"
# Gnat lacks arm support
%define _gnat		0
%endif

%if "%{gcc_target}" == "avr-rtems@osversion@"
%define _cxx		0
%define _fortran	0
%define _gcj		0
%define _gnat		0
%endif

%if "%{gcc_target}" == "h8300-rtems@osversion@"
%define _fortran	0
%define _gcj		0
%define _gnat		0
%endif

%if "%{gcc_target}" == "sh-rtems@osversion@"
# Triggers an ICE in GCC-4.0.0
%define _gnat		0
%endif

%if "%{gcc_target}" == "tic4x-rtems@osversion@"
%define _cxx		0
%define _gnat		0
%define _gcj		0
%define _fortran	0
%endif


# Allow the user to build arbitrary languages
%{?_with_cxx:%define _cxx 1}
%{?_with_fortran:%define _fortran 1}
%{?_with_gcj:%define _gcj 1}
%{?_with_gnat:%define _gnat 1}
%{?_with_objc:%define _objc 1}
%{?_with_libgcj:%define _libgcj 1}

# Allow the user to suppress building languages
%{?_without_cxx:%define _cxx 0}
%{?_without_fortran:%define _fortran 0}
%{?_without_gcj:%define _gcj 0}
%{?_without_gnat:%define _gnat 0}
%{?_without_objc:%define _objc 0}
%{?_without_libgcj:%define _libgcj 0}

%define build_cxx	%_cxx
%if "%{gcc_version}" >= "4.0.0"
%define build_f95	%_fortran
%define build_g77	0
%else
%define build_f95	0
%define build_g77 	%_fortran
%endif
%define build_gnat	%_gnat
%define build_gcj	%_gcj
%define build_objc	%_objc
%define build_libgcj	%_libgcj

%if %build_gcj
# Building gcj requires bison and zlib
BuildRequires:	bison
%endif

%if "%_vendor" == "redhat"
%if %build_gcj
BuildRequires:	zlib-devel
%endif
%if %build_gnat
# Building gnat requires gnat
# This really isn't available until RedHat 8.0.  How to conditionalize this?
BuildRequires:	gcc-gnat
# Urgh, building gnat requires the target c-toolchain
BuildRequires:  %{rpmprefix}%{gcc_target}-gcc < %{version}-%{release}
%endif
%if %build_f95
BuildRequires: gmp-devel
%endif
%endif

%if "%{gcc_version}" >= "3.4"
%define gcclib %{_libdir}/gcc
%define gccexec %{_libexecdir}/gcc
%else
%define gcclib %{_libdir}/gcc-lib
%define gccexec %{_libdir}/gcc-lib
%endif

%description
RTEMS is an open source operating system for embedded systems.

This is gcc's and newlib C Library's sources with patches for RTEMS.

%prep
# untar the sources inside %{gcc_target}-gcc-newlib
%setup -c -T -n %{name}-%{version} -a0 -a1

cd gcc-%{gcc_version}
%{?PATCH0:%patch0 -p1}
cd ..
cd newlib-%{newlib_version}
%{?PATCH1:%patch1 -p1}
cd ..

sed 's,@BRPSTRIPPATH@,.%_bindir .%_prefix/%gcc_target/bin,' \
  %SOURCE98 > brp-rtems-strip
chmod +x brp-rtems-strip

sed 's,@BRPCOMPRESSPATH@,.%_mandir/man* .%_infodir,' \
  %SOURCE99 > brp-rtems-compress
chmod +x brp-rtems-compress

  cd gcc-%{gcc_version}
    sed -e 's/\(version_string.* = \"[^\"]*\)/\1 (RTEMS gcc-%{gcc_version}-@gcc_patch_version@\/newlib-%{newlib_version}-@newlib_patch_version@-@Release@)/' \
    gcc/version.c > gcc/version.c~
    mv gcc/version.c~  gcc/version.c 

  # Fix timestamps
    contrib/gcc_update --touch
  cd ..

  # Copy the C library into gcc's source tree
  ln -s ../newlib-%{newlib_version}/newlib gcc-%{gcc_version}
  test -d build || mkdir build

%build
  cd build

  languages="c"
%if %build_cxx
  languages="$languages,c++"
%endif
%if %build_g77
  languages="$languages,g77"
%endif
%if %build_f95
  languages="$languages,f95"
%endif
%if %build_gcj
  languages="$languages,java"
%endif
%if %build_objc
  languages="$languages,objc"
%endif
%if %build_gnat
  languages="$languages,ada"
%endif
%if %build_libgcj
  optargs="--enable-libgcj"
%endif
  export PATH="%{_bindir}:${PATH}"
  ../gcc-%{gcc_version}/configure \
    --prefix=%{_prefix} \
    --bindir=%{_bindir} \
    --includedir=%{_includedir} \
    --libdir=%{_libdir} \
    --mandir=%{_mandir} \
    --infodir=%{_infodir} \
    --build=%_build --host=%_host \
    --target=%{gcc_target} \
    --with-gnu-as --with-gnu-ld --with-newlib --verbose \
    --with-system-zlib --disable-nls \
    --enable-version-specific-runtime-libs \
    --enable-threads=rtems \
    --enable-languages=$languages $optargs

%if "%_host" != "%_build"
  # Bug in gcc-3.2.1:
  # Somehow, gcc doesn't get syslimits.h right for Cdn-Xs
  test -d gcc/include || mkdir -p gcc/include
  cp ../gcc-%{gcc_version}/gcc/gsyslimits.h gcc/include/syslimits.h
%endif

  make all
  make info

%install
  export PATH="%{_bindir}:${PATH}"
  rm -rf $RPM_BUILD_ROOT

  cd build
# Bug in gcc-2.95.1: It doesn't build this installation directory
# If it doesn't find it, gcc doesn't install %{gcc_target}/bin/gcc
%if "%{gcc_version}" < "3.0"
  mkdir -p $RPM_BUILD_ROOT%{_prefix}/%{gcc_target}/bin
%endif

  make prefix=$RPM_BUILD_ROOT%{_prefix} \
    bindir=$RPM_BUILD_ROOT%{_bindir} \
    libdir=$RPM_BUILD_ROOT%{_libdir} \
    includedir=$RPM_BUILD_ROOT%{_includedir} \
    mandir=$RPM_BUILD_ROOT%{_mandir} \
    infodir=$RPM_BUILD_ROOT%{_infodir} \
    install
  cd %{gcc_target}/newlib
  make prefix=$RPM_BUILD_ROOT%{_prefix} \
    bindir=$RPM_BUILD_ROOT%{_bindir} \
    libdir=$RPM_BUILD_ROOT%{_libdir} \
    includedir=$RPM_BUILD_ROOT%{_includedir} \
    mandir=$RPM_BUILD_ROOT%{_mandir} \
    infodir=$RPM_BUILD_ROOT%{_infodir} \
    install-info
  # cd back to build/
  cd ../..

  # Bug in gcc-3.x: It puts the build dirs into *.la files

  # host library
  rm -f  ${RPM_BUILD_ROOT}%{_prefix}/lib/libiberty.a

  # We use the version from binutils
  rm -f $RPM_BUILD_ROOT%{_bindir}/%{gcc_target}-c++filt%{_exeext}

%if %build_gnat
  # Seemingly a VAX tool. Not meaningful for RTEMS
  rm -f $RPM_BUILD_ROOT%{_bindir}/vxaddr2line%{_exeext}
%endif

  # We don't ship info/dir
  rm -f $RPM_BUILD_ROOT%{_infodir}/dir
  touch $RPM_BUILD_ROOT%{_infodir}/dir

%if "%{_prefix}" == "/usr"
# Conflict with a native GCC's infos
  rm -rf $RPM_BUILD_ROOT%{_infodir}

# Conflict with a native GCC's man pages
  rm -rf $RPM_BUILD_ROOT%{_mandir}/man7
%endif

%if %build_f95
#  # Bug in gcc-4.0.0pre
#  mv $RPM_BUILD_ROOT%{_bindir}/gfortran $RPM_BUILD_ROOT%{_bindir}/%{gcc_target}-gfortran
%endif

%if "%{gcc_version}" >= "3.4"
  # Bug in gcc-3.4.0pre
  rm -f $RPM_BUILD_ROOT%{_bindir}/%{gcc_target}-%{gcc_target}-gcjh%{_exeext}
%endif

%if "%{gcc_version}" >= "3.3"
  # Bug in gcc-3.3.x/gcc-3.4.x: Despite we don't need fixincludes, it installs
  # the fixinclude-install-tools
  rm -rf ${RPM_BUILD_ROOT}%{gcclib}/%{gcc_target}/%{gcc_version}/install-tools
  rm -rf ${RPM_BUILD_ROOT}%{gccexec}/%{gcc_target}/%{gcc_version}/install-tools
%endif

%if "%{gcc_version}" < "3.0"
  # Bug in gcc-2.95.x: It bogusly tries to share cpp for all targets.
  # Rename it to target_alias-cpp
  if test -f $RPM_BUILD_ROOT%{_bindir}/cpp%{_exeext};
  then
    mv $RPM_BUILD_ROOT%{_bindir}/cpp%{_exeext} \
      $RPM_BUILD_ROOT%{_bindir}/%{gcc_target}-cpp%{_exeext}
  fi
%endif

  rm -f dirs ;
  echo "%defattr(-,root,root)" >> dirs
%if "%{_prefix}" != "/usr"
  echo "%dir %{_libdir}" >> dirs ;
%endif
  echo "%dir %{gcclib}" >> dirs ;
  echo "%dir %{gcclib}/%{gcc_target}" >> dirs ;

  # Collect multilib subdirectories
  f=`gcc/xgcc -Bgcc/ --print-multi-lib | sed -e 's,;.*$,,'`

  TGTDIR="%{gcclib}/%{gcc_target}/%{gcc_version}"
  for i in $f; do
    case $i in
    \.) echo "%dir ${TGTDIR}" >> dirs
      ;;
    *)  echo "%dir ${TGTDIR}/$i" >> dirs
      ;;
    esac
  done

  TGTDIR="%{_prefix}/%{gcc_target}/lib"
  for i in $f; do
    case $i in
    \.) echo "%dir ${TGTDIR}" >> dirs
      ;;
    *)  echo "%dir ${TGTDIR}/$i" >> dirs
      ;;
    esac
  done

  # Collect files to go into different packages
  cp dirs files.gcc
  cp dirs files.g77
  cp dirs files.gfortran
  cp dirs files.objc
  cp dirs files.gcj
  cp dirs files.g++

  TGTDIR="%{gcclib}/%{gcc_target}/%{gcc_version}"
  f=`find ${RPM_BUILD_ROOT}${TGTDIR} ! -type d -print | sed -e "s,^$RPM_BUILD_ROOT,,g"`;
  for i in $f; do
    case $i in
    *lib*.la) rm ${RPM_BUILD_ROOT}/$i ;; # ignore: gcc produces bogus libtool libs
    *f771) ;;
    *f951) ;;
    *cc1) ;;
    *cc1obj) ;;
    *cc1plus) ;; # ignore: explicitly put into rpm elsewhere
    *collect2) ;;
    *libobjc*) echo "$i" >> files.objc ;;
    *include/objc*) ;;
    *include/g++*);;
    *include/c++*);;
    *adainclude*);;
    *adalib*);;
    *gnat1);;
    *jc1) ;;
    *jvgenmain) ;;
    *libgfortran*.a) echo "$i" >> files.gfortran ;;
    *libstdc++.a) echo "$i" >> files.g++ ;;
    *libsupc++.a) echo "$i" >> files.g++ ;;
    *) echo "$i" >> files.gcc ;;
    esac
  done

  TGTDIR="%{_prefix}/%{gcc_target}/lib"
  f=`find ${RPM_BUILD_ROOT}${TGTDIR} ! -type d -print | sed -e "s,^$RPM_BUILD_ROOT,,g"`;
  for i in $f; do
    case $i in
    *lib*.la) rm ${RPM_BUILD_ROOT}/$i;; # ignore - gcc produces bogus libtool libs
    *libiberty.a) rm ${RPM_BUILD_ROOT}/$i ;; # ignore - GPL'ed
# all other files belong to gcc
    *) echo "$i" >> files.gcc ;; 
    esac
  done

  cd ..