This file is indexed.

/usr/share/cross-gcc/template/rules.generic is in cross-gcc-dev 176.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  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
#!/usr/bin/make -f

SHELL := /bin/bash

THIS_PKG       := $(shell dpkg-parsechangelog --show-field=Source)
THIS_PKG_VER   := $(shell dpkg-parsechangelog --show-field=Version)
DEB_HOST_ARCH  := $(shell dpkg-architecture -qDEB_HOST_ARCH)

THIS_PKG_MAINT     = $(shell <debian/control.template awk '/Maintainer:/{$$1=""; sub("^ ",""); print; exit}')
THIS_PKG_UPLOADERS = $(shell <debian/control.template awk '/Uploaders:/ {$$1=""; sub("^ ",""); print; exit}')
stamp             := stamps/

DISTRO ?= $(shell dpkg-vendor --query vendor)


# The base gcc version comes from the environment, or if that's not set, from
# the control file, if it exists. Otherwise we default to "4.9"

ifneq (,$(BASE_VER_GCC))
  # BASE_VER_GCC defined. all good
else ifneq (,$(wildcard debian/control))
  # we have a debian/control. Parse the gcc version from it
  BASE_VER_GCC := $(or \
    $(shell <debian/control \
               sed 's/[, ]/\n/g' | \
                awk '/gcc-[0-9\.\-]*-source/ {gsub(".*gcc-",""); gsub("-source",""); print; exit}'), \
    $(error "Couldn't parse BASE_VER_GCC from debian/control"))
else
  # no debian/control or env variable. Hardcode something
  BASE_VER_GCC := 4.9
endif


# defaults
ifeq ($(DISTRO),Debian)
HOST_LIST ?= amd64 i386
else # Ubuntu
HOST_LIST ?= amd64
endif

#frontends to disable (default)
NOLANG := d,go,java,objc,obj-c++,ada

#Use DEB_CROSS_MULTILIB=yes to control whether we build multilib crosstoolchains or not
#Default:
DEB_CROSS_MULTILIB ?= yes
ifeq ($(DEB_CROSS_MULTILIB),yes)
  NOLANG := $(NOLANG)
  DEB_CROSS_NO_BIARCH :=
else
  # disable biarch/triarch builds and just build for the main target abi
  NOLANG := biarch,$(NOLANG)
endif

# disable verbose ICE backtraces by default (unstripped_exe=no)
# set unstripped_exe=yes to have unstripped binaries that can do ICE backtraces (with gcc-5)
stripopt ?= unstripped_exe=no

# To build a second (set of) cross-gcc-<ver>-<arch> upload(s) for the same major
# gcc release (4.9, 5, etc), increment the SUFFIX env var thus:
#
#   SUFFIX=.1 cross-gcc-gensources
#
# This will add .1 to the version number of the binary packages so they don't
# clash with the previous upload(s). If unset we assume this is the first upload
# for a given gcc release, so no SUFFIX is used
SUFFIX ?= 

GCC_SOURCES_DEBIAN_CHANGELOG := /usr/src/gcc-$(BASE_VER_GCC)/debian/changelog

# Debian package version (with '-')
#
# If we have gcc-xxx-source installed, we read the version. Otherwise we set an
# error such that if anything tries to use this version, make will barf. This is
# OK if we're just generating the debian/control file
ifneq (,$(wildcard $(GCC_SOURCES_DEBIAN_CHANGELOG)))
  DEB_VER_GCC := $(shell dpkg-parsechangelog -l/usr/src/gcc-$(BASE_VER_GCC)/debian/changelog --show-field=Version)
  FINAL_VER_GCC := $(DEB_VER_GCC)$(SUFFIX)
else
  DEB_VER_GCC = $(error Tried to access $(GCC_SOURCES_DEBIAN_CHANGELOG) but it does not exist)
endif


# Package base version (directory name)
PKG_VER_GCC = $(firstword $(subst -, ,$(DEB_VER_GCC)))
# 


# 3-digit upstream gcc version (tarball name)
space :=
space +=
VER_GCC=$(subst $(space),.,$(wordlist 1,3,$(subst ., ,$(PKG_VER_GCC))))

GCC_DIR  := /usr/src/gcc-$(BASE_VER_GCC)



# Don't try to build the HOST=TARGET (ie. non-cross) combination on/for this arch
TARGETS := $(filter-out ${DEB_HOST_ARCH}, ${DEB_TARGET_ARCH})


info:
	@echo "Gcc version:         ${VER_GCC}	${DEB_VER_GCC}	${PKG_VER_GCC}	${FINAL_VER_GCC}"
	@echo "Target architecture:      ${DEB_TARGET_ARCH}"
	@echo "Host architecture:        ${DEB_HOST_ARCH}"

