[project @ 2001-02-13 14:18:49 by simonmar]
[ghc-hetmet.git] / mk / target.mk
index 5008e98..aae3cfd 100644 (file)
 # 
 #
 
+##################################################################
+#              FPtools standard targets
+#
+# depend:
+#
+#  The depend target has to cope with a set of files that may have
+#  different ways of computing their dependencies, i.e., a Haskell
+#  module's dependencies are computed differently from C files.
+#
+.PHONY: depend
+
+# Compiler produced files that are targets of the source's imports.
+MKDEPENDHS_OBJ_SUFFICES=o
+
+DEPEND_SRCS = $(MKDEPENDHS_SRCS) $(MKDEPENDC_SRCS)
+
+ifneq "$(DEPEND_SRCS)" ""
+depend :: .depend
+
+# Build .depend, then recursively invoke $(MAKE) to carry on.  Because the
+# build system includes .depend (from boilerplate.mk), GNU make records .depend
+# as a Makefile and automatically tries to rebuild it if it is out-of-date.
+# this will happen before any other targets are processed.
+.depend : $(DEPEND_SRCS)
+       @echo "------------------------------------------------------------------------"
+       @echo "===fptools== Rebuilding dependencies..."
+       @echo "PWD = $(shell pwd)"
+       @echo "------------------------------------------------------------------------"
+       @$(RM) .depend
+       @touch .depend
+ifneq "$(MKDEPENDC_SRCS)" ""
+       $(MKDEPENDC) -f .depend $(MKDEPENDC_OPTS) $(foreach way,$(WAYS),-s $(way)) -- $(CC_OPTS) -- $(MKDEPENDC_SRCS) 
+endif
+ifneq "$(MKDEPENDHS_SRCS)" ""
+       $(MKDEPENDHS) -M -optdep-f -optdep.depend $(foreach way,$(WAYS),-optdep-s -optdep$(way)) $(foreach obj,$(MKDEPENDHS_OBJ_SUFFICES),-osuf $(obj)) $(MKDEPENDHS_OPTS) $(HC_OPTS) $(MKDEPENDHS_SRCS)
+endif
+
+else # no dependencies required
+depend ::
+endif
 
 ##################################################################
 #
@@ -81,12 +121,12 @@ ifneq "$(SUBDIRS)" ""
 
 # we override the boot & all targets in the top level Makefile
 ifneq "$(NO_ALL_TARGETS)" "YES"
-ALL     = all
-BOOT    = boot
-INSTALL = install
+ALL_TARGET     = all
+BOOT_TARGET    = boot
+INSTALL_TARGET = install
 endif
 
-$(ALL) docs runtests $(BOOT) TAGS clean distclean mostlyclean maintainer-clean $(INSTALL) html ps dvi txt::
+$(ALL_TARGET) docs runtests $(BOOT_TARGET) TAGS clean distclean mostlyclean maintainer-clean $(INSTALL_TARGET) html ps dvi txt::
        @echo "------------------------------------------------------------------------"
        @echo "===fptools== Recursively making \`$@' in $(SUBDIRS) ..."
        @echo "PWD = $(shell pwd)"
@@ -118,48 +158,6 @@ $(SUBDIRS) ::
 endif
 
 ##################################################################
-#              FPtools standard targets
-#
-# depend:
-#
-#  The depend target has to cope with a set of files that may have
-#  different ways of computing their dependencies, i.e., a Haskell
-#  module's dependencies are computed differently from C files.
-#
-# Note that we don't compute dependencies automatically, i.e., have the
-# .depend file be a target that is dependent on the Haskell+C sources,
-# and then have the `depend' target depend on `.depend'. The reason for
-# this is that when GNU make is processing the `include .depend' statement
-# it records .depend as being a Makefile. Before doing any other processing,
-# `make' will try to check to see if the Makefiles are up-to-date. And,
-# surprisingly enough, .depend has a rule for it, so if any of the source
-# files change, it will be invoked, *regardless* of what target you're making.
-#
-# So, for now, the dependencies has to be re-computed manually via `make depend'
-# whenever a module changes its set of imports. Doing what was outlined above
-# is only a small optimisation anyway, it would avoid the recomputation of
-# dependencies if the .depend file was newer than any of the source modules.
-#
-.PHONY: depend
-
-# Compiler produced files that are targets of the source's imports.
-MKDEPENDHS_OBJ_SUFFICES=o
-
-depend :: $(MKDEPENDHS_SRCS) $(MKDEPENDC_SRCS)
-       @$(RM) .depend
-       @touch .depend
-ifneq "$(DOC_SRCS)" ""
-       $(MKDEPENDLIT) -o .depend $(MKDEPENDLIT_OPTS) $(filter %.lit,$(DOC_SRCS))
-endif
-ifneq "$(MKDEPENDC_SRCS)" ""
-       $(MKDEPENDC) -f .depend $(MKDEPENDC_OPTS) $(foreach way,$(WAYS),-s $(way)) -- $(CC_OPTS) -- $(MKDEPENDC_SRCS) 
-endif
-ifneq "$(MKDEPENDHS_SRCS)" ""
-       $(MKDEPENDHS) -M -optdep-f -optdep.depend $(foreach way,$(WAYS),-optdep-s -optdep$(way)) $(foreach obj,$(MKDEPENDHS_OBJ_SUFFICES),-osuf $(obj)) $(MKDEPENDHS_OPTS) $(HC_OPTS) $(MKDEPENDHS_SRCS)
-endif
-
-
-##################################################################
 #                      boot
 #
 #  The boot target, at a minimum generates dependency information
@@ -359,19 +357,23 @@ SRC_HC_OPTS += -split-objs
 
 define BUILD_LIB
 $(RM) $@
-( echo $(STUBOBJS) ; $(FIND) $(patsubst %.$(way_)o,%,$(LIBOBJS)) -name '*.$(way_)o' -print ) | xargs ar q $@
+(echo $(STUBOBJS); $(FIND) $(patsubst %.$(way_)o,%,$(LIBOBJS)) -name '*.$(way_)o') | xargs ar q $@
 $(RANLIB) $@
 endef
 
 # Extra stuff for compiling Haskell files with $(SplitObjs):
 
-HC_SPLIT_PRE= \
- $(RM) $@ ; if [ ! -d $(basename $@) ]; then mkdir $(basename $@); else \
- $(FIND) $(basename $@) -name '*.$(way_)o' -print | xargs $(RM) __rm_food ; fi
-HC_SPLIT_POST  = touch $@
+HC_SPLIT_PRE = \
+    $(RM) $@; if [ ! -d $(basename $@) ]; then mkdir $(basename $@); else \
+    $(FIND) $(basename $@) -name '*.$(way_)o' | xargs $(RM) __rm_food; fi
+ifeq "$(GhcWithInterpreter)" "YES"
+HC_SPLIT_POST = ld -r -x -o $@ $(basename $@)/*.$(way_)o
+else
+HC_SPLIT_POST = touch $@
+endif
 
-SRC_HC_PRE_OPTS  += $(HC_SPLIT_PRE) ;
-SRC_HC_POST_OPTS += $(HC_SPLIT_POST) ;
+SRC_HC_PRE_OPTS  += $(HC_SPLIT_PRE);
+SRC_HC_POST_OPTS += $(HC_SPLIT_POST);
 
 #
 # If (Haskell) object files are split, cleaning up 
@@ -413,6 +415,7 @@ endif
 #
 
 ifneq "$(GHCI_LIBRARY)" ""
+ifeq "$(way)" ""
 ifeq "$(GhcWithInterpreter)" "YES"
 
 all :: $(GHCI_LIBRARY)
@@ -421,22 +424,14 @@ ifeq "$(GHCI_LIBOBJS)" ""
 GHCI_LIBOBJS = $(LIBOBJS)
 endif
 
-ifneq "$(HS_SRCS)" ""
-ifeq "$(SplitObjs)" "YES"
-$(GHCI_LIBRARY) :: $(GHCI_LIBOBJS)
-       ( echo $(STUBOBJS) ; $(FIND) $(patsubst %.$(way_)o,%,$(GHCI_LIBOBJS)) -name '*.$(way_)o' -print ) | xargs ld -r -x -o $@
-else # not SplitObjs
 $(GHCI_LIBRARY) :: $(GHCI_LIBOBJS)
-       ld -r -x -o $@ $(GHCI_LIBOBJS)
-endif
-else # no HS_SRCS
-$(GHCI_LIBRARY) :: $(GHCI_LIBOBJS)
-       ld -r -x -o $@ $(GHCI_LIBOBJS)
-endif
+       ld -r -x -o $@ $(GHCI_LIBOBJS) $(STUBOBJS)
 
+INSTALL_LIBS += $(GHCI_LIBRARY)
 CLEAN_FILES += $(GHCI_LIBRARY)
 endif
 endif
+endif
 
 #----------------------------------------
 #      Building Win32 DLLs
@@ -639,31 +634,68 @@ endif
        @echo Done.
 endif
 
-# links to script programs: we sometimes install a script as
-# <name>-<version> with a link from <name> to the real script.
+# ---------------------------------------------------------------------------
+# Symbolic links
+
+# links to programs: we sometimes install a program as
+# <name>-<version> with a link from <name> to the real program.
+
+ifneq "$(LINK)" ""
+
+all :: $(LINK)
 
-ifneq "$(SCRIPT_LINK)" ""
-all :: $(SCRIPT_LINK)
+CLEAN_FILES += $(LINK)
+
+ifeq "$(LINK_TARGET)" ""
+ifneq "$(SCRIPT_PROG)" ""
+LINK_TARGET = $(SCRIPT_PROG)
+else
+ifneq "$(HS_PROG)" ""
+LINK_TARGET = $(HS_PROG)
+else
+ifneq "$(C_PROG)" ""
+LINK_TARGET = $(C_PROG)
+else
+LINK_TARGET = dunno
+endif
+endif
+endif
+endif
 
 #
-# Don't want to overwrite $(SCRIPT_LINK)s that aren't symbolic
+# Don't want to overwrite $(LINK)s that aren't symbolic
 # links. Testing for symbolic links is problematic to do in
 # a portable fashion using a /bin/sh test, so we simply rely
 # on perl.
 #
-$(SCRIPT_LINK) : $(SCRIPT_PROG)
-       @if ( $(PERL) -e '$$fn="$(SCRIPT_LINK)"; exit ((! -f $$fn || -l $$fn) ? 0 : 1);' ); then \
-          echo "Creating a symbolic link from $(SCRIPT_PROG) to $(SCRIPT_LINK)"; \
-          $(RM) $(SCRIPT_LINK); \
-          $(LN_S) $(SCRIPT_PROG) $(SCRIPT_LINK); \
+$(LINK) : $(LINK_TARGET)
+       @if ( $(PERL) -e '$$fn="$(LINK)"; exit ((! -f $$fn || -l $$fn) ? 0 : 1);' ); then \
+          echo "Creating a symbolic link from $(LINK_TARGET) to $(LINK)"; \
+          $(RM) $(LINK); \
+          $(LN_S) $(LINK_TARGET) $(LINK); \
         else \
-          echo "Creating a symbolic link from $(SCRIPT_PROG) to $(SCRIPT_LINK) failed: \`$(SCRIPT_LINK)' already exists"; \
-          echo "Perhaps remove \`$(SCRIPT_LINK)' manually?"; \
+          echo "Creating a symbolic link from $(LINK_TARGET) to $(LINK) failed: \`$(LINK)' already exists"; \
+          echo "Perhaps remove \`$(LINK)' manually?"; \
           exit 1; \
         fi;
-endif
 
 
+#
+# install links to script drivers.
+#
+install ::
+       @if ( $(PERL) -e '$$fn="$(bindir)/$(LINK)"; exit ((! -f $$fn || -l $$fn) ? 0 : 1);' ); then \
+          echo "Creating a symbol link from $(LINK_TARGET) to $(LINK) in $(bindir)"; \
+          $(RM) $(bindir)/$(LINK); \
+          $(LN_S) $(LINK_TARGET) $(bindir)/$(LINK); \
+        else \
+          echo "Creating a symbol link from $(LINK_TARGET) to $(LINK) in $(bindir) failed: \`$(bindir)/$(LINK)' already exists"; \
+          echo "Perhaps remove \`$(bindir)/$(LINK)' manually?"; \
+          exit 1; \
+        fi;
+
+endif # LINK 
+
 
 ###########################################
 #
@@ -862,23 +894,6 @@ install-strip::
        @$(MAKE) EXTRA_INSTALL_OPTS='-s' install                                        
 endif
 
-#
-# install links to script drivers.
-#
-ifneq "$(SCRIPT_LINK)" ""
-install ::
-       @if ( $(PERL) -e '$$fn="$(bindir)/$(SCRIPT_LINK)"; exit ((! -f $$fn || -l $$fn) ? 0 : 1);' ); then \
-          echo "Creating a symbol link from $(SCRIPT_PROG) to $(SCRIPT_LINK) in $(bindir)"; \
-          $(RM) $(bindir)/$(SCRIPT_LINK); \
-          $(LN_S) $(SCRIPT_PROG) $(bindir)/$(SCRIPT_LINK); \
-        else \
-          echo "Creating a symbol link from $(SCRIPT_PROG) to $(SCRIPT_LINK) in $(bindir) failed: \`$(bindir)/$(SCRIPT_LINK)' already exists"; \
-          echo "Perhaps remove \`$(bindir)/$(SCRIPT_LINK)' manually?"; \
-          exit 1; \
-        fi;
-
-endif
-
 ###########################################
 #
 #      Targets: check tags show