Training courses

Kernel and Embedded Linux

Bootlin training courses

Embedded Linux, kernel,
Yocto Project, Buildroot, real-time,
graphics, boot time, debugging...

Bootlin logo

Elixir Cross Referencer

  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
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
#!/bin/sh
#	$NetBSD: mknative-gcc.old,v 1.6 2018/09/05 01:20:20 mrg Exp $
#
# Shell script for generating all the constants needed for a native
# platform build of gcc.
#
# This version is for GCC 6.4

# initialise

_TMPDIR=$2
_TOP=$3
_SRC=$4
_PLATFORM=$5
_DESTDIR=$6
_TOOLDIR=$7
_VPATH=`grep VPATH ${_TMPDIR}/Makefile | sed 's,^.*=[ 	]*,,'`
_GNU_DIST=`cd ${_VPATH}; pwd`

if [ -z "$_DESTDIR" ]; then
	echo "\$_DESTDIR is empty" 2>&1
	exit 1
fi

. $_TOP/tools/gcc/mknative.common

_OUTDIR="$_TOP/external/gpl3/gcc.old"
_OUTDIRBASE="external/gpl3/gcc.old"

sanitise_includes () {
	sed \
		-e "s,-I$_DESTDIR/usr/include,,g" \
		-e "s,-I$_SRC/external/lgpl3/mpfr/dist/src,,g" \
		-e "s,-I$_SRC/external/lgpl3/mpc/dist/src,,g" \
		-e "s,-I$_SRC/external/lgpl3/gmp/lib/libgmp/arch/[a-z_0-9-]*,,g" \
		-e "s,-I$_TOOLDIR/include,,g" \
		-e "s,-I/usr/include/[^ 	]*,,"
}

##### lib/libg2c #####

get_libg2c () {
	mkdir -p $_OUTDIR/lib/libg2c3/arch/$MACHINE_ARCH

	write_c $_OUTDIRBASE/lib/libg2c3/arch/$MACHINE_ARCH/config.h <$_TMPDIR/$_PLATFORM/libf2c/libU77/config.h
	write_c $_OUTDIRBASE/lib/libg2c3/arch/$MACHINE_ARCH/g2c.h <$_TMPDIR/$_PLATFORM/libf2c/g2c.h

	{
		getvars $_PLATFORM/libf2c/Makefile \
			F2CEXT
		getvars $_PLATFORM/libf2c/libF77/Makefile \
			ALL_CFLAGS OBJS
		getvars $_PLATFORM/libf2c/libI77/Makefile \
			ALL_CFLAGS OBJS | sed 's,=,+=,'
		getvars $_PLATFORM/libf2c/libU77/Makefile \
			ALL_CFLAGS OBJS | sed 's,=,+=,'
	} | write_mk $_OUTDIRBASE/lib/libg2c3/arch/$MACHINE_ARCH/defs.mk
}

##### lib/libgcc #####

get_libgcc () {
	_subdir="$1"
	mkdir -p $_OUTDIR/lib/lib$_subdir/arch

	# DPBIT, FPBIT only used on mn10[23]00, we don't need them.
	# XXX we should probably grab everything Just In Case for
	# the future.

	mkdir -p $_OUTDIR/lib/lib$_subdir/arch/$MACHINE_ARCH
	cd $_TMPDIR/$_PLATFORM/libgcc
	{
		getvars $_PLATFORM/libgcc/Makefile \
			INCLUDES \
			INTERNAL_CFLAGS \
			LIB2ADD LIB2ADDEH LIB2ADD_ST \
			LIB1ASMFUNCS LIB1ASMSRC \
			LIB2_DIVMOD_FUNCS LIB2FUNCS_ST \
			LIB2FUNCS_EXTRA \
			LIBGCC2_CFLAGS \
			SHLIB_MKMAP SHLIB_MKMAP_OPTS \
			SHLIB_MAPFILES SHLIB_NM_FLAGS
		getvars gcc/Makefile \
			NOEXCEPTION_FLAGS EXTRA_HEADERS
		getlinks config.status libgcc
	}	| sanitise_includes \
		| write_mk $_OUTDIRBASE/lib/lib$_subdir/arch/$MACHINE_ARCH/defs.mk

	if [ "${MACHINE_ARCH}" = "m68000" ]
	then
		ex <<__EOF__ $_OUTDIR/lib/lib$_subdir/arch/$MACHINE_ARCH/defs.mk
/G_LIBGCC2_CFLAGS/ s/-fPIC//
wq
__EOF__
	fi

	for f in auto-target.h; do
		write_c $_OUTDIRBASE/lib/lib$_subdir/arch/$MACHINE_ARCH/$f \
		    <$_TMPDIR/$_PLATFORM/libgcc/$f
	done
}

##### lib/libgcov #####

get_libgcov () {
	_subdir="$1"
	_mf="$2"

	mkdir -p $_OUTDIR/lib/lib$_subdir/libgcov/arch/$MACHINE_ARCH

	{
		getvars $_mf \
			LIBGCOV_MERGE \
			LIBGCOV_PROFILER \
			LIBGCOV_INTERFACE \
			LIBGCOV_DRIVER
	} | write_mk $_OUTDIRBASE/lib/lib$_subdir/libgcov/arch/$MACHINE_ARCH/defs.mk

	write_c $_OUTDIRBASE/lib/lib$_subdir/libgcov/arch/$MACHINE_ARCH/gcov-iov.h \
	   <$_TMPDIR/gcc/gcov-iov.h

}

##### lib/libiberty #####

get_gcc_libiberty () {
	_subdir="$1"
	_libibertydir="lib/libiberty"
	mkdir -p $_OUTDIR/$_libibertydir/arch/$MACHINE_ARCH

	getvars libiberty/Makefile \
		ALLOCA EXTRA_OFILES LIBOBJS REQUIRED_OFILES \
		| write_mk $_OUTDIRBASE/$_libibertydir/defs.mk

	write_c $_OUTDIRBASE/$_libibertydir/arch/$MACHINE_ARCH/config.h \
		<$_TMPDIR/libiberty/config.h
}

##### lib/libdecnumber #####

get_libdecnumber () {
	_subdir="$1"

	mkdir -p $_OUTDIR/usr.bin/$_subdir/arch/$MACHINE_ARCH
	write_c $_OUTDIRBASE/usr.bin/$_subdir/arch/$MACHINE_ARCH/config.h \
		<$_TMPDIR/libdecnumber/config.h
}

##### lib/libgomp #####

get_libgomp () {
	_subdir="$1"

	mkdir -p $_OUTDIR/lib/$_subdir/arch/$MACHINE_ARCH
	write_c $_OUTDIRBASE/lib/$_subdir/arch/$MACHINE_ARCH/config.h \
		<$_TMPDIR/$_PLATFORM/libgomp/config.h
	write_c $_OUTDIRBASE/lib/$_subdir/arch/$MACHINE_ARCH/libgomp_f.h \
		<$_TMPDIR/$_PLATFORM/libgomp/libgomp_f.h
	write_mk $_OUTDIRBASE/lib/$_subdir/arch/$MACHINE_ARCH/libgomp.spec \
		<$_TMPDIR/$_PLATFORM/libgomp/libgomp.spec
	write_c $_OUTDIRBASE/lib/$_subdir/arch/$MACHINE_ARCH/omp.h \
		<$_TMPDIR/$_PLATFORM/libgomp/omp.h
}

##### lib/libbacktrace #####

get_libbacktrace () {
	_subdir="$1"

	mkdir -p $_OUTDIR/lib/$_subdir/arch/$MACHINE_ARCH
	write_c $_OUTDIRBASE/lib/$_subdir/arch/$MACHINE_ARCH/config.h \
		<$_TMPDIR/$_subdir/config.h
	write_c $_OUTDIRBASE/lib/$_subdir/arch/$MACHINE_ARCH/backtrace-supported.h \
		<$_TMPDIR/$_subdir/backtrace-supported.h
}

##### lib/libobjc #####

