Description: Fix buildsystem
 - Correct Makefile abuse.
 - Make cross-compilable.
Author: Thorsten Glaser <tg@mirbsd.de>
Origin: https://www.mirbsd.org/cvs.cgi/ports/lang/pcc/patches/
Forwarded: http://thread.gmane.org/gmane.comp.compilers.pcc/2091
Last-Update: $MirOS: contrib/hosted/tg/deb/pcc/debian/patches/001-fix-buildsystem,v 1.1 2011/04/22 19:15:01 tg Exp $

--- pcc-1.1.0~DEVEL+20110422.orig/Makefile.in
+++ pcc-1.1.0~DEVEL+20110422/Makefile.in
@@ -12,23 +12,25 @@ CPPFLAGS=@CPPFLAGS@
 YACC=@YACC@
 LEX=@LEX@
 
-SUBDIR=cc
+ALL_SUBDIRS=	cc
+DIST_SUBDIRS=	$(ALL_SUBDIRS) f77
 
-all: ${SUBDIR}
-
-install:
-	cd cc && ${MAKE} install
-
-clean:
-	cd cc && ${MAKE} clean
+all install clean:
+	@for subdir in $(ALL_SUBDIRS); do \
+		_nextdir_=$${_thisdir_+$$_thisdir_/}$$subdir; \
+		echo "===> $$_nextdir_"; \
+		(_thisdir_=$$_nextdir_; export _thisdir_; cd $$subdir && \
+		    exec $(MAKE) $(MFLAGS) $@) || exit $$?; \
+		echo "<=== $$_nextdir_"; \
+	done
 
 distclean:
-	cd cc && ${MAKE} distclean
-	cd f77 && ${MAKE} distclean
+	@for subdir in $(DIST_SUBDIRS); do \
+		_nextdir_=$${_thisdir_+$$_thisdir_/}$$subdir; \
+		echo "===> $$_nextdir_"; \
+		(_thisdir_=$$_nextdir_; export _thisdir_; cd $$subdir && \
+		    exec $(MAKE) $(MFLAGS) $@) || exit $$?; \
+		echo "<=== $$_nextdir_"; \
+	done
 	/bin/rm -rf Makefile config.log stamp-h1 config.status \
-	configure.lineno config.h autom4te.cache
-
-${SUBDIR}: nonexistant
-	cd $@ && $(MAKE) all $(MFLAGS)
-
-nonexistant:
+	    configure.lineno config.h autom4te.cache
--- pcc-1.1.0~DEVEL+20110422.orig/configure.ac
+++ pcc-1.1.0~DEVEL+20110422/configure.ac
@@ -377,7 +377,11 @@ else
         AC_MSG_RESULT([not cross compiling])
         CC_FOR_BUILD=${CC-cc}
         AC_SUBST(CC_FOR_BUILD)
+	test -n "$CPPFLAGS_FOR_BUILD" || CPPFLAGS_FOR_BUILD=$CPPFLAGS
+	test -n "$CFLAGS_FOR_BUILD" || CFLAGS_FOR_BUILD=$CFLAGS
 fi