$(stamp): 
	mkdir $(stamp) -p

debian/tmp:
	mkdir debian/tmp -p

$(stamp)init-dirs: $(stamp) debian/tmp
	touch $@

init: $(stamp)init-dirs $(stamp)init

PATCHDIR:=/usr/share/cross-gcc/patches/gcc-$(BASE_VER_GCC)
$(stamp)init:
	@echo START $@
	tar -x -f ${GCC_DIR}/gcc-*.tar.[gx]z
	set -e; \
	if [ gcc-* != gcc-${PKG_VER_GCC} ]; then \
	   mv gcc-* gcc-${PKG_VER_GCC} ; \
	else \
	  true; \
	fi; \
	cd gcc-${PKG_VER_GCC} ;\
	cp -a ${GCC_DIR}/debian/ . ;\
	if [ -n "$$(grep -v '^\#' $(PATCHDIR)/series)" ]; then \
	  QUILT_PATCHES=$(PATCHDIR) quilt --quiltrc /dev/null push -a; \
	fi; \

	touch $@

# There are 3 ways to specify a target arch to the build:
#
# DEB_TARGET_ARCH env var
# dpkg-buildpackage --target-arch
# debian/target file
#
# Those have all been broken at various points in time, so I can't simply pick
# one method. Instead I use one of two methods: (if available, --target-arch
# else DEB_TARGET_ARCH). Hopefully this always works
#
# dpkg-buildpackage target-arch setting changed from env var to option from
# dpkg 1.17.17, so pass --target-arch if available.
DPKG_HAS_TARGETARCH = $(shell (cd /; dpkg-buildpackage --target-arch 2> /dev/null; if [ $$? -eq 2 ] ; then echo 'no'; fi))
ifeq ($(DPKG_HAS_TARGETARCH),no)
dpkg_target_cmd = DEB_TARGET_ARCH=$* with_deps_on_target_arch_pkgs=yes DEB_BUILD_OPTIONS="nolang=$(NOLANG)" $(stripopt) dpkg-buildpackage
else # must use --target-arch
dpkg_target_cmd = with_deps_on_target_arch_pkgs=yes DEB_BUILD_OPTIONS="nolang=$(NOLANG)" $(stripopt) dpkg-buildpackage --target-arch $*
endif

$(stamp)build-%: $(stamp)init
	@echo START $@
	set -e; \
	cd gcc-${PKG_VER_GCC}; \
	$(dpkg_target_cmd) -d -T control; \
	$(dpkg_target_cmd) -B -d -uc -us; \
	cd ..; \
	touch $@


clean:
	rm -rf gcc-*
	rm -rf debian/tmp debian/files
	find debian -name '*~' | xargs -r rm -f
	rm -f *.deb *.changes
	rm -rf repackfiles tmp
	rm -rf $(stamp)
	mkdir $(stamp)


BUILD_TARGET := $(patsubst %,$(stamp)build-%,${DEB_TARGET_ARCH})

build-arch: build
build-indep: 
build: $(BUILD_TARGET)
	rm -f *.changes

binary: binary-arch binary-indep 
binary-arch:  build-arch mangle-debian-files
binary-indep:

# Get the list of binaries we care about. Make sure this is = instead of := so
# that we don't look at the control file unless we need to (it may not exist)
PACKAGES = $(patsubst  %,%_*.deb, $(shell awk  '/^Package: / { print $$2 }' debian/control))

