From d5506465b53089cc3c3d126fc42fc26c971271b7 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Mon, 21 Mar 2011 15:21:20 +0100
Subject: [PATCH] Fix parallel compilation for htools

We do it via per-target-binary .o/.hi files. There are a few other
options, in the end this was chosen as different binaries can have
different options/components (e.g. hail won't use RAPI, etc.) and that
the unittests need different compilation options.

We add a wildcard *.o/*.hi to CLEANFILES, so that it removes all
per-target build artifacts.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>
---
 Makefile.am | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index c155895a8..deaebf7e4 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -40,6 +40,11 @@ docdir = $(datadir)/doc/$(PACKAGE)
 # Delete output file if an error occurred while building it
 .DELETE_ON_ERROR:
 
+HTOOLS_DIRS = \
+	htools \
+	htools/Ganeti \
+	htools/Ganeti/HTools
+
 DIRS = \
 	autotools \
 	daemons \
@@ -48,9 +53,7 @@ DIRS = \
 	doc/examples \
 	doc/examples/hooks \
 	doc/examples/gnt-debug \
-	htools \
-	htools/Ganeti \
-	htools/Ganeti/HTools \
+	$(HTOOLS_DIRS) \
 	lib \
 	lib/client \
 	lib/build \
@@ -98,6 +101,8 @@ maintainer-clean-local:
 
 CLEANFILES = \
 	$(addsuffix /*.py[co],$(DIRS)) \
+	$(addsuffix /*.hi,$(HTOOLS_DIRS)) \
+	$(addsuffix /*.o,$(HTOOLS_DIRS)) \
 	$(all_dirfiles) \
 	$(PYTHON_BOOTSTRAP) \
 	epydoc.conf \
@@ -117,9 +122,7 @@ CLEANFILES = \
 	tools/kvm-ifup \
 	stamp-srclinks \
 	$(nodist_pkgpython_PYTHON) \
-	$(HALLPROGS) $(HSRCS2) \
-	$(patsubst %.hs,%.hi,$(HSRCS) $(HSRCPROGS) $(HSRCS2)) \
-	$(patsubst %.hs,%.o,$(HSRCS) $(HSRCPROGS) $(HSRCS2))
+	$(HALLPROGS) $(HSRCS2)
 
 # BUILT_SOURCES should only be used as a dependency on phony targets. Otherwise
 # it'll cause the target to rebuild every time.
@@ -279,7 +282,7 @@ HPROGS = \
 HALLPROGS = $(HPROGS) htools/test
 HSRCPROGS = $(patsubst %,%.hs,$(HALLPROGS))
 # we don't add -Werror by default
-HFLAGS = -O -Wall -fwarn-monomorphism-restriction -fwarn-tabs
+HFLAGS = -O -Wall -fwarn-monomorphism-restriction -fwarn-tabs -ihtools
 HEXTRA =
 
 HSRCS = \
@@ -307,7 +310,6 @@ HSRCS = \
 HSRCS2 = htools/Ganeti/HTools/Version.hs
 HSRCS2IN = $(patsubst %,%.in,$(HSRCS2))
 
-
 $(RUN_IN_TEMPDIR): | $(all_dirfiles)
 
 # Note: we use here an order-only prerequisite, as the contents of
@@ -410,8 +412,11 @@ iallocators_SCRIPTS += $(filter htools/hail,$(HPROGS))
 endif
 
 $(HALLPROGS): %: %.hs $(HSRCS) $(HSRCS2) Makefile
-	cd htools && $(GHC) --make $(HFLAGS) $(HEXTRA) $(HTOOLS_NOCURL) \
-	  $(patsubst htools/%,%,$@)
+	BINARY=$(@:htools/%=%); \
+	$(GHC) --make \
+	  $(HFLAGS) $(HEXTRA) $(HTOOLS_NOCURL) \
+	  -osuf $$BINARY.o -hisuf $$BINARY.hi \
+	  $@
 
 dist_sbin_SCRIPTS = \
 	tools/ganeti-listrunner
-- 
GitLab