+AC_SUBST(CPPFLAGS_FOR_BUILD)
+AC_SUBST(CFLAGS_FOR_BUILD)
 
 AC_CACHE_CHECK([for C99 printf size specifiers], ac_have_c99_format, [
   AC_RUN_IFELSE([
--- pcc-1.1.0~DEVEL+20110422.orig/cc/Makefile.in
+++ pcc-1.1.0~DEVEL+20110422/cc/Makefile.in
@@ -12,28 +12,25 @@ CPPFLAGS=@CPPFLAGS@
 YACC=@YACC@
 LEX=@LEX@
 
-SUBDIR=cc cpp ccom
+ALL_SUBDIRS=	cc cpp ccom
+DIST_SUBDIRS=	$(ALL_SUBDIRS)
 
-all: ${SUBDIR}
-
-install:
-	cd cc && ${MAKE} install
-	cd cpp && ${MAKE} install
-	cd ccom && ${MAKE} install
-
-clean:
-	cd cc && ${MAKE} clean
-	cd cpp && ${MAKE} clean
-	cd ccom && ${MAKE} clean
+all install clean:
+	@for subdir in $(ALL_SUBDIRS); do \
+		_nextdir_=$${_thisdir_+$$_thisdir_/}$$subdir; \
+		echo "===> $$_nextdir_"; \
+		(_thisdir_=$$_nextdir_; export _thisdir_; cd $$subdir && \
+		    exec $(MAKE) $(MFLAGS) $@) || exit $$?; \
+		echo "<=== $$_nextdir_"; \
+	done
 
 distclean:
-	cd cc && ${MAKE} distclean
-	cd cpp && ${MAKE} distclean
-	cd ccom && ${MAKE} distclean
+	@for subdir in $(DIST_SUBDIRS); do \
+		_nextdir_=$${_thisdir_+$$_thisdir_/}$$subdir; \
+		echo "===> $$_nextdir_"; \
+		(_thisdir_=$$_nextdir_; export _thisdir_; cd $$subdir && \
+		    exec $(MAKE) $(MFLAGS) $@) || exit $$?; \
+		echo "<=== $$_nextdir_"; \
+	done
 	/bin/rm -rf Makefile config.log stamp-h1 config.status \
-	configure.lineno config.h autom4te.cache
-
-${SUBDIR}: nonexistant
-	cd $@; $(MAKE) all $(MFLAGS)
-
-nonexistant:
+	    configure.lineno config.h autom4te.cache
--- pcc-1.1.0~DEVEL+20110422.orig/cc/ccom/Makefile.in
+++ pcc-1.1.0~DEVEL+20110422/cc/ccom/Makefile.in
@@ -11,9 +11,14 @@ XFL=-DPCC_DEBUG
 CC = @CC@
 EXEEXT = @EXEEXT@
 CC_FOR_BUILD = @CC_FOR_BUILD@
+CFLAGS_FOR_BUILD = @CFLAGS_FOR_BUILD@
+CPPFLAGS_FOR_BUILD = @CPPFLAGS_FOR_BUILD@ -D_ISOC99_SOURCE \
+	@ADD_CPPFLAGS@ ${XFL} -Dos_${TARGOS} -Dmach_${TARGMACH} \
+	-I${srcdir} -I${builddir} -I${top_builddir} -I${MIPDIR} -I${MDIR} \
+	-I${top_srcdir}/os/${TARGOS}
 _CFLAGS = @CFLAGS@
 CFLAGS = $(_CFLAGS) @ADD_CFLAGS@
-CPPFLAGS = @ADD_CPPFLAGS@ ${XFL} -Dos_${TARGOS} -Dmach_${TARGMACH} \
+CPPFLAGS = @CPPFLAGS@ @ADD_CPPFLAGS@ ${XFL} -Dos_${TARGOS} -Dmach_${TARGMACH} \
 	-D_ISOC99_SOURCE \
 	-I${srcdir} -I${builddir} -I${top_builddir} -I${MIPDIR} -I${MDIR} \
 	-I${top_srcdir}/os/${TARGOS} 
@@ -92,7 +97,8 @@ compat.o: $(MIPDIR)/compat.c external.h
 	$(CC) $(DEFS) $(CPPFLAGS) $(CFLAGS) -c -o $@ $(MIPDIR)/compat.c
 
 external.h external.c: ${MIPDIR}/mkext.c $(MDIR)/table.c
-	$(CC_FOR_BUILD) $(DEFS) $(CPPFLAGS) $(CFLAGS) -DMKEXT -o mkext \
+	$(CC_FOR_BUILD) $(DEFS) $(CPPFLAGS_FOR_BUILD) $(CFLAGS_FOR_BUILD) \
+	    -DMKEXT -o mkext \
 	${MIPDIR}/mkext.c $(MDIR)/table.c ${MIPDIR}/common.c
 	./mkext
 
--- pcc-1.1.0~DEVEL+20110422.orig/libs/Makefile.in
+++ pcc-1.1.0~DEVEL+20110422/libs/Makefile.in
@@ -5,19 +5,25 @@
 
 VPATH = @srcdir@
 
-SUBDIR = libsoftfloat libpcc csu
+ALL_SUBDIRS=	libsoftfloat libpcc csu
+DIST_SUBDIRS=	$(ALL_SUBDIRS) libF77 libI77
 
-all: $(SUBDIR)
-
-install clean:
-	for f in $(SUBDIR); do (cd $$f && $(MAKE) $@); done
+all install clean:
+	@for subdir in $(ALL_SUBDIRS); do \
+		_nextdir_=$${_thisdir_+$$_thisdir_/}$$subdir; \
+		echo "===> $$_nextdir_"; \
+		(_thisdir_=$$_nextdir_; export _thisdir_; cd $$subdir && \
+		    exec $(MAKE) $(MFLAGS) $@) || exit $$?; \
+		echo "<=== $$_nextdir_"; \
+	done
 
 distclean: clean
-	for f in $(SUBDIR); do (cd $$f && $(MAKE) distclean); done
+	@for subdir in $(DIST_SUBDIRS); do \
+		_nextdir_=$${_thisdir_+$$_thisdir_/}$$subdir; \
+		echo "===> $$_nextdir_"; \
+		(_thisdir_=$$_nextdir_; export _thisdir_; cd $$subdir && \
+		    exec $(MAKE) $(MFLAGS) $@) || exit $$?; \
+		echo "<=== $$_nextdir_"; \
+	done
 	/bin/rm -rf Makefile config.log config.status \
 		configure.lineno config.h autom4te.cache
-
-$(SUBDIR): nonexistant
-	cd $@; $(MAKE) all $(MFLAGS)
-
-nonexistant:
--- pcc-1.1.0~DEVEL+20110422.orig/libs/libF77/Makefile
+++ pcc-1.1.0~DEVEL+20110422/libs/libF77/Makefile
@@ -28,6 +28,6 @@ CHAR =	s_cat.o s_cmp.o s_copy.o
 libF77.a : $(MISC) $(POW) $(CX) $(DCX) $(REAL) $(DBL) $(INT) $(HALF) $(CMP) $(CHAR) cabs.o
 	ar r libF77.a $?
 
-clean:
+clean distclean:
 	rm -f $(MISC) $(POW) $(CX) $(DCX) $(REAL) $(DBL) $(INT) $(HALF) \
 		$(CMP) $(CHAR) cabs.o libF77.a
--- pcc-1.1.0~DEVEL+20110422.orig/libs/libI77/Makefile
+++ pcc-1.1.0~DEVEL+20110422/libs/libI77/Makefile
@@ -16,5 +16,5 @@ OBJS= backspace.o dfe.o due.o iio.o inqu
 libI77.a: $(OBJS)
 	ar r libI77.a $?
 
-clean:
+clean distclean:
 	/bin/rm -f $(OBJS) libI77.a