get_libobjc () {
	_subdir="$1/arch/$MACHINE_ARCH"
	_options="ALL_OPT_FILES"

	mkdir -p $_OUTDIR/lib/$_subdir

	{
		if [ -n "$_options" ]; then
			getvars gcc/Makefile $_options
		fi
		getvars $_PLATFORM/libobjc/Makefile \
			ALL_CFLAGS INCLUDES OBJC_SOURCE_FILES C_SOURCE_FILES OBJC_H \
			| sed "s,$_GNU_DIST,\${GNUHOSTDIST},g"
		getlinks $_TMPDIR/$_PLATFORM/libgcc/config.status libgcc
	} | sanitise_includes \
	  | write_mk $_OUTDIRBASE/lib/$_subdir/defs.mk

	write_c $_OUTDIRBASE/lib/$_subdir/config.h \
		<$_TMPDIR/$_PLATFORM/libobjc/config.h
}

##### lib/libstdc++-v3 #####

get_libstdcxx_v3 () {
	_subdir="$1"
	_ver="$2"

	mkdir -p $_OUTDIR/lib/$_subdir/arch/$MACHINE_ARCH

	_build_headers="c++config.h cxxabi_tweaks.h gthr-posix.h gthr-single.h gthr.h"
	_headers1="c_base_headers_extra_install"
	_headers1="$_headers1 tr1_headers tr2_headers decimal_headers c_compatibility_headers_install"
	_headers1="$_headers1 debug_headers parallel_headers"
	_headers2="host_headers thread_host_headers"
	_pf_headers="profile_headers profile_impl_headers"
	_pb_headers="pb_headers1 pb_headers2 pb_headers3 pb_headers4 pb_headers5 pb_headers6 pb_headers7"

	# build files
	for h in $_build_headers; do
		write_c $_OUTDIRBASE/lib/$_subdir/arch/$MACHINE_ARCH/$h \
			<$_TMPDIR/$_PLATFORM/libstdc++-v3/include/$_PLATFORM/bits/$h
	done

	write_c $_OUTDIRBASE/lib/$_subdir/arch/$MACHINE_ARCH/gstdint.h \
		<$_TMPDIR/$_PLATFORM/libstdc++-v3/include/gstdint.h

	{
		getvars $_PLATFORM/libstdc++-v3/Makefile \
			port_specific_symbol_files

		# libsupc++
		getvars $_PLATFORM/libstdc++-v3/libsupc++/Makefile \
			sources | sed 's/^G_sources=/G_LIBSUPCXX_SOURCES=/'
		getvars $_PLATFORM/libstdc++-v3/libsupc++/Makefile \
			c_sources | sed 's/^G_c_sources=/G_LIBSUPCXX_C_SOURCES=/'

		# includes
		getvars $_PLATFORM/libstdc++-v3/include/Makefile \
			c_base_headers std_headers | sed -e 's#/[^ 	][^ 	]*/##g' -e 's/\${GNUHOSTDIST}//g'

		# src
		getvars $_PLATFORM/libstdc++-v3/src/Makefile \
			libstdc___la_SOURCES | sed 's/^G_libstdc___la_SOURCES=/G_SRC_SOURCES=/'
		getvars $_PLATFORM/libstdc++-v3/src/c++11/Makefile \
			libc__11convenience_la_SOURCES | \
			sed -e 's/^G_libc__11convenience_la_SOURCES=/G_CPP11_SOURCES=/' \
			    -e 's/codecvt.cc/c11-codecvt.cc/'
		getvars $_PLATFORM/libstdc++-v3/src/c++98/Makefile \
			GLIBCXX_ABI_FLAGS libc__98convenience_la_SOURCES | \
			sed -e 's/^G_libc__98convenience_la_SOURCES=/G_CPP98_SOURCES=/' \
			    -e 's/codecvt.cc/c98-codecvt.cc/'
		getvars $_PLATFORM/libstdc++-v3/Makefile ATOMICITY_SRCDIR \
			BASIC_FILE_CC CLOCALE_CC CCODECVT_CC CCOLLATE_CC \
			CCTYPE_CC  CMESSAGES_CC CMONEY_CC CNUMERIC_CC CTIME_CC \
			CPU_OPT_BITS_RANDOM

		# includes
		getvars $_PLATFORM/libstdc++-v3/include/Makefile \
			backward_headers c_base_headers_extra $_headers1 $_pb_headers | \
				sed -e 's#\${GNUHOSTDIST}/libstdc++-v3/include/##g'
		getvars $_PLATFORM/libstdc++-v3/include/Makefile \
			bits_headers ext_headers $_headers2 | \
				sed -e 's#\${GNUHOSTDIST}/libstdc++-v3/include/##g' -e 's#\${GNUHOSTDIST}/libstdc++-v3/config/##g'
		getvars $_PLATFORM/libstdc++-v3/include/Makefile \
			$_pf_headers | sed -e 's#\${GNUHOSTDIST}/libstdc++-v3/include/profile/##g'
		getvars $_PLATFORM/libstdc++-v3/include/Makefile \
			BASIC_FILE_H ALLOCATOR_H CSTDIO_H CLOCALE_H CMESSAGES_H CTIME_H
		getlinks $_TMPDIR/$_PLATFORM/libgcc/config.status libgcc
	} | sanitise_includes \
	  | write_mk $_OUTDIRBASE/lib/$_subdir/arch/$MACHINE_ARCH/defs.mk
}

