[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Modifications to makefiles of binutils and gcc-4.4 to compile for alternate prefix directories

The following are patch files that I apply to the binutils and gcc-4.4 in order to get them to build for use at an alternate prefix. I post these for general interest and discussion. I use these modifications to create tools that can be installed under /opt/.. instead of /usr/.. in support of a generic cross building environment that is stand alone and not specifically tied to a Debian environment.

In order to build the tools with an alternate build prefix, I need to make some manual changes to the makefiles of the binutils and gcc packages prior to compilation. These changes turn out in fact to be fairly trivial and generic, simply some replacement of hardcoded '/usr' paths with a prefix variable that defaults to '/usr' if it is not already defined (e.g. by passing on the command line). In fact, the gcc package had nearly everything I needed already in place, and already mostly supported the alternate prefix.

In general to build these toolchains, I follow the method described here http://wiki.debian.org/EmdebianToolchain under the heading 'Build your own from sources'. Once I have made the following modifications to the three makefiles listed, I can change the prefix directory of the resulting tools by specifying the PF environment variable on the command line as follows by example:

For binutils
jheck@squeeze2:~/opt-build/binutils-2.20.1$ PF=/opt/crosscompiler/gcc-4.4.4/arm TARGET=armel fakeroot debian/rules binary-cross

For gcc-4.4
jheck@squeeze2:~/opt-build/gcc-4.4-4.4.4$ PF=/opt/crosscompiler/gcc-4.4.4/arm GCC_TARGET=armel DEB_CROSS=yes fakeroot debian/rules control jheck@squeeze2:~/opt-build/gcc-4.4-4.4.4$ PF=/opt/crosscompiler/gcc-4.4.4/arm DEB_CROSS_NO_BIARCH=yes GCC_TARGET=armel DEB_CROSS=yes dpkg-buildpackage -us -uc -rfakeroot

Here are the diff files as they apply to the specific source package versions listed.

For binutils_2.20.1-11, the following patch applies to the debian/rules makefile

jheck@squeeze2:~/opt-build$ diff binutils-2.20.1/debian/rules.orig binutils-2.20.1/debian/rules
> # PF is the installation prefix for the package without the leading slash.
> # It's "usr" for gcc releases, so use this if not explicitly set
> ifeq ($(PF),)
>   PF = usr
> endif
<     --prefix=/usr \
>     --prefix=/$(PF) \
< --build=$(DEB_BUILD_GNU_TYPE) --target=$(TARGET) --prefix=/usr \
> --build=$(DEB_BUILD_GNU_TYPE) --target=$(TARGET) --prefix=/$(PF) \
<     $(MAKE) -C builddir-$(TARGET) prefix=$(pwd)/$(d_cross)/usr \
<         mandir=$(pwd)/$(d_cross)/usr/share/man \
<         infodir=$(pwd)/$(d_cross)/usr/share/info install
< rm -rf $(d_cross)/usr/lib* $(d_cross)/usr/share/info $(d_cross)/usr/share/locale
>     $(MAKE) -C builddir-$(TARGET) prefix=$(pwd)/$(d_cross)/$(PF) \
>         mandir=$(pwd)/$(d_cross)/$(PF)/share/man \
>         infodir=$(pwd)/$(d_cross)/$(PF)/share/info install
> rm -rf $(d_cross)/usr/lib* $(d_cross)/$(PF)/share/info $(d_cross)/$(PF)/share/locale
< $(STRIP) $$(file $(d_cross)/usr/bin/* | awk -F: '$$0 !~ /script/ {print $$1}')
> $(STRIP) $$(file $(d_cross)/$(PF)/bin/* | awk -F: '$$0 !~ /script/ {print $$1}')
<     gzip -9 $(d_cross)/usr/share/man/man1/*
>     gzip -9 $(d_cross)/$(PF)/share/man/man1/*
<     $(install_dir) $(d_cross)/usr/share/doc/$(p_cross)/
< $(install_file) debian/changelog $(d_cross)/usr/share/doc/$(p_cross)/changelog.Debian < $(install_file) debian/copyright debian/README.cross $(d_cross)/usr/share/doc/$(p_cross)/
<     gzip -9f $(d_cross)/usr/share/doc/$(p_cross)/changelog.Debian
>     $(install_dir) $(d_cross)/$(PF)/share/doc/$(p_cross)/
> $(install_file) debian/changelog $(d_cross)/$(PF)/share/doc/$(p_cross)/changelog.Debian > $(install_file) debian/copyright debian/README.cross $(d_cross)/$(PF)/share/doc/$(p_cross)/
>     gzip -9f $(d_cross)/$(PF)/share/doc/$(p_cross)/changelog.Debian
< ln -sf ../binutils/$$pkg $(d_cross)/usr/share/doc/$(p_cross)/$$pkg; \
> ln -sf ../binutils/$$pkg $(d_cross)/$(PF)/share/doc/$(p_cross)/$$pkg; \
<     dpkg-shlibdeps $(d_cross)/usr/bin/*
>     dpkg-shlibdeps $(d_cross)/$(PF)/bin/*

For gcc-4.4_4.4.4-5 the following patch applies to the debian/rules2 makefile

jheck@squeeze2:~/opt-build$ diff gcc-4.4-4.4.4/debian/rules2.orig gcc-4.4-4.4.4/debian/rules2
< # It's "usr" for gcc releases
< ifeq ($(PKGSOURCE),gcc-snapshot)
> # It's "usr" for gcc releases, so use this if not explicitly set
> ifneq ($(PF),)
> else ifeq ($(PKGSOURCE),gcc-snapshot)

For gcc-4.4_4.4.4-5 the following patch applies to the debian/rules.d/binary-libstdcxx-cross.mk makefile

jheck@squeeze2:~/opt-build$ diff gcc-4.4-4.4.4/debian/rules.d/binary-libstdcxx-cross.mk.orig gcc-4.4-4.4.4/debian/rules.d/binary-libstdcxx-cross.mk
<     mkdir -p $(d_lib)/usr/$(DEB_TARGET_GNU_TYPE)/lib/debug
< mv $(d_lib)/usr/lib/debug/usr/$(DEB_TARGET_GNU_TYPE)/lib/* $(d_lib)/usr/$(DEB_TARGET_GNU_TYPE)/lib/debug/
>     mkdir -p $(d_lib)/$(PF)/$(DEB_TARGET_GNU_TYPE)/lib/debug
> mv $(d_lib)/usr/lib/debug/$(PF)/$(DEB_TARGET_GNU_TYPE)/lib/* $(d_lib)/$(PF)/$(DEB_TARGET_GNU_TYPE)/lib/debug/
< tar -C $(d_lib) -c -f - usr/$(DEB_TARGET_GNU_TYPE)/lib/debug | tar -v -C $(d_dbg) -x -f -
<     rm -rf $(d_lib)/usr/$(DEB_TARGET_GNU_TYPE)/lib/debug
> tar -C $(d_lib) -c -f - $(PF)/$(DEB_TARGET_GNU_TYPE)/lib/debug | tar -v -C $(d_dbg) -x -f -
>     rm -rf $(d_lib)/$(PF)/$(DEB_TARGET_GNU_TYPE)/lib/debug
< ln -s "`readlink -e /usr/$(DEB_TARGET_GNU_TYPE)/lib`" debian/$(p_lib)-deps/lib
> ln -s "`readlink -e /$(PF)/$(DEB_TARGET_GNU_TYPE)/lib`" debian/$(p_lib)-deps/lib
<     mkdir -p $(d_lib64)/usr/$(DEB_TARGET_GNU_TYPE)/lib64/debug
< mv $(d_lib64)/usr/lib/debug/usr/$(DEB_TARGET_GNU_TYPE)/lib64/* $(d_lib64)/usr/$(DEB_TARGET_GNU_TYPE)/lib64/debug/
>     mkdir -p $(d_lib64)/$(PF)/$(DEB_TARGET_GNU_TYPE)/lib64/debug
> mv $(d_lib64)/usr/lib/debug/$(PF)/$(DEB_TARGET_GNU_TYPE)/lib64/* $(d_lib64)/$(PF)/$(DEB_TARGET_GNU_TYPE)/lib64/debug/
< tar -C $(d_lib64) -c -f - usr/$(DEB_TARGET_GNU_TYPE)/lib64/debug | tar -v -C $(d_dbg64) -x -f -
<     rm -rf $(d_lib64)/usr/$(DEB_TARGET_GNU_TYPE)/lib64/debug
> tar -C $(d_lib64) -c -f - $(PF)/$(DEB_TARGET_GNU_TYPE)/lib64/debug | tar -v -C $(d_dbg64) -x -f -
>     rm -rf $(d_lib64)/$(PF)/$(DEB_TARGET_GNU_TYPE)/lib64/debug
< ln -s "`readlink -e /usr/$(DEB_TARGET_GNU_TYPE)/lib64`" debian/$(p_lib64)-deps/lib
> ln -s "`readlink -e /$(PF)/$(DEB_TARGET_GNU_TYPE)/lib64`" debian/$(p_lib64)-deps/lib
<     mkdir -p $(d_lib32)/usr/$(DEB_TARGET_GNU_TYPE)/lib32/debug
< mv $(d_lib32)/usr/lib/debug/usr/$(DEB_TARGET_GNU_TYPE)/lib32/* $(d_lib32)/usr/$(DEB_TARGET_GNU_TYPE)/lib32/debug/
>     mkdir -p $(d_lib32)/$(PF)/$(DEB_TARGET_GNU_TYPE)/lib32/debug
> mv $(d_lib32)/usr/lib/debug/$(PF)/$(DEB_TARGET_GNU_TYPE)/lib32/* $(d_lib32)/$(PF)/$(DEB_TARGET_GNU_TYPE)/lib32/debug/
< tar -C $(d_lib32) -c -f - usr/$(DEB_TARGET_GNU_TYPE)/lib32/debug | tar -v -C $(d_dbg32) -x -f -
<     rm -rf $(d_lib32)/usr/$(DEB_TARGET_GNU_TYPE)/lib32/debug
> tar -C $(d_lib32) -c -f - $(PF)/$(DEB_TARGET_GNU_TYPE)/lib32/debug | tar -v -C $(d_dbg32) -x -f -
>     rm -rf $(d_lib32)/$(PF)/$(DEB_TARGET_GNU_TYPE)/lib32/debug
< ln -s "`readlink -e /usr/$(DEB_TARGET_GNU_TYPE)/lib32`" debian/$(p_lib32)-deps/lib
> ln -s "`readlink -e /$(PF)/$(DEB_TARGET_GNU_TYPE)/lib32`" debian/$(p_lib32)-deps/lib


Reply to: