]> git.saurik.com Git - apple/xnu.git/blobdiff - makedefs/MakeInc.rule
xnu-4903.221.2.tar.gz
[apple/xnu.git] / makedefs / MakeInc.rule
index bfd896d290996d459bdcbb30056a6335a5ed5eb4..d2e05a89fea2cdf3c00ef2f4ed107c7629143411 100644 (file)
@@ -1,22 +1,17 @@
+# -*- mode: makefile;-*-
 #
-# Generic Install rules
+# Copyright (C) 1999-2016 Apple Inc. All rights reserved.
+#
+# MakeInc.rule defines the targets and rules for
+# leaf directories once MakeInc.dir has recursed
+# into them. "do_XXX" may be double-colon rules
+# to allow the Makefile in the source directory
+# to augment the actions that will be performed.
 #
 
-ifndef INSTALL_MI_LCL_LIST
-    INSTALL_MI_LCL_LIST = $(INSTALL_MI_LIST)
-endif
-
-ifndef INSTALL_MI_LCL_GEN_LIST
-    INSTALL_MI_LCL_GEN_LIST = $(INSTALL_MI_GEN_LIST)
-endif
-
-ifndef INSTALL_MD_LCL_LIST
-    INSTALL_MD_LCL_LIST = $(INSTALL_MD_LIST)
-endif
-
-ifndef INSTALL_MD_LCL_GEN_LIST
-    INSTALL_MD_LCL_GEN_LIST = $(INSTALL_MD_GEN_LIST)
-endif
+#
+# Generic Install rules
+#
 
 ifndef INSTALL_KF_MI_LCL_LIST
     INSTALL_KF_MI_LCL_LIST = $(EXPORT_MI_LIST)
@@ -50,461 +45,242 @@ ifndef INSTALL_KF_MD_GEN_LIST
     INSTALL_KF_MD_GEN_LIST = $(EXPORT_MD_GEN_LIST)
 endif
 
-INSTALL_MI_GEN_FILES = $(addprefix $(DSTROOT)/$(INCDIR)/$(INSTALL_MI_DIR)/, $(INSTALL_MI_GEN_LIST))
-
-$(INSTALL_MI_GEN_FILES): $(DSTROOT)/$(INCDIR)/$(INSTALL_MI_DIR)/% : %
-       @true echo Installing $< in $(dir $@);                  \
-       [ -d $(DSTROOT)/$(INCDIR)/$(INSTALL_MI_DIR) ] ||$(MKDIR) $(DSTROOT)/$(INCDIR)/$(INSTALL_MI_DIR);        \
-       filename=`$(BASENAME) $<`;                              \
-       filename_strip=$(addsuffix .strip,$${filename});        \
-       $(RM) $(RMFLAGS) $@;                                    \
-       [ -d ./incmidir ] || $(MKDIR) ./incmidir;                       \
-       echo garbage > ./incmidir/$${filename_strip};           \
-       $(UNIFDEF) $(SINCFRAME_UNIFDEF)                         \
-               $< > ./incmidir/$${filename} ||                 \
-               $(DECOMMENT) ./incmidir/$${filename} r >                \
-               ./incmidir/$${filename_strip};                  \
-       if [ -s ./incmidir/$${filename_strip} ];                        \
-       then (                                                  \
-               install $(INSTALL_FLAGS) ./incmidir/$${filename} $(dir $@);\
-       );                                                      \
-       else                                                    \
-               echo Header file $< not exported;               \
-       fi;
-
-INSTALL_KF_MI_GEN_FILES = $(addprefix  $(DSTROOT)/$(KINCDIR)/$(EXPORT_MI_DIR)/, $(INSTALL_KF_MI_GEN_LIST))
-
-$(INSTALL_KF_MI_GEN_FILES): $(DSTROOT)/$(KINCDIR)/$(EXPORT_MI_DIR)/% : %
-       @true echo Installing $< in $(midir $@);                        \
-       [ -d $(DSTROOT)/$(KINCDIR)/$(EXPORT_MI_DIR) ] ||$(MKDIR) $(DSTROOT)/$(KINCDIR)/$(EXPORT_MI_DIR);        \
-       filename=`$(BASENAME) $<`;                              \
-       filename_strip=$(addsuffix .strip,$${filename});        \
-       $(RM) $(RMFLAGS) $@;                                    \
-       [ -d ./kincmidir ] || $(MKDIR) ./kincmidir;                     \
-       echo garbage > ./kincmidir/$${filename_strip};          \
-       $(UNIFDEF) $(KINCFRAME_UNIFDEF)                         \
-               $< > ./kincmidir/$${filename} ||                        \
-               $(DECOMMENT) ./kincmidir/$${filename} r >               \
-               ./kincmidir/$${filename_strip};                 \
-       if [ -s ./kincmidir/$${filename_strip} ];                       \
-       then (                                                  \
-               install $(INSTALL_FLAGS) ./kincmidir/$${filename} $(dir $@);\
-       );                                                      \
-       else                                                    \
-               echo Header file $< not exported;               \
-       fi;
-
-INSTALL_MI_GEN_LCL_FILES = $(addprefix $(DSTROOT)/$(LCLDIR)/$(INSTALL_MI_DIR)/, $(INSTALL_MI_LCL_GEN_LIST))
-
-$(INSTALL_MI_GEN_LCL_FILES): $(DSTROOT)/$(LCLDIR)/$(INSTALL_MI_DIR)/% : %
-       @true echo Installing $< in $(dir $@);                  \
-       [ -d $(DSTROOT)/$(LCLDIR)/$(INSTALL_MI_DIR) ] ||$(MKDIR) $(DSTROOT)/$(LCLDIR)/$(INSTALL_MI_DIR);        \
-       filename=`$(BASENAME) $<`;                              \
-       filename_strip=$(addsuffix .strip,$${filename});        \
-       $(RM) $(RMFLAGS) $@;                                    \
-       [ -d ./pincmidir ] || $(MKDIR) ./pincmidir;                     \
-       echo garbage > ./pincmidir/$${filename_strip};          \
-       $(UNIFDEF) $(SPINCFRAME_UNIFDEF)                        \
-               $< > ./pincmidir/$${filename} ||                        \
-               $(DECOMMENT) ./pincmidir/$${filename} r >               \
-               ./pincmidir/$${filename_strip};                 \
-       if [ -s ./pincmidir/$${filename_strip} ];                       \
-       then (                                                  \
-               install $(INSTALL_FLAGS) ./pincmidir/$${filename} $(dir $@);\
-       );                                                      \
-       else                                                    \
-               echo Header file $< not exported;               \
-       fi;
-
-INSTALL_KF_MI_LCL_GEN_FILES = $(addprefix  $(DSTROOT)/$(KPINCDIR)/$(EXPORT_MI_DIR)/, $(INSTALL_KF_MI_LCL_GEN_LIST))
-
-$(INSTALL_KF_MI_LCL_GEN_FILES): $(DSTROOT)/$(KPINCDIR)/$(EXPORT_MI_DIR)/% : %
-       @true echo Installing $< in $(dir $@);                  \
-       [ -d $(DSTROOT)/$(KPINCDIR)/$(EXPORT_MI_DIR) ] ||$(MKDIR) $(DSTROOT)/$(KPINCDIR)/$(EXPORT_MI_DIR);      \
-       filename=`$(BASENAME) $<`;                              \
-       filename_strip=$(addsuffix .strip,$${filename});        \
-       $(RM) $(RMFLAGS) $@;                                    \
-       [ -d ./kpincmidir ] || $(MKDIR) ./kpincmidir;                   \
-       echo garbage > ./kpincmidir/$${filename_strip};         \
-       $(UNIFDEF) $(KPINCFRAME_UNIFDEF)                        \
-               $< > ./kpincmidir/$${filename} ||                       \
-               $(DECOMMENT) ./kpincmidir/$${filename} r >              \
-               ./kpincmidir/$${filename_strip};                        \
-       if [ -s ./kpincmidir/$${filename_strip} ];                      \
-       then (                                                  \
-               install $(INSTALL_FLAGS) ./kpincmidir/$${filename} $(dir $@);\
-       );                                                      \
-       else                                                    \
-               echo Header file $< not exported;               \
-       fi;
-
-INSTALL_MD_GEN_INC_FILES = $(addprefix $(DSTROOT)/$(INCDIR)/$(INSTALL_MD_DIR)/, $(INSTALL_MD_GEN_LIST))
-
-$(INSTALL_MD_GEN_INC_FILES): $(DSTROOT)/$(INCDIR)/$(INSTALL_MD_DIR)/% : %
-       @true echo Installing $< in $(dir $@);                  \
-       [ -d $(DSTROOT)/$(INCDIR)/$(INSTALL_MD_DIR) ] ||$(MKDIR) $(DSTROOT)/$(INCDIR)/$(INSTALL_MD_DIR);        \
-       filename=`$(BASENAME) $<`;                              \
-       filename_strip=$(addsuffix .strip,$${filename});        \
-       $(RM) $(RMFLAGS) $@;                                    \
-       [ -d ./incdir ] || $(MKDIR) ./incdir;                   \
-       echo garbage > ./incdir/$${filename_strip};             \
-       $(UNIFDEF) $(SINCFRAME_UNIFDEF)                         \
-               $< > ./incdir/$${filename} ||           \
-               $(DECOMMENT) ./incdir/$${filename} r >          \
-               ./incdir/$${filename_strip};                    \
-       if [ -s ./incdir/$${filename_strip} ];                  \
-       then (                                                  \
-               install $(INSTALL_FLAGS) ./incdir/$${filename} $(dir $@);\
-       );                                                      \
-       else                                                    \
-               echo Header file $< not exported;               \
-       fi;
+ifeq (${XNU_LOGCOLORS},y)
+    LOGCOLORS ?= y
+endif
 
-INSTALL_KF_MD_GEN_FILES = $(addprefix $(DSTROOT)/$(KINCDIR)/$(EXPORT_MD_DIR)/, $(INSTALL_KF_MD_GEN_LIST))
+ifeq ($(LOGCOLORS),y)
+    # Get a nice list of device code names associated with the build platform
+    ifndef CDevs
+        #ifdef EMBEDDED_DEVICE_MAP
+        #    export CDevs := $(shell $(EMBEDDED_DEVICE_MAP) -db $(EDM_DBPATH) -query "SELECT DISTINCT TargetType FROM Targets WHERE KernelPlatform = '$(CURRENT_MACHINE_CONFIG_LC)'" | tr '[\r\n]' ':' | sed 's,:$$,,')
+        #endif
+    endif
+    ifndef CMD_MC
+        export _MACHINE := $(CURRENT_MACHINE_CONFIG_LC)
+        ifeq ($(CURRENT_MACHINE_CONFIG),NONE)
+            export _MACHINE := $(subst Mac,,$(PLATFORM))
+        endif
+        export CMD_MC := \\033[1m$(shell __A="$(CURRENT_ARCH_CONFIG_LC)"; \
+                                         __As=$$((6-$${\#__A})); \
+                                         printf "%-.6s%*.*s %9.9s" \
+                                                "$${__A}" \
+                                                $${__As} $${__As} " " \
+                                                "$(_MACHINE)")\\033[m
+    endif
+    # Turn off colored output
+    Color0=\\033[m
+    # Start a host command: bold, underlined pink text
+    ColorH=\\033[1;4;35m
+    # Start a compilation-related command: bold, underlined blue text
+    ColorC=[$(CMD_MC)] \\033[1;4;34m
+    # Start a MIG command: bold, green text on light grey background
+    ColorM=[$(CMD_MC)] \\033[1;32;40m
+    # Start a linking command: bold, white text on blue background
+    ColorL=[$(CMD_MC)] \\033[1;37;44m
+    # Start a filename: bold, white text
+    ColorF=\\033[1;37m
+    # Start a linked file name: yellow text on light grey background
+    ColorLF=\\033[1;33;40m
+    # Error strings: underlined bold white text on red background
+    ColorErr=\033[1;4;37;41m
+endif
 
-$(INSTALL_KF_MD_GEN_FILES): $(DSTROOT)/$(KINCDIR)/$(EXPORT_MD_DIR)/% : %
-       @true echo Installing $< in $(dir $@);                  \
-       [ -d $(DSTROOT)/$(KINCDIR)/$(EXPORT_MD_DIR) ] ||$(MKDIR) $(DSTROOT)/$(KINCDIR)/$(EXPORT_MD_DIR);        \
-       filename=`$(BASENAME) $<`;                              \
-       filename_strip=$(addsuffix .strip,$${filename});        \
-       $(RM) $(RMFLAGS) $@;                                    \
-       [ -d ./kincdir ] || $(MKDIR) ./kincdir;                 \
-       echo garbage > ./kincdir/$${filename_strip};            \
-       $(UNIFDEF) $(KINCFRAME_UNIFDEF)                         \
-               $< > ./kincdir/$${filename} ||                  \
-               $(DECOMMENT) ./kincdir/$${filename} r >         \
-               ./kincdir/$${filename_strip};                   \
-       if [ -s ./kincdir/$${filename_strip} ];                 \
-       then (                                                  \
-               install $(INSTALL_FLAGS) ./kincdir/$${filename} $(dir $@);\
-       );                                                      \
-       else                                                    \
-               echo Header file $< not exported;               \
-       fi;
-
-INSTALL_MD_LCL_FILES = $(addprefix $(SOURCE), $(INSTALL_MD_LCL_LIST))
-INSTALL_MD_GEN_LCL_FILES = $(addprefix $(DSTROOT)/$(LCLDIR)/$(INSTALL_MD_DIR)/, $(INSTALL_MD_LCL_GEN_LIST))
-
-$(INSTALL_MD_GEN_LCL_FILES): $(DSTROOT)/$(LCLDIR)/$(INSTALL_MD_DIR)/% : %
-       @true echo Installing $< in $(dir $@);                  \
-       [ -d $(DSTROOT)/$(LCLDIR)/$(INSTALL_MD_DIR) ] ||$(MKDIR) $(DSTROOT)/$(LCLDIR)/$(INSTALL_MD_DIR);        \
-       filename=`$(BASENAME) $<`;                              \
-       filename_strip=$(addsuffix .strip,$${filename});        \
-       $(RM) $(RMFLAGS) $@;                                    \
-       [ -d ./pincdir ] || $(MKDIR) ./pincdir;                 \
-       echo garbage > ./pincdir/$${filename_strip};            \
-       $(UNIFDEF) $(SPINCFRAME_UNIFDEF)                        \
-               $< > ./pincdir/$${filename} ||                  \
-               $(DECOMMENT) ./pincdir/$${filename} r >         \
-               ./pincdir/$${filename_strip};                   \
-       if [ -s ./pincdir/$${filename_strip} ];                 \
-       then (                                                  \
-               install $(INSTALL_FLAGS) ./pincdir/$${filename} $(dir $@);\
-       );                                                      \
-       else                                                    \
-               echo Header file $< not exported;               \
-       fi;
-
-INSTALL_KF_MD_LCL_FILES = $(addprefix $(SOURCE), $(INSTALL_KF_MD_LCL_LIST))
-INSTALL_KF_MD_LCL_GEN_FILES = $(addprefix $(DSTROOT)/$(KPINCDIR)/$(EXPORT_MD_DIR)/, $(INSTALL_KF_MD_LCL_GEN_LIST))
+.PHONY: ALWAYS
 
-$(INSTALL_KF_MD_LCL_GEN_FILES): $(DSTROOT)/$(KPINCDIR)/$(EXPORT_MD_DIR)/% : %
-       @true echo Installing $< in $(dir $@);                  \
-       [ -d $(DSTROOT)/$(KPINCDIR)/$(EXPORT_MD_DIR) ] ||$(MKDIR) $(DSTROOT)/$(KPINCDIR)/$(EXPORT_MD_DIR);      \
-       filename=`$(BASENAME) $<`;                              \
-       filename_strip=$(addsuffix .strip,$${filename});        \
-       $(RM) $(RMFLAGS) $@;                                    \
-       [ -d ./kpincdir ] || $(MKDIR) ./kpincdir;                       \
-       echo garbage > ./kpincdir/$${filename_strip};           \
-       $(UNIFDEF) $(KPINCFRAME_UNIFDEF)                        \
-               $< > ./kpincdir/$${filename} ||                 \
-               $(DECOMMENT) ./kpincdir/$${filename} r >                \
-               ./kpincdir/$${filename_strip};                  \
-       if [ -s ./kpincdir/$${filename_strip} ];                        \
-       then (                                                  \
-               install $(INSTALL_FLAGS) ./kpincdir/$${filename} $(dir $@);\
-       );                                                      \
-       else                                                    \
-               echo Header file $< not exported;               \
-       fi;
-
-setup_installhdrs_mi: 
-       @echo "[ $(SOURCE) ] make setup_installhdrs_mi $(KERNEL_CONFIG) $(ARCH_CONFIG) $(TARGET)"
-
-do_installhdrs_mi: $(INSTALL_MI_GEN_FILES) $(INSTALL_MI_GEN_LCL_FILES) $(INSTALL_KF_MI_GEN_FILES) $(INSTALL_KF_MI_LCL_GEN_FILES)
-       @true echo "[ $(SOURCE) ] make do_installhdrs_mi $(KERNEL_CONFIG) $(ARCH_CONFIG) $(TARGET)";    \
-       $(MKDIR) ./incmidir ./pincmidir ./kincmidir ./kpincmidir;                               \
-       if [ -n "$(strip $(INSTALL_MI_LIST))" ]; then                   \
-           if [ -d $(DSTROOT)/$(INCDIR)/$(INSTALL_MI_DIR) ]; then      \
-               (cd $(DSTROOT)/$(INCDIR)/$(INSTALL_MI_DIR);$(RM) $(RMFLAGS) $(INSTALL_MI_LIST) );       \
-           else                                                                \
-               $(MKDIR) $(DSTROOT)/$(INCDIR)/$(INSTALL_MI_DIR);        \
-           fi;                                                         \
-           for j in $(INSTALL_MI_LIST);                                \
-           do                                                          \
-               echo garbage > ./incmidir/$$j.strip;                    \
-               $(UNIFDEF) $(SINCFRAME_UNIFDEF)                         \
-                   $(SOURCE)/$$j > ./incmidir/$$j ||                   \
-                   $(DECOMMENT) ./incmidir/$$j r >                     \
-                   ./incmidir/$$j.strip;                               \
-               if [ -s ./incmidir/$$j.strip ];                         \
-               then (                                                  \
-                   install $(INSTALL_FLAGS) ./incmidir/$$j $(DSTROOT)/$(INCDIR)/$(INSTALL_MI_DIR);     \
-               );                                                      \
-               else                                                    \
-                   echo Header file $$j not exported;          \
-               fi;                                                     \
-           done;                                                       \
-       fi;                                                             \
-       if [ -n "$(strip $(INSTALL_MI_LCL_LIST))" ]; then                       \
-           if [ -d $(DSTROOT)/$(LCLDIR)/$(INSTALL_MI_DIR) ]; then      \
-               (cd $(DSTROOT)/$(LCLDIR)/$(INSTALL_MI_DIR);$(RM) $(RMFLAGS) $(INSTALL_MI_LCL_LIST) );       \
-           else                                                                \
-               $(MKDIR) $(DSTROOT)/$(LCLDIR)/$(INSTALL_MI_DIR);        \
-           fi;                                                         \
-           for j in $(INSTALL_MI_LCL_LIST);                            \
-           do                                                          \
-               echo garbage > ./pincmidir/$$j.strip;                   \
-               $(UNIFDEF) $(SPINCFRAME_UNIFDEF)                                \
-                   $(SOURCE)/$$j > ./pincmidir/$$j ||                  \
-                   $(DECOMMENT) ./pincmidir/$$j r >                    \
-                   ./pincmidir/$$j.strip;                              \
-               if [ -s ./pincmidir/$$j.strip ];                                \
-               then (                                                  \
-                   install $(INSTALL_FLAGS) ./pincmidir/$$j $(DSTROOT)/$(LCLDIR)/$(INSTALL_MI_DIR);    \
-               );                                                      \
-               else                                                    \
-                   echo Header file $$j not exported;          \
-               fi;                                                     \
-           done;                                                       \
-       fi;                                                             \
-       if [ -n "$(strip $(INSTALL_KF_MI_LIST))" ]; then                        \
-           if [ -d $(DSTROOT)/$(KINCDIR)/$(EXPORT_MI_DIR) ]; then      \
-               (cd $(DSTROOT)/$(KINCDIR)/$(EXPORT_MI_DIR);$(RM) $(RMFLAGS) $(INSTALL_KF_MI_LIST) );       \
-           else                                                                \
-               $(MKDIR) $(DSTROOT)/$(KINCDIR)/$(EXPORT_MI_DIR);        \
-           fi;                                                         \
-           for j in $(INSTALL_KF_MI_LIST);                             \
-           do                                                          \
-               echo garbage > ./kincmidir/$$j.strip;                   \
-               $(UNIFDEF) $(KINCFRAME_UNIFDEF)                         \
-                   $(SOURCE)/$$j > ./kincmidir/$$j ||                  \
-                   $(DECOMMENT) ./kincmidir/$$j r >                    \
-                   ./kincmidir/$$j.strip;                              \
-               if [ -s ./kincmidir/$$j.strip ];                                \
-               then (                                                  \
-                   install $(INSTALL_FLAGS) ./kincmidir/$$j $(DSTROOT)/$(KINCDIR)/$(EXPORT_MI_DIR);    \
-               );                                                      \
-               else                                                    \
-                   echo Header file $$j not exported;          \
-               fi;                                                     \
-           done;                                                       \
-       fi;                                                             \
-       if [ -n "$(strip $(INSTALL_KF_MI_LCL_LIST))" ]; then                    \
-           if [ -d $(DSTROOT)/$(KPINCDIR)/$(EXPORT_MI_DIR) ]; then     \
-               (cd $(DSTROOT)/$(KPINCDIR)/$(EXPORT_MI_DIR);$(RM) $(RMFLAGS) $(INSTALL_KF_MI_LCL_LIST) );       \
-           else                                                                \
-               $(MKDIR) $(DSTROOT)/$(KPINCDIR)/$(EXPORT_MI_DIR);       \
-           fi;                                                         \
-           for j in $(INSTALL_KF_MI_LCL_LIST);                         \
-           do                                                          \
-               echo garbage > ./kpincmidir/$$j.strip;                  \
-               $(UNIFDEF) $(KPINCFRAME_UNIFDEF)                                \
-                   $(SOURCE)/$$j > ./kpincmidir/$$j ||                 \
-                   $(DECOMMENT) ./kpincmidir/$$j r >                   \
-                   ./kpincmidir/$$j.strip;                             \
-               if [ -s ./kpincmidir/$$j.strip ];                               \
-               then (                                                  \
-                   install $(INSTALL_FLAGS) ./kpincmidir/$$j $(DSTROOT)/$(KPINCDIR)/$(EXPORT_MI_DIR);  \
-               );                                                      \
-               else                                                    \
-                   echo Header file $$j not exported;          \
-               fi;                                                     \
-           done;                                                       \
-       fi;                                                             \
-       $(RM) -rf ./incmidir ./pincmidir ./kincmidir ./kpincmidir;
-
-setup_installhdrs_md:
-       @echo "[ $(SOURCE) ] make setup_installhdrs_md $(KERNEL_CONFIG) $(ARCH_CONFIG) $(TARGET)"
-
-do_installhdrs_md: $(INSTALL_MD_GEN_INC_FILES) $(INSTALL_MD_GEN_LCL_FILES) $(INSTALL_KF_MD_GEN_FILES) $(INSTALL_KF_MD_LCL_GEN_FILES)
-       @true echo "[ $(SOURCE) ] make do_installhdrs_md $(KERNEL_CONFIG) $(ARCH_CONFIG) $(TARGET)";    \
-       $(MKDIR) ./incdir ./pincdir ./kincdir ./kpincdir;                               \
-       if [ -n "$(strip $(INSTALL_MD_LIST))" ]; then                   \
-           if [ -d $(DSTROOT)/$(INCDIR)/$(INSTALL_MD_DIR) ]; then      \
-               (cd $(DSTROOT)/$(INCDIR)/$(INSTALL_MD_DIR);$(RM) $(RMFLAGS) $(INSTALL_MD_LIST) );       \
-           else                                                        \
-               $(MKDIR) $(DSTROOT)/$(INCDIR)/$(INSTALL_MD_DIR);        \
-           fi;                                                         \
-           for j in $(INSTALL_MD_LIST);                                \
-           do                                                          \
-               echo garbage > ./incdir/$$j.strip;                      \
-               $(UNIFDEF) $(SINCFRAME_UNIFDEF)                         \
-                   $(SOURCE)/$$j > ./incdir/$$j ||                     \
-                   $(DECOMMENT) ./incdir/$$j r >                       \
-                   ./incdir/$$j.strip;                         \
-               if [ -s ./incdir/$$j.strip ];                           \
-               then (                                                  \
-                   install $(INSTALL_FLAGS) ./incdir/$$j $(DSTROOT)/$(INCDIR)/$(INSTALL_MD_DIR);       \
-               );                                                      \
-               else                                                    \
-                   echo Header file $$j not exported;          \
-               fi;                                                     \
-           done;                                                       \
-       fi;                                                             \
-       if [ -n "$(strip $(INSTALL_MD_LCL_LIST))" ]; then                       \
-           if [ -d $(DSTROOT)/$(LCLDIR)/$(INSTALL_MD_DIR) ]; then      \
-               (cd $(DSTROOT)/$(LCLDIR)/$(INSTALL_MD_DIR);$(RM) $(RMFLAGS) $(INSTALL_MD_LCL_LIST) );       \
-           else                                                        \
-               $(MKDIR) $(DSTROOT)/$(LCLDIR)/$(INSTALL_MD_DIR);        \
-           fi;                                                         \
-           for j in $(INSTALL_MD_LCL_LIST);                            \
-           do                                                          \
-               echo garbage > ./pincdir/$$j.strip;                     \
-               $(UNIFDEF) $(SPINCFRAME_UNIFDEF)                                \
-                   $(SOURCE)/$$j > ./pincdir/$$j ||                    \
-                   $(DECOMMENT) ./pincdir/$$j r >                      \
-                   ./pincdir/$$j.strip;                                \
-               if [ -s ./pincdir/$$j.strip ];                          \
-               then (                                                  \
-                   install $(INSTALL_FLAGS) ./pincdir/$$j $(DSTROOT)/$(LCLDIR)/$(INSTALL_MD_DIR);      \
-               );                                                      \
-               else                                                    \
-                   echo Header file $$j not exported;          \
-               fi;                                                     \
-           done;                                                       \
+ALWAYS:
+
+# $(1) is the list of install paths
+# $(2) is "1" if it's a "GEN"-style rule that looks locally, or else $(SOURCE)
+# $(3) is the local temp directory for processing
+# $(4) is the unifdef flags
+#
+# $$$$$$$$ is a double-escaped "$$" to represent the current pid
+# of the shell process for creating uniquely named temporary files
+
+define INSTALLHDRS_RULE_template
+
+.PHONY: $(3)_MKDIR
+
+$(3)_MKDIR:
+       $$(_v)$$(MKDIR) ./$(3)
+       $$(_v)$$(MKDIR) $(dir $(firstword $(1)))
+
+# Rebuild if unifdef flags change
+$(1): $(3)/.UNIFDEF_FLAGS
+$(3)/.UNIFDEF_FLAGS: ALWAYS | $(3)_MKDIR
+       $$(_v)$$(REPLACECONTENTS) $$@ $$(UNIFDEF) $(4)
+
+$(1): $(dir $(firstword $(1)))% : $(if $(2),%,$$(SOURCE)/%) | $(3)_MKDIR
+       @echo "$$(ColorH)INSTALLHDR$$(Color0)    $$(ColorF)$$*$$(Color0)"
+       $$(_v)$$(UNIFDEF) $(4) $$< > ./$(3)/$$*.unifdef.$$$$$$$$;       \
+       if [ $$$$? -eq 2 ]; then                                                \
+               echo Parse failure for $$<;                             \
+               exit 1;                                                 \
        fi;                                                             \
-       if [ -n "$(strip $(INSTALL_KF_MD_LIST))" ]; then                        \
-           if [ -d $(DSTROOT)/$(KINCDIR)/$(EXPORT_MD_DIR) ]; then      \
-               (cd $(DSTROOT)/$(KINCDIR)/$(EXPORT_MD_DIR);$(RM) $(RMFLAGS) $(INSTALL_KF_MD_LIST) );       \
-           else                                                        \
-               $(MKDIR) $(DSTROOT)/$(KINCDIR)/$(EXPORT_MD_DIR);        \
-           fi;                                                         \
-           for j in $(INSTALL_KF_MD_LIST);                             \
-           do                                                          \
-               echo garbage > ./kincdir/$$j.strip;                     \
-               $(UNIFDEF) $(KINCFRAME_UNIFDEF)                         \
-                   $(SOURCE)/$$j > ./kincdir/$$j ||                    \
-                   $(DECOMMENT) ./kincdir/$$j r >                      \
-                   ./kincdir/$$j.strip;                                \
-               if [ -s ./kincdir/$$j.strip ];                          \
-               then (                                                  \
-                   install $(INSTALL_FLAGS) ./kincdir/$$j $(DSTROOT)/$(KINCDIR)/$(EXPORT_MD_DIR);      \
-               );                                                      \
-               else                                                    \
-                   echo Header file $$j not exported;          \
-               fi;                                                     \
-           done;                                                       \
+       $$(DECOMMENT) ./$(3)/$$*.unifdef.$$$$$$$$ r >                   \
+               ./$(3)/$$*.strip.$$$$$$$$ || exit 1;                    \
+       if [ -s ./$(3)/$$*.strip.$$$$$$$$ ]; then                       \
+               $$(INSTALL) $$(INSTALL_FLAGS) ./$(3)/$$*.unifdef.$$$$$$$$ $$@ || exit 1;        \
        fi;                                                             \
-       if [ -n "$(strip $(INSTALL_KF_MD_LCL_LIST))" ]; then                    \
-           if [ -d $(DSTROOT)/$(KPINCDIR)/$(EXPORT_MD_DIR) ]; then     \
-               (cd $(DSTROOT)/$(KPINCDIR)/$(EXPORT_MD_DIR);$(RM) $(RMFLAGS) $(INSTALL_KF_MD_LCL_LIST) );       \
-           else                                                        \
-               $(MKDIR) $(DSTROOT)/$(KPINCDIR)/$(EXPORT_MD_DIR);       \
-           fi;                                                         \
-           for j in $(INSTALL_KF_MD_LCL_LIST);                         \
-           do                                                          \
-               echo garbage > ./kpincdir/$$j.strip;                    \
-               $(UNIFDEF) $(KPINCFRAME_UNIFDEF)                                \
-                   $(SOURCE)/$$j > ./kpincdir/$$j ||                   \
-                   $(DECOMMENT) ./kpincdir/$$j r >                     \
-                   ./kpincdir/$$j.strip;                               \
-               if [ -s ./kpincdir/$$j.strip ];                         \
-               then (                                                  \
-                   install $(INSTALL_FLAGS) ./kpincdir/$$j $(DSTROOT)/$(KPINCDIR)/$(EXPORT_MD_DIR);    \
-               );                                                      \
-               else                                                    \
-                   echo Header file $$j not exported;          \
-               fi;                                                     \
-           done;                                                       \
+       $$(RM) ./$(3)/$$*.unifdef.$$$$$$$$ ./$(3)/$$*.strip.$$$$$$$$
+endef
+
+# $(1) is the list of install paths
+# $(2) is the source path pattern (using % to match with $(5)) or source file
+# $(3) is the local temp directory for processing
+# $(4) is the unifdef flags
+# $(5) is the destination directory (when pattern matching) or empty
+#
+# $$$$$$$$ is a double-escaped "$$" to represent the current pid
+# of the shell process for creating uniquely named temporary files
+
+define INSTALLPYTHON_RULE_template
+
+.PHONY: $(3)_MKDIR
+
+$(3)_MKDIR:
+       $$(_v)$$(MKDIR) ./$(3)
+
+# Rebuild if unifdef flags change
+$(1): $(3)/.UNIFDEF_FLAGS
+$(3)/.UNIFDEF_FLAGS: ALWAYS | $(3)_MKDIR
+       $$(_v)$$(REPLACECONTENTS) $$@ $$(UNIFDEF) -t $(4)
+
+$(1): $(5)% : $(2) | $(3)_MKDIR
+       @echo "$$(ColorH)INSTALLPY$$(Color0)    $$(ColorF)$$*$$(Color0)"
+       $$(_v)$$(MKDIR) $$(dir $$@) $$(dir ./$(3)/$$*)
+       $$(_v)$$(UNIFDEF) -t $(4) $$< > ./$(3)/$$*.unifdef.$$$$$$$$$$(suffix $$*); \
+       if [ $$$$? -eq 2 ]; then                                                \
+               echo Parse failure for $$<;                             \
+               exit 1;                                                 \
        fi;                                                             \
-       $(RM) -rf ./incdir ./pincdir ./kincdir ./kpincdir;
+       $$(INSTALL) $$(DATA_INSTALL_FLAGS) \
+               ./$(3)/$$*.unifdef.$$$$$$$$$$(suffix $$*) $$@ || exit 1; \
+       $$(PYTHON) $$(LLDBMACROS_SOURCE)/core/syntax_checker.py \
+               ./$(3)/$$*.unifdef.$$$$$$$$$$(suffix $$*) $$(_vstdout) || exit 1; \
+       $$(RM) ./$(3)/$$*.unifdef.$$$$$$$$$$(suffix $$*)
+       $$(_v)if [ -n "$(5)" ]; then $$(TOUCH) "$(5)"; fi
+endef
+
+#
+# Machine-independent (public) files
+#
+
+INSTALL_MI_INC_FILES = $(addprefix $(DSTROOT)/$(INCDIR)/$(INSTALL_MI_DIR)/, $(INSTALL_MI_LIST))
+INSTALL_MI_INC_GEN_FILES = $(addprefix $(DSTROOT)/$(INCDIR)/$(INSTALL_MI_DIR)/, $(INSTALL_MI_GEN_LIST))
+
+$(eval $(call INSTALLHDRS_RULE_template,$(INSTALL_MI_INC_FILES),,incmidir,$(SINCFRAME_UNIFDEF)))
+$(eval $(call INSTALLHDRS_RULE_template,$(INSTALL_MI_INC_GEN_FILES),1,incmigendir,$(SINCFRAME_UNIFDEF)))
 
+INSTALL_KF_MI_FILES = $(addprefix $(DSTROOT)/$(KINCDIR)/$(EXPORT_MI_DIR)/, $(INSTALL_KF_MI_LIST))
+INSTALL_KF_MI_GEN_FILES = $(addprefix $(DSTROOT)/$(KINCDIR)/$(EXPORT_MI_DIR)/, $(INSTALL_KF_MI_GEN_LIST))
+
+$(eval $(call INSTALLHDRS_RULE_template,$(INSTALL_KF_MI_FILES),,kincmidir,$(KINCFRAME_UNIFDEF)))
+$(eval $(call INSTALLHDRS_RULE_template,$(INSTALL_KF_MI_GEN_FILES),1,kincmigendir,$(KINCFRAME_UNIFDEF)))
 
 #
-# Generic Export rules
+# Machine-independent local (private) files
 #
-ifeq ($(INCR_EXPORTHDRS), TRUE)
 
-EXPORT_MI_INC_FILES = $(addprefix $(OBJROOT)/$(EXPDIR)/$(EXPORT_MI_DIR)/, $(EXPORT_MI_LIST))
-EXPORT_MI_GEN_INC_FILES = $(addprefix $(OBJROOT)/$(EXPDIR)/$(EXPORT_MI_DIR)/, $(EXPORT_MI_GEN_LIST))
+INSTALL_MI_LCL_FILES = $(addprefix $(DSTROOT)/$(LCLDIR)/$(INSTALL_MI_DIR)/, $(sort $(INSTALL_MI_LCL_LIST) $(INSTALL_MI_LIST)))
+INSTALL_MI_LCL_GEN_FILES = $(addprefix $(DSTROOT)/$(LCLDIR)/$(INSTALL_MI_DIR)/, $(sort $(INSTALL_MI_LCL_GEN_LIST) $(INSTALL_MI_GEN_LIST)))
 
-$(EXPORT_MI_INC_FILES) $(EXPORT_MI_GEN_INC_FILES): $(OBJROOT)/$(EXPDIR)/$(EXPORT_MI_DIR)/% : %
-       @true echo Exporting $< in $(dir $@);                   \
-       [ -d $(OBJROOT)/$(EXPDIR)/$(EXPORT_MI_DIR) ] ||$(MKDIR) $(OBJROOT)/$(EXPDIR)/$(EXPORT_MI_DIR);  \
-       ${CP} -p $< $(dir $@);  \
+$(eval $(call INSTALLHDRS_RULE_template,$(INSTALL_MI_LCL_FILES),,pincmidir,$(SPINCFRAME_UNIFDEF)))
+$(eval $(call INSTALLHDRS_RULE_template,$(INSTALL_MI_LCL_GEN_FILES),1,pincmigendir,$(SPINCFRAME_UNIFDEF)))
 
+INSTALL_KF_MI_LCL_FILES = $(addprefix $(DSTROOT)/$(KPINCDIR)/$(EXPORT_MI_DIR)/, $(INSTALL_KF_MI_LCL_LIST))
+INSTALL_KF_MI_LCL_GEN_FILES = $(addprefix $(DSTROOT)/$(KPINCDIR)/$(EXPORT_MI_DIR)/, $(INSTALL_KF_MI_LCL_GEN_LIST))
 
-EXPORT_MD_INC_FILES = $(addprefix $(OBJROOT)/$(EXPDIR)/$(EXPORT_MD_DIR)/, $(EXPORT_MD_LIST))
-EXPORT_MD_GEN_INC_FILES = $(addprefix $(OBJROOT)/$(EXPDIR)/$(EXPORT_MD_DIR)/, $(EXPORT_MD_GEN_LIST))
+$(eval $(call INSTALLHDRS_RULE_template,$(INSTALL_KF_MI_LCL_FILES),,kpincmidir,$(KPINCFRAME_UNIFDEF)))
+$(eval $(call INSTALLHDRS_RULE_template,$(INSTALL_KF_MI_LCL_GEN_FILES),1,kpincmigendir,$(KPINCFRAME_UNIFDEF)))
 
-$(EXPORT_MD_INC_FILES) $(EXPORT_MD_GEN_INC_FILES): $(OBJROOT)/$(EXPDIR)/$(EXPORT_MD_DIR)/% : %
-       @true echo Exporting $< in $(dir $@);                   \
-       [ -d $(OBJROOT)/$(EXPDIR)/$(EXPORT_MD_DIR) ] ||$(MKDIR) $(OBJROOT)/$(EXPDIR)/$(EXPORT_MD_DIR);  \
-       ${CP} -p $< $(dir $@);  \
+#
+# Machine-dependent (public) files
+#
 
-setup_exporthdrs_mi:
-       @echo "[ $(SOURCE) ] make setup_exporthdrs_mi $(KERNEL_CONFIG) $(ARCH_CONFIG) $(TARGET)"
+INSTALL_MD_INC_FILES = $(addprefix $(DSTROOT)/$(INCDIR)/$(INSTALL_MD_DIR)/, $(INSTALL_MD_LIST))
+INSTALL_MD_INC_GEN_FILES = $(addprefix $(DSTROOT)/$(INCDIR)/$(INSTALL_MD_DIR)/, $(INSTALL_MD_GEN_LIST))
 
-do_exporthdrs_mi: $(EXPORT_MI_INC_FILES) $(EXPORT_MI_GEN_INC_FILES)
-       @true echo "[ $(SOURCE) ] make do_exporthdrs_mi $(KERNEL_CONFIG) $(ARCH_CONFIG) $(TARGET)"
+$(eval $(call INSTALLHDRS_RULE_template,$(INSTALL_MD_INC_FILES),,incdir,$(SINCFRAME_UNIFDEF)))
+$(eval $(call INSTALLHDRS_RULE_template,$(INSTALL_MD_INC_GEN_FILES),1,incgendir,$(SINCFRAME_UNIFDEF)))
 
-setup_exporthdrs_md:
-       @echo "[ $(SOURCE) ] make setup_exporthdrs_md $(KERNEL_CONFIG) $(ARCH_CONFIG) $(TARGET)"
+INSTALL_KF_MD_FILES = $(addprefix $(DSTROOT)/$(KINCDIR)/$(EXPORT_MD_DIR)/, $(INSTALL_KF_MD_LIST))
+INSTALL_KF_MD_GEN_FILES = $(addprefix $(DSTROOT)/$(KINCDIR)/$(EXPORT_MD_DIR)/, $(INSTALL_KF_MD_GEN_LIST))
 
-do_exporthdrs_md: $(EXPORT_MD_INC_FILES) $(EXPORT_MD_GEN_INC_FILES)
-       @true echo "[ $(SOURCE) ] make do_exporthdrs_md $(KERNEL_CONFIG) $(ARCH_CONFIG) $(TARGET)"
+$(eval $(call INSTALLHDRS_RULE_template,$(INSTALL_KF_MD_FILES),,kincdir,$(KINCFRAME_UNIFDEF)))
+$(eval $(call INSTALLHDRS_RULE_template,$(INSTALL_KF_MD_GEN_FILES),1,kincgendir,$(KINCFRAME_UNIFDEF)))
 
-else
+#
+# Machine-dependent local (private) files
+#
+
+INSTALL_MD_LCL_FILES = $(addprefix $(DSTROOT)/$(LCLDIR)/$(INSTALL_MD_DIR)/, $(sort $(INSTALL_MD_LCL_LIST) $(INSTALL_MD_LIST)))
+INSTALL_MD_LCL_GEN_FILES = $(addprefix $(DSTROOT)/$(LCLDIR)/$(INSTALL_MD_DIR)/, $(sort $(INSTALL_MD_LCL_GEN_LIST) $(INSTALL_MD_GEN_LIST)))
+
+$(eval $(call INSTALLHDRS_RULE_template,$(INSTALL_MD_LCL_FILES),,pincdir,$(SPINCFRAME_UNIFDEF)))
+$(eval $(call INSTALLHDRS_RULE_template,$(INSTALL_MD_LCL_GEN_FILES),1,pincgendir,$(SPINCFRAME_UNIFDEF)))
+
+INSTALL_KF_MD_LCL_FILES = $(addprefix $(DSTROOT)/$(KPINCDIR)/$(EXPORT_MD_DIR)/, $(INSTALL_KF_MD_LCL_LIST))
+INSTALL_KF_MD_LCL_GEN_FILES = $(addprefix $(DSTROOT)/$(KPINCDIR)/$(EXPORT_MD_DIR)/, $(INSTALL_KF_MD_LCL_GEN_LIST))
+
+$(eval $(call INSTALLHDRS_RULE_template,$(INSTALL_KF_MD_LCL_FILES),,kpincdir,$(KPINCFRAME_UNIFDEF)))
+$(eval $(call INSTALLHDRS_RULE_template,$(INSTALL_KF_MD_LCL_GEN_FILES),1,kpincgendir,$(KPINCFRAME_UNIFDEF)))
 
-EXPORT_MI_INC_FILES = $(addprefix $(SOURCE), $(EXPORT_MI_LIST))
+.PHONY: do_installhdrs_mi
+
+# Double-colon rule so that MakeInc.kernel can add custom behaviors
+do_installhdrs_mi:: $(INSTALL_MI_INC_FILES) $(INSTALL_MI_INC_GEN_FILES) $(INSTALL_KF_MI_FILES) $(INSTALL_KF_MI_GEN_FILES) \
+                   $(INSTALL_MI_LCL_FILES) $(INSTALL_MI_LCL_GEN_FILES) $(INSTALL_KF_MI_LCL_FILES) $(INSTALL_KF_MI_LCL_GEN_FILES)
+       @:
+
+.PHONY: do_installhdrs_md
+
+do_installhdrs_md: $(INSTALL_MD_INC_FILES) $(INSTALL_MD_INC_GEN_FILES) $(INSTALL_KF_MD_FILES) $(INSTALL_KF_MD_GEN_FILES) \
+                  $(INSTALL_MD_LCL_FILES) $(INSTALL_MD_LCL_GEN_FILES) $(INSTALL_KF_MD_LCL_FILES) $(INSTALL_KF_MD_LCL_GEN_FILES)
+       @:
+
+#
+# Generic Export rules
+#
+EXPORT_MI_INC_FILES = $(addprefix $(OBJROOT)/$(EXPDIR)/$(EXPORT_MI_DIR)/, $(EXPORT_MI_LIST))
 EXPORT_MI_GEN_INC_FILES = $(addprefix $(OBJROOT)/$(EXPDIR)/$(EXPORT_MI_DIR)/, $(EXPORT_MI_GEN_LIST))
 
-$(EXPORT_MI_GEN_INC_FILES): $(OBJROOT)/$(EXPDIR)/$(EXPORT_MI_DIR)/% : %
-       @true echo Exporting $< in $(dir $@);                   \
-       [ -d $(OBJROOT)/$(EXPDIR)/$(EXPORT_MI_DIR) ] ||$(MKDIR) $(OBJROOT)/$(EXPDIR)/$(EXPORT_MI_DIR);  \
-       ${CP} -p $< $(dir $@);  \
+.PHONY: EXP_MI_INC_DIR
+
+EXP_MI_INC_DIR:
+       $(_v)$(MKDIR) $(OBJROOT)/$(EXPDIR)/$(EXPORT_MI_DIR)
 
+$(EXPORT_MI_GEN_INC_FILES): $(OBJROOT)/$(EXPDIR)/$(EXPORT_MI_DIR)/% : % | EXP_MI_INC_DIR
+       $(_v)$(INSTALL) $(DATA_INSTALL_FLAGS) $< $@
 
-EXPORT_MD_INC_FILES = $(addprefix $(SOURCE), $(EXPORT_MD_LIST))
+$(EXPORT_MI_INC_FILES): $(OBJROOT)/$(EXPDIR)/$(EXPORT_MI_DIR)/% : $(SOURCE)/% | EXP_MI_INC_DIR
+       $(_v)$(INSTALL) $(DATA_INSTALL_FLAGS) $< $@
+
+EXPORT_MD_INC_FILES = $(addprefix $(OBJROOT)/$(EXPDIR)/$(EXPORT_MD_DIR)/, $(EXPORT_MD_LIST))
 EXPORT_MD_GEN_INC_FILES = $(addprefix $(OBJROOT)/$(EXPDIR)/$(EXPORT_MD_DIR)/, $(EXPORT_MD_GEN_LIST))
 
-$(EXPORT_MD_GEN_INC_FILES): $(OBJROOT)/$(EXPDIR)/$(EXPORT_MD_DIR)/% : %
-       @true echo Exporting $< in $(dir $@);                   \
-       [ -d $(OBJROOT)/$(EXPDIR)/$(EXPORT_MD_DIR) ] ||$(MKDIR) $(OBJROOT)/$(EXPDIR)/$(EXPORT_MD_DIR);  \
-       ${CP} -p $< $(dir $@);  \
-
-setup_exporthdrs_mi:
-       @echo "[ $(SOURCE) ] make setup_exporthdrs_mi $(KERNEL_CONFIG) $(ARCH_CONFIG) $(TARGET)"
-
-do_exporthdrs_mi: $(EXPORT_MI_GEN_INC_FILES)
-       @true echo "[ $(SOURCE) ] make do_exporthdrs_mi $(KERNEL_CONFIG) $(ARCH_CONFIG) $(TARGET)"
-       @if [ -n "$(strip $(EXPORT_MI_LIST))" ]; then                                   \
-               if [ -d $(OBJROOT)/$(EXPDIR)/$(EXPORT_MI_DIR) ]; then                   \
-                       (cd $(OBJROOT)/$(EXPDIR)/$(EXPORT_MI_DIR);$(RM) $(RMFLAGS) $(EXPORT_MI_LIST) );       \
-               else                                                            \
-                       $(MKDIR) $(OBJROOT)/$(EXPDIR)/$(EXPORT_MI_DIR); \
-               fi;                                                             \
-               ${CP} -p $(EXPORT_MI_INC_FILES) $(OBJROOT)/$(EXPDIR)/$(EXPORT_MI_DIR);          \
-       fi
-
-setup_exporthdrs_md:
-       @echo "[ $(SOURCE) ] make setup_exporthdrs_md $(KERNEL_CONFIG) $(ARCH_CONFIG) $(TARGET)"
-
-do_exporthdrs_md: $(EXPORT_MD_GEN_INC_FILES)
-       @true echo "[ $(SOURCE) ] make do_exporthdrs_md $(KERNEL_CONFIG) $(ARCH_CONFIG) $(TARGET)"
-       @if [ -n "$(strip $(EXPORT_MD_LIST))" ]; then                                   \
-               if [ -d $(OBJROOT)/$(EXPDIR)/$(EXPORT_MD_DIR) ]; then                   \
-                       (cd $(OBJROOT)/$(EXPDIR)/$(EXPORT_MD_DIR);$(RM) $(RMFLAGS) $(EXPORT_MD_LIST) );       \
-               else                                                            \
-                       $(MKDIR) $(OBJROOT)/$(EXPDIR)/$(EXPORT_MD_DIR); \
-               fi;                                                             \
-               ${CP} -p $(EXPORT_MD_INC_FILES) $(OBJROOT)/$(EXPDIR)/$(EXPORT_MD_DIR);          \
-       fi
+.PHONY: EXP_MD_INC_DIR
 
+EXP_MD_INC_DIR:
+       $(_v)$(MKDIR) $(OBJROOT)/$(EXPDIR)/$(EXPORT_MD_DIR)
+
+$(EXPORT_MD_GEN_INC_FILES): $(OBJROOT)/$(EXPDIR)/$(EXPORT_MD_DIR)/% : % | EXP_MD_INC_DIR
+       $(_v)$(INSTALL) $(DATA_INSTALL_FLAGS) $< $@
+
+$(EXPORT_MD_INC_FILES): $(OBJROOT)/$(EXPDIR)/$(EXPORT_MD_DIR)/% : $(SOURCE)/% | EXP_MD_INC_DIR
+       $(_v)$(INSTALL) $(DATA_INSTALL_FLAGS) $< $@
+
+.PHONY: do_exporthdrs_mi
+
+do_exporthdrs_mi: $(EXPORT_MI_GEN_INC_FILES) $(EXPORT_MI_INC_FILES)
+       @:
+
+.PHONY: do_exporthdrs_md
+
+do_exporthdrs_md: $(EXPORT_MD_GEN_INC_FILES)  $(EXPORT_MD_INC_FILES)
+       @:
 
-#
-endif
 #
 # Generic Compilation rules
 #
@@ -512,203 +288,163 @@ endif
 #
 # Compilation rules to generate .o from .s
 #
-COMP_SOBJ_FILES = $(addprefix $(TARGET)$(COMP_OBJ_DIR), $(COMP_SOBJ_LIST))
-
-$(COMP_SOBJ_FILES): $(TARGET)$(COMP_OBJ_DIR)%.o : %.s
-       ${S_KCC} -E -MD ${SFLAGS} -DASSEMBLER $(INCFLAGS) $< > $(patsubst %.o, %.pp, ${@});
-       sed '/^\#/d' $(patsubst %.o, %.pp, ${@}) > $(patsubst %.o, %.s, ${@});
-       ${S_KCC} ${SFLAGS} ${_HOST_AS_FLAGS}  -c $(patsubst %.o, %.s, ${@});
-       ${RM} ${_RMFLAGS_} $(patsubst %.o, %.pp, ${@}) $(patsubst %.o,%.s,${@});
-
-S_RULE_1A=@ls /
-S_RULE_1B= ${patsubst %.o,%.s,${@}} > /dev/null
-S_RULE_2= ${S_KCC} -E -MD ${SFLAGS} -DASSEMBLER $(INCFLAGS) $< \
-               > $(patsubst %.o, %.pp, ${@}); \
-       sed '/^\#/d' $(patsubst %.o, %.pp, ${@}) > $(patsubst %.o, %.s, ${@});
-S_RULE_3= ${S_KCC} ${SFLAGS} ${_HOST_AS_FLAGS}  -c $(patsubst %.o, %.s, ${@});\
-       ${RM} ${_RMFLAGS_} $(patsubst %.o, %.pp, ${@}) $(patsubst %.o,%.s,${@})
-
-#
-# Compilation rules to generate .o from .c
-#
-COMP_COBJ_FILES = $(addprefix $(TARGET)$(COMP_OBJ_DIR), $(COMP_COBJ_LIST))
 
-$(COMP_COBJ_FILES): $(TARGET)$(COMP_OBJ_DIR)%.o : %.c
-       ${KCC} -c ${filter-out ${${join $@,_CFLAGS_RM}}, ${CFLAGS}} -MD ${${join $@,_CFLAGS_ADD}} ${INCFLAGS} ${${join $@,_INCFLAGS}} $<
+S_RULE_0=@echo "$(ColorC)AS$(Color0)  $(ColorF)$@$(Color0)"
+S_RULE_1A=$(_v)${S_KCC} -c ${SFLAGS} -MD -MF $(@:o=d) -MP ${$@_SFLAGS_ADD} ${INCFLAGS} ${$@_INCFLAGS}
+S_RULE_1B=$(<F)
+S_RULE_2=
 
 #
 # Compilation rules to generate .o from .c for normal files
 #
-C_RULE_1A=${KCC} -c ${filter-out ${${join $@,_CFLAGS_RM}}, ${CFLAGS} ${CWARNFLAGS}} -MD ${${join $@,_CFLAGS_ADD}} ${INCFLAGS} ${${join $@,_INCFLAGS}} 
-C_RULE_1B=$*.c
+C_RULE_0=@echo "$(ColorC)CC$(Color0)  $(ColorF)$@$(Color0)"
+C_RULE_1A=$(_v)${KCC} -c ${filter-out ${$@_CFLAGS_RM}, ${CFLAGS} ${CWARNFLAGS}} -MD -MF $(@:o=d) -MP ${$@_CFLAGS_ADD} ${$@_CWARNFLAGS_ADD} ${INCFLAGS} ${$@_INCFLAGS}
+C_RULE_1B=$(<F)
+ifeq ($(BUILD_MACHO_OBJ),0)
+C_RULE_2=
+else ifeq ($(DO_CTFCONVERT),1)
+C_RULE_2=$(_v)if [ -z "${$@_SKIP_CTFCONVERT}" ]; then \
+                  ctferr=`${CTFCONVERT} -l xnu -v -o $@.ctf $@ 2>&1 > /dev/null || true`; \
+                  if [ ! -z "$${ctferr}" ]; then \
+                      echo "[$(CMD_MC)] $(ColorErr)$@$(Color0)  $(ColorErr)$${ctferr}$(Color0)"; \
+                  fi; \
+              fi
+else
 C_RULE_2=
-C_RULE_3=
-C_RULE_4=
+endif
+ifeq ($(DO_CTFMACHO), 1)
+C_CTFRULE_1A=$(_v)${KCC} -o $@.non_lto -c ${filter-out ${$@_CFLAGS_RM}, ${CFLAGS} ${CWARNFLAGS}} ${$@_CFLAGS_ADD} ${$@_CWARNFLAGS_ADD} ${INCFLAGS} $(CFLAGS_NOLTO_FLAG) ${$@_INCFLAGS}
+C_CTFRULE_1B=$(<F)
+C_CTFRULE_2=$(_v)if [ -z "${$@_SKIP_CTFCONVERT}" ]; then \
+                     ctferr=`${CTFCONVERT} -l xnu -v -o $@.non_lto.ctf $@.non_lto 2>&1 > /dev/null || true`; \
+                     if [ ! -z "$${ctferr}" ]; then \
+                         echo "[$(CMD_MC)] $(ColorErr)$@$(Color0)  $(ColorErr)$${ctferr}$(Color0)"; \
+                     fi; \
+                 fi
+else
+C_CTFRULE_1A=@true 
+C_CTFRULE_1B=
+C_CTFRULE_2=@true 
+endif
+
+C_RULE_3=@true 
+C_RULE_4A=@true 
+C_RULE_4B=
 
 #
 # Compilation rules to generate .o from .c for driver files
 #
+C_RULE_0_D=${C_RULE_0}
 C_RULE_1A_D=${C_RULE_1A}
 C_RULE_1B_D=${C_RULE_1B}
 C_RULE_2_D=${C_RULE_2}
 C_RULE_3_D=${C_RULE_3}
-C_RULE_4_D=${C_RULE_4}
-
-#
-# Compilation rules to generate .o from .m
-#
-M_RULE_1A=${KCC} -c ${filter-out ${${join $@,_CFLAGS_RM}}, ${CFLAGS} ${MWARNFLAGS}} -MD ${${join $@,_CFLAGS_ADD}} ${INCFLAGS} ${${join $@,_INCFLAGS}} 
-M_RULE_1B=$*.m
-M_RULE_2=
-M_RULE_3=
-M_RULE_4=
+C_RULE_4A_D=${C_RULE_4A}
+C_RULE_4B_D=${C_RULE_4B}
+C_CTFRULE_1A_D=${C_CTFRULE_1A}
+C_CTFRULE_1B_D=${C_CTFRULE_1B}
+C_CTFRULE_2_D=${C_CTFRULE_2}
+C_CTFRULE_3_D=${C_CTFRULE_3}
 
 #
 # Compilation rules to generate .co from .cp or .cpo from .cpp
 #   The config tool slickly changes the last source filename char to 'o'
 #   for the object filename.
-#
-P_RULE_1A=${KC++} -o $@ -c ${CXXFLAGS} ${filter-out ${${join $@,_CFLAGS_RM}}, ${CFLAGS} ${CXXWARNFLAGS}} -MD ${${join $@,_CFLAGS_ADD}} ${INCFLAGS} ${${join $@,_INCFLAGS}} 
+P_RULE_0=@echo "$(ColorC)C++$(Color0) $(ColorF)$@$(Color0)"
+P_RULE_1A=$(_v)${KC++} -o $@ -c ${CXXFLAGS} ${filter-out ${$@_CFLAGS_RM}, ${CFLAGS} ${CXXWARNFLAGS}} -MD -MF $(@:o=d) -MP ${$@_CFLAGS_ADD} ${$@_CXXWARNFLAGS_ADD} ${INCFLAGS} ${$@_INCFLAGS}
 P_RULE_1B=$(<F)
-P_RULE_2=@sed 's/.c.o: /.cpo: /' $(@:.cpo=.d) > $(@:.cpo=.d~) && mv $(@:.cpo=.d~) $(@:.cpo=.d)
-P_RULE_3=
-P_RULE_4=
+P_RULE_2=
+P_CTFRULE_1A=@true 
+P_CTFRULE_1B=
+P_CTFRULE_2=@true 
+
+P_RULE_3=@true 
+P_RULE_4A=@true 
+P_RULE_4B=
 
 #
-# Linker rule to generate a component
+# This isn't the right place to put this, but we need to := override some settings
+# in Makefiles that include the generic helper fragments (like this file)
 #
-LD_COMPONENT_OBJ_FILES = $(addprefix $(TARGET)$(COMP_OBJ_DIR), $(LD_COMPONENT_OBJ_LIST))
+ifeq ($(BUILD_JSON_COMPILATION_DATABASE),1)
+HIB_FILES :=
+LAST_FILES :=
+KLD_FILES :=
+endif
 
-COMPONENT_IMAGE_FILE = $(addprefix $(TARGET), $(COMPONENT_IMAGE))
+.PHONY: do_build_all
 
-$(COMPONENT_IMAGE_FILE): $(LD_COMPONENT_OBJ_FILES)
-       @echo "[ creating $(COMPONENT_IMAGE) ]"
-       $(LD)  $(LDFLAGS_COMPONENT) -o $(COMPONENT_IMAGE_FILE) ${LD_COMPONENT_OBJ_FILES};
-       (cd $(TARGET)$(COMP_OBJ_DIR); ${MD} -u Makedep -f -d `ls *.d`);
+# Do-nothing rule, since not all levels of the recursive hierarchy might implement this
+# in their local Makefiles. Those that do will use a "::" rule to augment this.
+do_build_all::
+       @:
 
-setup_build_all: 
-       @echo "[ $(SOURCE) ] make setup_build_all $(KERNEL_CONFIG) $(ARCH_CONFIG) $(TARGET)"
+.PHONY: do_build_install_primary
 
-do_build_all: $(COMP_FILES) $(COMP_COBJ_FILES) $(COMP_SOBJ_FILES) $(COMPONENT_IMAGE_FILE)
-       @true echo "[ $(SOURCE) ] make do_build_all $(KERNEL_CONFIG) $(ARCH_CONFIG) $(TARGET)"
+# Do-nothing rule, since not all levels of the recursive hierarchy might implement this
+# in their local Makefiles. Those that do will use a "::" rule to augment this.
+do_build_install_primary::
+       @:
 
-ifeq ($(COMPONENT), .)
-do_build_all: do_build_mach_kernel
-endif
+.PHONY: do_build_install_non_primary
 
-#
-# mach_kernel building rules
-#
-do_build_mach_kernel: $(OBJROOT)/$(KERNEL_CONFIG)_$(ARCH_CONFIG)/kgmacros
-       @echo "[ building mach_kernel ]";
-       @install $(DATA_INSTALL_FLAGS) $(SRCROOT)/config/version.c $(OBJROOT)/$(KERNEL_CONFIG)_$(ARCH_CONFIG)/version.c;
-       @$(SRCROOT)/config/newvers.pl $(OBJROOT)/$(KERNEL_CONFIG)_$(ARCH_CONFIG)/version.c;
-       ${KCC} -c ${filter-out ${${join $@,_CFLAGS_RM}}, ${CFLAGS}} ${${join $@,_CFLAGS_ADD}} ${INCFLAGS} ${${join $@,_INCFLAGS}} $(OBJROOT)/$(KERNEL_CONFIG)_$(ARCH_CONFIG)/version.c -o $(OBJROOT)/$(KERNEL_CONFIG)_$(ARCH_CONFIG)/version.o
-       $(LD) $(LDFLAGS_KERNEL) $(addprefix $(TARGET)/,$(foreach component,$(COMPONENT_LIST), $(addprefix $(component)/$(firstword $($(addsuffix _KERNEL_CONFIG, $(shell echo -n $(component) | tr a-z A-Z))) $(KERNEL_CONFIG))/, $(addsuffix .o, $(component))))) $(OBJROOT)/$(KERNEL_CONFIG)_$(ARCH_CONFIG)/version.o -o $(TARGET)/mach_kernel.sys $(LD_KERNEL_LIBS); \
-       $(STRIP) $(STRIP_FLAGS) $(TARGET)/mach_kernel.sys -o $(TARGET)/mach_kernel;
+# Do-nothing rule, since not all levels of the recursive hierarchy might implement this
+# in their local Makefiles. Those that do will use a "::" rule to augment this.
+do_build_install_non_primary::
+       @:
 
-$(OBJROOT)/$(KERNEL_CONFIG)_$(ARCH_CONFIG)/kgmacros: $(SRCROOT)/kgmacros
-       cp $? $@
+INSTALL_MAN_FILES = $(addprefix $(DSTROOT)/$(MANDIR)/$(INSTALL_MAN_DIR)/, $(INSTALL_MAN_LIST))
 
-#
-# Generic Install rules
-#
-INSTALL_FILE_FILES = $(addprefix $(DSTROOT)$(INSTALL_FILE_DIR), $(INSTALL_FILE_LIST))
-
-force_file_install:
-
-$(INSTALL_FILE_FILES): $(DSTROOT)$(INSTALL_FILE_DIR)% : $(TARGET)/% force_file_install
-       @echo Installing $< in $@;
-       @if [ ! -e $(DSTROOT)$(INSTALL_FILE_DIR) ]; then        \
-               $(MKDIR) $(DSTROOT)$(INSTALL_FILE_DIR);         \
-       fi;                                                     \
-       if [ "`echo $(INSTALL_ARCHS_LC) | wc -w`" -eq 1 ]; then \
-               $(RM) $(RMFLAGS) $@;                            \
-               install $(FILE_INSTALL_FLAGS) $< $(dir $@);             \
-       else                                                    \
-               if [ ! -e $@ ]; then                            \
-                       echo >empty_file_$(notdir $@);                  \
-                       lipo_arg="$(subst _empty_file, empty_file_$(notdir $@),$(foreach lipo_arch,$(INSTALL_ARCHS_LC), $(addprefix -arch , $(addsuffix _empty_file, $(lipo_arch)))))"; \
-                       $(LIPO) $${lipo_arg} -create -output $@;        \
-                       $(RM) $(RMFLAGS) empty_file_$(notdir $@);               \
-               fi;                                                     \
-               $(LIPO) $@ -replace $(ARCH_CONFIG_LC)  $< -o $@;        \
-       fi
-
-INSTALL_FILESYS_FILES = $(addprefix $(SYMROOT)$(INSTALL_FILE_DIR), $(INSTALL_FILE_LIST))
-
-force_filesys_install:
-
-$(INSTALL_FILESYS_FILES): $(SYMROOT)$(INSTALL_FILE_DIR)% : $(TARGET)/%.sys force_filesys_install
-       @echo Installing $< in $@;
-       @if [ ! -e $(SYMROOT)$(INSTALL_FILE_DIR) ]; then        \
-               $(MKDIR) $(SYMROOT)$(INSTALL_FILE_DIR);         \
-       fi;                                                     \
-       if [ "`echo $(INSTALL_ARCHS_LC) | wc -w`" -eq 1 ]; then \
-               $(RM) $(RMFLAGS) $@;                            \
-               install $(INSTALL_FLAGS) $< $(dir $@);          \
-       else                                                    \
-               if [ ! -e $@ ]; then                            \
-                       echo >empty_filesys_$(notdir $@);                       \
-                       lipo_arg="$(subst _empty_file, empty_filesys_$(notdir $@),$(foreach lipo_arch,$(INSTALL_ARCHS_LC), $(addprefix -arch , $(addsuffix _empty_file, $(lipo_arch)))))"; \
-                       $(LIPO) $${lipo_arg} -create -output $@;        \
-                       $(RM) $(RMFLAGS) empty_filesys_$(notdir $@);            \
-               fi;                                                     \
-               $(LIPO) $@ -replace $(ARCH_CONFIG_LC)  $< -o $@;        \
-       fi
-       cp $(SOURCE)kgmacros $(SYMROOT)$(INSTALL_FILE_DIR)
-
-INSTALL_DATA_FILES = $(addprefix $(DSTROOT)$(INSTALL_DATA_DIR), $(INSTALL_DATA_LIST))
-
-$(INSTALL_DATA_FILES): $(DSTROOT)$(INSTALL_DATA_DIR)% : $(SOURCE)/%
-       @echo Installing $< in $@;
-       @[ -d $(dir $@) ] ||$(MKDIR) $(dir $@);         \
-       $(RM) $(RMFLAGS) $@;            \
-       install $(DATA_INSTALL_FLAGS) $< $(dir $@);
-
-setup_build_install:
-       @echo "[ $(SOURCE) ] make setup_build_install $(KERNEL_CONFIG) $(ARCH_CONFIG) $(TARGET)"
-
-do_build_install: $(INSTALL_FILESYS_FILES) $(INSTALL_FILE_FILES) $(INSTALL_DATA_FILES)
-       @echo "[ $(SOURCE) ] make do_build_install $(KERNEL_CONFIG) $(ARCH_CONFIG) $(TARGET)"
+.PHONY: INSTALL_MAN_DIR
 
-INSTALL_MAN_FILES = $(addprefix $(DSTROOT)/$(MANDIR)/$(INSTALL_MAN_DIR)/, $(INSTALL_MAN_LIST))
+INSTALL_MAN_DIR:
+       $(_v)$(MKDIR) $(DSTROOT)/$(MANDIR)/$(INSTALL_MAN_DIR)
 
-do_installman: $(INSTALL_MAN_FILES)
-       @echo "[ $(SOURCE) ] make do_installman"
-       @if [ -n "$(strip $(INSTALL_MAN_LIST))" ]; then \
-               man_dir=$(DSTROOT)/$(MANDIR)/$(INSTALL_MAN_DIR); \
-               if [ -d $$man_dir ]; then       \
-                       cur_dir=`pwd`;  \
-                       cd $$man_dir;   \
-                       $(RM) $(RMFLAGS) $(INSTALL_MAN_LIST) $(INSTALL_MAN_LINKS); \
-                       cd $$cur_dir;   \
-               else                    \
-                       $(MKDIR) $$man_dir;     \
-               fi;                             \
-               echo Installing $(INSTALL_MAN_LIST) in $$man_dir;       \
-               install $(INSTALL_FLAGS) $(INSTALL_MAN_LIST) $$man_dir; \
-               if [ -n "$(strip $(INSTALL_MAN_LINKS))" ]; then \
-                       set `echo ${INSTALL_MAN_LINKS}`; \
-                       while : ; do \
-                               case $$# in \
-                                       0) break;; \
-                                       1) echo "warn: empty INSTALL_MAN_LINKS: $$1"; break;; \
-                               esac; \
-                               link_src=$$1; shift; link_dst=$$1; shift; \
-                               echo "hard linking $${link_src} to $${link_dst}"; \
-                               ln -f $${man_dir}/$${link_src} $${man_dir}/$${link_dst} ; \
-                       done; \
-               fi; \
-       fi
-
-$(INSTALL_MAN_FILES): $(DSTROOT)/$(MANDIR)/$(INSTALL_MAN_DIR)/% : %
-       @true echo Installing $< in $(dir $@);                  \
-       $(MKDIR) $(DSTROOT)/$(MANDIR)/$(INSTALL_MAN_DIR);       \
-       $(RM) $(RMFLAGS) $@;                                    \
-       install $(INSTALL_FLAGS) $< $(dir $@);
-
-ifeq    ($(INCL_MAKEDEP), TRUE)
--include Makedep
-endif
+$(INSTALL_MAN_FILES): $(DSTROOT)/$(MANDIR)/$(INSTALL_MAN_DIR)/% : % | INSTALL_MAN_DIR
+       @echo "$(ColorH)MAN$(Color0)        $(ColorF)$*$(Color0)"
+       $(_v)$(INSTALL) $(INSTALL_FLAGS) $< $@
+
+define MAN_LINKS_RULE_template
+$$(DSTROOT)/$$(MANDIR)/$$(INSTALL_MAN_DIR)/$(2): $$(DSTROOT)/$$(MANDIR)/$$(INSTALL_MAN_DIR)/$(1)
+       @echo "$$(ColorH)MANLINK$$(Color0)    $$(ColorF)$(2)$$(Color0)"
+       $(_v)ln -f $$< $$@
+endef
+
+function_generate_man_links_rules = $(if $(word 1,$(1)),$(eval $(call MAN_LINKS_RULE_template,$(word 1,$(1)),$(word 2,$(1)))) $(DSTROOT)/$(MANDIR)/$(INSTALL_MAN_DIR)/$(word 2,$(1)) $(call function_generate_man_links_rules,$(wordlist 3,$(words $(1)),$(1))))
+
+INSTALL_MAN_FILES_LINKS = $(call function_generate_man_links_rules,$(INSTALL_MAN_LINKS))
+
+.PHONY: do_installman
+
+do_installman: $(INSTALL_MAN_FILES) $(INSTALL_MAN_FILES_LINKS)
+       @:
+
+.PHONY: do_textfiles_install
+
+# Do-nothing rule, since not all levels of the recursive hierarchy might implement this
+# in their local Makefiles. Those that do will use a "::" rule to augment this.
+do_textfiles_install:: do_installman
+       @:
+
+.PHONY: do_build_setup
+
+# Do-nothing rule, since not all levels of the recursive hierarchy might implement this
+# in their local Makefiles. Those that do will use a "::" rule to augment this.
+do_build_setup::
+       @:
+
+.PHONY: do_config_all
+
+# Do-nothing rule, since not all levels of the recursive hierarchy might implement this
+# in their local Makefiles. Those that do will use a "::" rule to augment this.
+do_config_all::
+       @:
+
+.PHONY: do_config_install
+
+# Do-nothing rule, since not all levels of the recursive hierarchy might implement this
+# in their local Makefiles. Those that do will use a "::" rule to augment this.
+do_config_install::
+       @:
 
+# vim: set ft=make: