File: rules

package info (click to toggle)
cross-binutils 0.23
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 52 kB
  • ctags: 17
  • sloc: makefile: 109; sh: 11
file content (152 lines) | stat: -rwxr-xr-x 5,131 bytes parent folder | download
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
#!/usr/bin/make -f


THIS_PKG         := $(shell dpkg-parsechangelog| sed -n 's/-*//; s/^Source: \(.*\)/\1/p')
THIS_PKG_VER     := $(shell dpkg-parsechangelog| sed -n 's/^Version: \(.*\)/\1/p')
THIS_PKG_MAINT   := $(shell dpkg-parsechangelog| sed -n 's/^Maintainer: \(.*\)/\1/p')

DEB_HOST_ARCH    := $(shell dpkg-architecture -qDEB_HOST_ARCH)
stamp            := stamp/



DEB_VER_BINUTILS := $(shell dpkg-parsechangelog -l/usr/src/binutils/debian/changelog | egrep '^Version:' | cut -f 2 -d ' ')
PKG_VER_BINUTILS := $(shell dpkg-parsechangelog -l/usr/src/binutils/debian/changelog | egrep '^Version:' | cut -f 2 -d ' '|cut -f 1 -d '-')
VER_BINUTILS     := $(shell dpkg-parsechangelog -l/usr/src/binutils/debian/changelog | egrep '^Version:' | cut -f 2 -d ' '|cut -f 1 -d '-'|cut -d '.' -f1-3)

BINUTILS_DIR  := /usr/src/binutils

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

# We know the HOST and TARGET arches for Debian and Ubuntu, but not others. 
ifeq ($(strip $(DISTRO)),)
  $(error cannot detect distro. Giving up. Set $DISTRO to 'Debian' or 'Ubuntu')
else ifeq ($(DISTRO),Debian)
  TARGET_LIST ?= armhf armel arm64 mips mipsel mips64el powerpc ppc64el i386 amd64
  HOST_LIST ?= amd64 i386 arm64
else ifeq ($(DISTRO),Ubuntu)
  TARGET_LIST ?= armhf armel arm64
  HOST_LIST ?= amd64 i386
else
  $(error unknown distro "$(DISTRO)". Nothing will be built.) 
endif

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


init: $(stamp)init

$(stamp)init:
	@echo START $@
	mkdir -p debian/tmp $(stamp)
	tar -x -f  ${BINUTILS_DIR}/binutils-${VER_BINUTILS}.tar.xz
	set -e; \
	cd binutils-${PKG_VER_BINUTILS} ;\
	cp -a ${BINUTILS_DIR}/debian/ . ;\
	if [ -n "$$(grep -v '^\#' debian/patches/binutils/series)" ]; then \
	  QUILT_PATCHES=debian/patches/binutils quilt push -a; \
	fi; \

	touch $@

$(stamp)build-%: $(stamp)init
	@echo START $@
	set -e; \
	cd binutils-${PKG_VER_BINUTILS}; \
	DEB_TARGET_ARCH=$* TARGET=$* dpkg-buildpackage -T control-stamp; \
	WITH_SYSROOT=/ DEB_TARGET_ARCH=$* TARGET=$* dpkg-buildpackage -B -uc -us; \
	cd ..; \
	touch $@


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


#
# Repack resulting packages to make changes:
# - Set Source and Version to this package 
define repack_deb
	echo "repacking $$deb ..."; \
	rm -rf tmp/*; \
	dpkg-deb -x $$deb tmp; \
	dpkg-deb -e $$deb tmp/DEBIAN; \
	pkgname=`echo $$deb | cut -d'_' -f1`; \
        sed -i -e's/^Source:.*/Source: ${THIS_PKG} (${THIS_PKG_VER})/' tmp/DEBIAN/control; \
        sed -i -e's/^Maintainer:.*/Maintainer: ${THIS_PKG_MAINT}\nOriginal-Source-&/' 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 ;\
	 chmod 644 DEBIAN/md5sums ; \
        );\
	find tmp/usr -type d -execdir chmod 755 '{}' \; ;\
	dpkg-deb -b tmp/ ../$$deb; \
	echo "        done";
endef

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

BUILD_TARGETS := $(patsubst %,$(stamp)build-%,${TARGETS})

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

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


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

mangle-debian-files: $(stamp)debian-files repack-debs
	@echo START $@
	@for deb in $(wildcard *.deb); \
	do \
		echo -n "`basename $$deb` " >>debian/files; \
		dpkg-deb -I $$deb | grep Section  | cut -d ' ' -f 3 | tr "\n" ' ' >>debian/files; \
		dpkg-deb -I $$deb | grep Priority | cut -d ' ' -f 3 | tr -d "\n" >>debian/files; \
		echo "" >>debian/files; \
	done


# Generate the control file from head plus stanza for each binary
# Don't build binaries when HOST=TARGET
# Ensure no underscores appear in package names (x86_64-linux-gnu we're looking at you)

control:
	cat debian/control.head.in > debian/control;
	for DEB_TARGET_ARCH in $(TARGET_LIST); do \
	    DEB_TARGET_GNU_TYPE=`dpkg-architecture -a$${DEB_TARGET_ARCH} -qDEB_HOST_GNU_TYPE -f 2>/dev/null`; \
	    TARGET_PACKAGENAME=`echo $${DEB_TARGET_GNU_TYPE} | tr _ -` ; \
	    ARCH_LIST_FOR_BINARY=`echo ${HOST_LIST} | sed "s/ *$${DEB_TARGET_ARCH} */ /"`; \
	    sed -e "s/DEB_TARGET_ARCH/$${DEB_TARGET_ARCH}/g" debian/control.binary.in | \
	    sed -e "s/ARCH_LIST_FOR_BINARY/$${ARCH_LIST_FOR_BINARY}/g" | \
	    sed -e "s/DEB_TARGET_GNU_TYPE/$${TARGET_PACKAGENAME}/g" >> debian/control; \
	done


# Manual convenience rule to update changelog to match current binutils version
# Works outside build-environment  
update-changelog-external:
	pkgver=$$( rmadison -a source -s sid binutils |  tail -n 1 | awk '{ print $$1 "_" $$3 }' );\
	dch -i --no-auto-nmu -D unstable "Rebuild using $$pkgver"

update-changelog:
	dch -i --no-auto-nmu -D unstable "Rebuild using binutils ${DEB_VER_BINUTILS}"