### Setup

tar_archive1 = archives/gcc-core-4.1.1.tar.bz2
tar_archive2 = archives/gcc-g++-4.1.1.tar.bz2
src_dir      = gcc-4.1.1
static_dir   = build.static
full_dir     = build.full


### Rules

all:
	@echo "No default rule, use static or full"

clean:
	rm -rf $(src_dir) $(static_dir) $(full_dir)

$(src_dir): $(tar_archive1) $(tar_archive2)
	tar xjf $(tar_archive1)
	tar xjf $(tar_archive2)
#	Fix for error in ld version check.
	patch -d $@ -p0 < ld_version.patch
#	Selected ST patches from stlinux23ear-cross-gcc-4.1.1-27.src.rpm.
#	In gcc-4.1.1-st40r2-4.0.2.patch, the testsuite patches does not apply
#	but do not fail because of that.
	patch -d $@ -p1 < gcc-4.1.1-recursive_inline_fix.patch
	-patch -d $@ -f -p1 < gcc-4.1.1-st40r2-4.0.2.patch
#	Strip $GCC_BASEDIR from filename before expanding __FILE__.
	patch -d $@ -p1 < cpp-strip-basedir-from-file-macro.patch
	@touch $@

$(static_dir): $(src_dir)
	mkdir $@
	cd $@ && ../$</configure \
	  --prefix=$(DIST_DIR) \
	  --target=$(ARCH_CROSS) \
	  --disable-nls \
	  --disable-shared \
	  --disable-threads \
	  --enable-languages=c \
	  --enable-target-optspace \
	  --with-sysroot=$(SYSROOT_DIR)
	$(MAKE) -C $@ all-gcc install-gcc

static: $(static_dir)

$(full_dir): $(src_dir)
	mkdir $@
	cd $@ && ../$</configure \
	  --prefix=$(DIST_DIR) \
	  --target=$(ARCH_CROSS) \
	  --disable-nls \
	  --enable-__cxa_atexit \
	  --enable-languages=c,c++ \
	  --enable-target-optspace \
	  --with-multilib-list=m4,m4-nofpu \
	  --with-sysroot=$(SYSROOT_DIR)
	$(MAKE) -C $@ all install

full: $(full_dir)

.PHONY: all clean static full