# Repack resulting packages to make changes:
# - Set Source and Version to this package 
# - Change Maintainer for cross packages
# - Change Uploaders for cross packages, taking care to not barf is not previous Uploaders exist
# - Get rid of unecessary gcc-<ver>-base dep - all docs are in cpp-<triplet> package
define repack_deb	
	echo "repacking $$deb ...";										 \
	rm -rf tmp/*;												 \
	pkgname=`echo $$deb | cut -d'_' -f1`;									 \
	version=`echo $$deb | cut -d'_' -f2`;									 \
	archdeb=`echo $$deb | cut -d'_' -f3`;									 \
	dpkg-deb -R $$deb tmp;											 \
	sed -i -e's/^Source:.*$$/Source: $(THIS_PKG) ($(THIS_PKG_VER))/' tmp/DEBIAN/control;			 \
	sed -i -e's/^Version:.*$$/Version: $(FINAL_VER_GCC)/' tmp/DEBIAN/control;				 \
	sed -i -e"s/^Maintainer:.*$$/Maintainer: $(THIS_PKG_MAINT)\nXB-Original-Source-&/"     tmp/DEBIAN/control; \
	if grep -q '^Uploaders:' tmp/DEBIAN/control; then							 \
	  sed -i -e"s/^Uploaders:.*$$/Uploaders: $(THIS_PKG_UPLOADERS)\nXB-Original-Source-&/" tmp/DEBIAN/control; \
	else													 \
	  sed -i -e"s/^XB-Original-Source-Maintainer.*$$/&\nUploaders: $(THIS_PKG_UPLOADERS)/" tmp/DEBIAN/control; \
	fi;													 \
														 \
	sed -r -i -e's/gcc-$(BASE_VER_GCC)(-[a-z0-9-]+)?-base[^,]*,//' tmp/DEBIAN/control;			 \
	if [ -e debian/overrides/$$pkgname ]; then								 \
	  mkdir -p tmp/usr/share/lintian/overrides;								 \
	  cp debian/overrides/$$pkgname tmp/usr/share/lintian/overrides/;					 \
	fi;													 \
	(cd tmp && md5sum `find usr -type f` >>DEBIAN/md5sums);							 \
	dpkg-deb -b tmp/ ../$${pkgname}_$(FINAL_VER_GCC)_$${archdeb};						 \
	echo "        done";
endef


repack-debs:
	@echo START $@
	install -d repackfiles; \
	for deb in $(wildcard ${PACKAGES}); \
	do \
	  $(call repack_deb, $${deb}) \
	done; \


$(stamp)debian-files-base:
	@echo START $@
	rm -f debian/files
	touch $@

define generate_debian_files
	@echo Debs: $1
	@for deb in $1; \
	do \
		echo -n "`basename $$deb` " >>debian/files; \
		dpkg-deb -f $$deb Section  | tr "\n" ' ' >>debian/files; \
		dpkg-deb -f $$deb Priority | tr -d "\n"  >>debian/files; \
		echo "" >>debian/files; \
	done
	sed -i -e 's/_$(DEB_VER_GCC)_/_$(FINAL_VER_GCC)_/' debian/files
endef

mangle-debian-files: $(stamp)debian-files-base repack-debs
	@echo START $@
	$(call generate_debian_files,  $(wildcard ${PACKAGES}))


# Generate the control file from head plus stanza for each binary
# Set the TARGET arch when doing it:
# e.g: DEB_TARGET_ARCH=armhf debian/rules control
# HOST=TARGET doesn't make sense.

#arrays used, so posix not good enough
SHELL=/bin/bash
GCC_DEBIAN_RELEASE=$(shell \
  source $(or $(LOCALPATH),/usr/share/cross-gcc)/cross-gcc-dev-helpers.sh; \
  get_debian_release ${BASE_VER_GCC})

#set multilib dependencies
mips_BASE_DEPS:= mips64 mipsn32
mipsel_BASE_DEPS:= mips64 mipsn32
powerpc_BASE_DEPS:= ppc64
amd64_BASE_DEPS:= i386 x32
i386_BASE_DEPS:= amd64 x32


#expand each item in DEPS into libc6-$abi-dev:${DEB_TARGET_ARCH}
MULTILIB_DEPS = $(foreach abi,$($(DEB_TARGET_ARCH)_BASE_DEPS), libc6-dev-$(abi):${DEB_TARGET_ARCH})

LIBC_DEPS_TMP=libc6-dev:${DEB_TARGET_ARCH}
ifeq ($(DEB_CROSS_MULTILIB),yes)
  ifneq ($($(DEB_TARGET_ARCH)_BASE_DEPS),"")
    LIBC_DEPS_TMP += $(MULTILIB_DEPS)
  endif
endif
comma = ,
LIBC_DEPS = $(subst $(space),$(comma)$(space),$(strip $(LIBC_DEPS_TMP)))

control: debian/control.template
	DEB_TARGET_ARCH=${DEB_TARGET_ARCH} ; \
	DEB_TARGET_GNU_TYPE=`dpkg-architecture -a$${DEB_TARGET_ARCH} -qDEB_HOST_GNU_TYPE -f 2>/dev/null | tr _ -`; \
	ARCH_LIST_FOR_BINARY=`echo ${HOST_LIST}`; \
	< debian/control.template \
	sed -e "s/LIBC_DEPS/${LIBC_DEPS}/g" | \
	sed -e "s/DEB_TARGET_ARCH/$${DEB_TARGET_ARCH}/g" | \
	sed -e "s/GCC_DEBIAN_RELEASE/${GCC_DEBIAN_RELEASE}/g" | \
	sed -e "s/BASE_VER_GCC/${BASE_VER_GCC}/g" | \
	sed -e "s/ARCH_LIST_FOR_BINARY/$${ARCH_LIST_FOR_BINARY}/g" | \
	sed -e "s/DEB_TARGET_GNU_TYPE/$${DEB_TARGET_GNU_TYPE}/g" > debian/control;