##### usr.bin/gcc* #####

get_gcc_bootstrap () {
	_subdir="$1"
	mkdir -p $_OUTDIR/usr.bin/$_subdir/arch/$MACHINE_ARCH
	for f in auto-host tm config; do
		write_c $_OUTDIRBASE/usr.bin/$_subdir/arch/$MACHINE_ARCH/$f.h <$_TMPDIR/gcc/$f.h
	done
	# XXXGCC5 don't really want to copy insn-modes as we build
	# it but libgcc needs to too early yet
	for f in insn-modes; do
		write_c $_OUTDIRBASE/usr.bin/$_subdir/arch/$MACHINE_ARCH/$f.h <$_TMPDIR/gcc/$f.h
	done
}

get_gcc () {
	_subdir="$1"
	mkdir -p $_OUTDIR/usr.bin/$_subdir/arch/$MACHINE_ARCH
	mkdir -p $_OUTDIR/usr.bin/libcpp/arch/$MACHINE_ARCH
	mkdir -p $_OUTDIR/usr.bin/include/arch
	_buildname="BUILD_"
	_libcppsubdir=""
	_extravars="TM_H ALL_OPT_FILES"
	_hconfig_h=""
	_extravars2="tm_file_list build_xm_include_list"
	_extravars3="tm_p_include_list"

	{
		getvars gcc/Makefile \
			${_buildname}EARLY_SUPPORT ${_buildname}ERRORS ${_buildname}PRINT \
			${_buildname}RTL ${_buildname}SUPPORT ${_buildname}VARRAY \
			${_buildname}MD | \
		    sed -e 's#build/errors.o#build-errors.o#g' \
			-e 's#build/print-rtl.o#build-print-rtl.o#g' \
			-e 's#build/rtl.o#build-rtl.o#g' \
			-e 's#build/varray.o#build-varray.o#g' \
			-e 's#build/ggc-none.o#build-ggc-none.o#g' \
			-e 's#build/##g'
		getvars gcc/Makefile \
			ALL_CFLAGS ALL_CPPFLAGS C_AND_OBJC_OBJS C_OBJS CCCP_OBJS \
			GCC_OBJS GCOV_OBJS GCOV_DUMP_OBJS GXX_OBJS GTM_H PROTO_OBJS ${_extravars1} \
			INCLUDES md_file OBJC_OBJS OBJS out_file version \
			BUILD_PREFIX RTL_H RTL_BASE_H TREE_H ${_hconfig_h} BASIC_BLOCK_H GCC_H \
			GGC_H \
			GTFILES_SRCDIR GTFILES_FILES_FILES GTFILES_FILES_LANGS \
			GTFILES GTFILES_LANG_DIR_NAMES NOEXCEPTION_FLAGS \
			NATIVE_SYSTEM_HEADER_DIR \
			tm_defines host_xm_file host_xm_defines tm_p_file \
			target_cpu_default ${_extravars} ${_extravars2} \
			lang_specs_files ${_extravars3} \
			common_out_file \
				| sanitise_includes
		getvars gcc/Makefile \
			LIB2ADDEHDEP | sed 's/unwind.inc//'
		getvars gcc/Makefile \
			CXX_OBJS CXX_C_OBJS | sed 's/cp\///g'
		getvars gcc/Makefile \
			F77_OBJS | sed 's/f\///g'
		getvars libcpp/Makefile \
			libcpp_a_OBJS
		getvars gcc/Makefile \
			ENABLE_SHARED
		echo G_SHLIB_LINK="$CC -shared"
		echo G_SHLIB_MULTILIB=.
	} | write_mk $_OUTDIRBASE/usr.bin/$_subdir/arch/$MACHINE_ARCH/defs.mk

	getvars gcc/Makefile \
		EXTRA_HEADERS \
			| write_mk $_OUTDIRBASE/usr.bin/include/arch/$MACHINE_ARCH.mk

	write_c $_OUTDIRBASE/usr.bin/libcpp/arch/$MACHINE_ARCH/config.h <$_TMPDIR/libcpp/config.h
	hfiles='auto-host configargs config bconfig bversion plugin-version multilib tm'
	for f in $hfiles; do
		write_c $_OUTDIRBASE/usr.bin/$_subdir/arch/$MACHINE_ARCH/$f.h <$_TMPDIR/gcc/$f.h
		if [ "${MACHINE_ARCH}" = "powerpc" -a "${f}" = "configargs" ]
		then
			ex <<__EOF__ $_OUTDIR/usr.bin/$_subdir/arch/$MACHINE_ARCH/$f.h
/configuration_arguments/ s/$//
ya
i
#ifdef _SOFT_FLOAT
.
pu
s/";$/ -with-float=soft";/
a
#else
#endif
.
. m +1
/configure_default_options/ s/{ NULL.*$//
a
#ifdef _SOFT_FLOAT
  { "float", "soft" },
#endif
  { NULL, NULL }
};
.
wq
__EOF__
		fi
		if [ "${f}" = "configargs" ]
		then
			_srcquoted=$(echo "$_SRC" | sed 's/\//\\\//g')
			sed -i -E -e "s,$_srcquoted,/usr/src,g" \
				  -e 's/--build=[^ ]+ --host=([^ ]+)/--build=\1 --host=\1/' \
				$_OUTDIR/usr.bin/$_subdir/arch/$MACHINE_ARCH/$f.h
		fi
	done

	# keep identical
	for f in all-tree.def; do
		cp $_TMPDIR/gcc/$f $_OUTDIR/usr.bin/$_subdir/arch/$MACHINE_ARCH/$f
	done

	# special transforms
	for f in gtyp-input.list; do
		sed -e "s@^.*$_OUTDIRBASE/dist@SRCDIR@" < $_TMPDIR/gcc/$f > $_OUTDIR/usr.bin/$_subdir/arch/$MACHINE_ARCH/$f
	done

	# special platforms
	if [ "${MACHINE_ARCH}" = "sh3el" -o "${MACHINE_ARCH}" = "sh3eb" ]; then
		write_c $_OUTDIRBASE/usr.bin/$_subdir/arch/$MACHINE_ARCH/sysroot-suffix.h <$_TMPDIR/gcc/sysroot-suffix.h
	fi

	if [ "${MACHINE_ARCH}" = "i386" -o "${MACHINE_ARCH}" = "x86_64" ]; then
		write_c $_OUTDIRBASE/usr.bin/$_subdir/arch/$MACHINE_ARCH/i386-builtin-types.inc <$_TMPDIR/gcc/i386-builtin-types.inc
	fi
}

##### main #####

case "$1" in
# .mk and .h files for libgcc bootstrap (from host build)

libgcc*-bootstrap)
	get_libgcc gcc
	get_libgcov gcc $_PLATFORM/libgcc/Makefile
	get_gcc_bootstrap gcc
	exit 0
	;;

libstdc++-bootstrap)
	get_libstdcxx_v3 libstdc++-v3 gcc
	exit 0
	;;

gcc*)
	get_gcc gcc
	get_libgcc gcc
	get_libgcov gcc $_PLATFORM/libgcc/Makefile
	get_gcc_bootstrap gcc
	get_gcc_libiberty gcc
	get_libobjc libobjc
	get_libstdcxx_v3 libstdc++-v3 gcc
	get_libdecnumber libdecnumber
	get_libgomp libgomp
	get_libbacktrace libbacktrace
	exit 0
	;;


*)
	echo invalid arguments;
	exit 1
	;;
esac