[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [UNIKRAFT PATCH RFC 3/5] build: Integrate fixdep in Unikraft build system



Now the tool will be called for every compiled file, modifying the
dependency file. It does 2 things:
1) removes _config.h so no full rebuilds anymore if configuration is
   changed
2) scans the source file for CONFIG_, and adds dependency to
   corresponding depinclude file

Signed-off-by: Yuri Volchkov <yuri.volchkov@xxxxxxxxx>
---
 Makefile                     |  9 +++++++--
 support/build/Makefile.rules | 22 +++++++++++++++-------
 support/kconfig/Makefile     |  2 ++
 support/kconfig/fixdep.c     | 21 +++++++++++++--------
 4 files changed, 37 insertions(+), 17 deletions(-)

diff --git a/Makefile b/Makefile
index b177bff..84484f1 100644
--- a/Makefile
+++ b/Makefile
@@ -116,6 +116,7 @@ UK_CONFIG             := $(CONFIG_DIR)/.config
 UK_CONFIG_OUT         := $(BUILD_DIR)/config
 UK_GENERATED_INCLUDES := $(BUILD_DIR)/include
 KCONFIG_DIR           := $(BUILD_DIR)/kconfig
+UK_FIXDEP             := $(KCONFIG_DIR)/fixdep
 KCONFIG_AUTOCONFIG    := $(KCONFIG_DIR)/auto.conf
 KCONFIG_TRISTATE      := $(KCONFIG_DIR)/tristate.config
 KCONFIG_AUTOHEADER    := $(UK_GENERATED_INCLUDES)/uk/_config.h
@@ -478,7 +479,8 @@ $(UK_CONFIG_OUT): $(UK_CONFIG)
                $(UK_CONFIG) \
                $(UK_CONFIG_OUT))
 
-prepare: $(KCONFIG_AUTOHEADER) $(UK_CONFIG_OUT) $(UK_PREPARE) $(UK_PREPARE-y) 
| fetch
+prepare: $(KCONFIG_AUTOHEADER) $(UK_CONFIG_OUT) $(UK_PREPARE) $(UK_PREPARE-y)
+prepare: $(UK_FIXDEP) | fetch
 
 objs: $(UK_OBJS) $(UK_OBJS-y)
 
@@ -562,7 +564,10 @@ $(KCONFIG_ELIB_IN).new:
 # enforce execution
 .PHONY: $(KCONFIG_APP_IN).new $(KCONFIG_ELIB_IN).new
 
-$(KCONFIG_DIR)/%onf:
+KCONFIG_TOOLS = conf mconf gconf nconf fixdep
+KCONFIG_TOOLS := $(addprefix $(KCONFIG_DIR)/,$(KCONFIG_TOOLS))
+
+$(KCONFIG_TOOLS):
        mkdir -p $(@D)/lxdialog
        $(MAKE) CC="$(HOSTCC_NOCCACHE)" HOSTCC="$(HOSTCC_NOCCACHE)" \
            obj=$(@D) -C $(CONFIG) -f Makefile.br $(@F)
diff --git a/support/build/Makefile.rules b/support/build/Makefile.rules
index feb1455..1f73fc6 100644
--- a/support/build/Makefile.rules
+++ b/support/build/Makefile.rules
@@ -287,16 +287,24 @@ endef
 # Adds library-specific (AS/C/CXX)FLAGS to the build
 #
 # buildrule_* $libname,$source,$target,$extraflags(optional)
+tmp_depfile = $(dir $1).$(notdir $1).d
+depflags = -Wp$(comma)-MD$(comma)$(call tmp_depfile,$(3))
+define fixdep_and_cmd =
+       $(call build_cmd,$1,$2,$3,$4)
+       $Q $(UK_FIXDEP) $(call tmp_depfile,$3) $3 '$(call strip,$4)' \
+               $(BUILD_DIR)    > $(call obj2dep,$3) && \
+               rm -f $(call tmp_depfile,$3)
+endef
 
 define buildrule_S =
 $(3): $(2) | prepare
-       $(call build_cmd,AS,$(1),$(3),\
+       $(call fixdep_and_cmd,AS,$(1),$(3),\
                $(AS)  $(ASINCLUDES) $(ASINCLUDES-y) \
                       $($(call vprefix_lib,$(1),ASINCLUDES)) $($(call 
vprefix_lib,$(1),ASINCLUDES-y)) \
                       $(ASFLAGS) $(ASFLAGS-y) \
                       $($(call vprefix_lib,$(1),ASFLAGS)) $($(call 
vprefix_lib,$(1),ASFLAGS-y)) \
                       $(4) -D__LIBNAME__=$(1) -D__BASENAME__=$(notdir $(2)) \
-                      -c $(2) -o $(3) -MD
+                      -c $(2) -o $(3) $(depflags)
        )
 
 UK_SRCS-y += $(2)
@@ -308,14 +316,14 @@ endef
 
 define buildrule_c =
 $(3): $(2) | prepare
-       $(call build_cmd,CC,$(1),$(3),\
+       $(call fixdep_and_cmd,CC,$(1),$(3),\
                $(CC)  $(CINCLUDES) $(CINCLUDES-y) \
                       $($(call vprefix_lib,$(1),CINCLUDES)) $($(call 
vprefix_lib,$(1),CINCLUDES-y)) \
                       $(CFLAGS) $(CFLAGS-y) \
                       $($(call vprefix_lib,$(1),CFLAGS)) $($(call 
vprefix_lib,$(1),CFLAGS-y)) \
                       $(4) -D__LIBNAME__=$(1) -D__BASENAME__=$(notdir $(2)) \
-                      -c $(2) -o $(3) -MD
-       )
+                      -c $(2) -o $(3) $(depflags)
+)
 
 UK_SRCS-y += $(2)
 UK_DEPS-y += $(call obj2dep,$(3))
@@ -326,13 +334,13 @@ endef
 
 define buildrule_cc =
 $(3): $(2) | prepare
-       $(call build_cmd,CXX,$(1),$(3),\
+       $(call fixdep_and_cmd,CXX,$(1),$(3),\
                $(CXX) $(CXXINCLUDES) $(CXXINCLUDES-y) \
                       $($(call vprefix_lib,$(1),CXXINCLUDES)) $($(call 
vprefix_lib,$(1),CXXINCLUDES-y)) \
                       $(CXXFLAGS) $(CXXFLAGS-y) \
                       $($(call vprefix_lib,$(1),CXXFLAGS)) $($(call 
vprefix_lib,$(1),CXXFLAGS-y)) \
                       $(4) -D__LIBNAME__=$(1) -D__BASENAME__=$(notdir $(2)) \
-                      -c $(2) -o $(3) -MD
+                      -c $(2) -o $(3) $(depflags)
        )
 
 UK_SRCS-y += $(2)
diff --git a/support/kconfig/Makefile b/support/kconfig/Makefile
index 7eb4071..6d5b611 100644
--- a/support/kconfig/Makefile
+++ b/support/kconfig/Makefile
@@ -156,8 +156,10 @@ kxgettext-objs     := kxgettext.o zconf.tab.o
 qconf-cxxobjs  := qconf.o
 qconf-objs     := zconf.tab.o
 gconf-objs     := gconf.o zconf.tab.o
+fixdep-obj     := fixdep.o
 
 hostprogs-y := conf
+hostprogs-y += fixdep
 
 ifeq ($(MAKECMDGOALS),nconf)
        hostprogs-y += nconf
diff --git a/support/kconfig/fixdep.c b/support/kconfig/fixdep.c
index e8ae044..6f13336 100644
--- a/support/kconfig/fixdep.c
+++ b/support/kconfig/fixdep.c
@@ -107,9 +107,15 @@
 #include <stdio.h>
 #include <ctype.h>
 
+/* The global variable is a bit against the style of fixdep. But this
+ * reduces number of changed lines significantly. Which hopefully will
+ * make it easier to merge with newer version from linux source tree.
+ */
+static const char *builddir;
+
 static void usage(void)
 {
-       fprintf(stderr, "Usage: fixdep [-e] <depfile> <target> <cmdline>\n");
+       fprintf(stderr, "Usage: fixdep [-e] <depfile> <target> <cmdline> 
<builddir>\n");
        fprintf(stderr, " -e  insert extra dependencies given on stdin\n");
        exit(1);
 }
@@ -121,7 +127,7 @@ static void print_dep(const char *m, int slen, const char 
*dir)
 {
        int c, i;
 
-       printf("    $(wildcard %s/", dir);
+       printf("    $(wildcard %s/%s/", builddir, dir);
        for (i = 0; i < slen; i++) {
                c = m[i];
                if (c == '_')
@@ -212,7 +218,7 @@ static void use_config(const char *m, int slen)
            return;
 
        define_config(m, slen, hash);
-       print_dep(m, slen, "include/config");
+       print_dep(m, slen, "kconfig/depinclude");
 }
 
 /* test if s ends in sub */
@@ -285,9 +291,7 @@ static void *read_file(const char *filename)
 /* Ignore certain dependencies */
 static int is_ignored_file(const char *s, int len)
 {
-       return str_ends_with(s, len, "include/generated/autoconf.h") ||
-              str_ends_with(s, len, "include/generated/autoksyms.h") ||
-              str_ends_with(s, len, ".ver");
+       return str_ends_with(s, len, "build/include/uk/_config.h");
 }
 
 /*
@@ -384,15 +388,16 @@ int main(int argc, char *argv[])
        int insert_extra_deps = 0;
        void *buf;
 
-       if (argc == 5 && !strcmp(argv[1], "-e")) {
+       if (argc == 6 && !strcmp(argv[1], "-e")) {
                insert_extra_deps = 1;
                argv++;
-       } else if (argc != 4)
+       } else if (argc != 5)
                usage();
 
        depfile = argv[1];
        target = argv[2];
        cmdline = argv[3];
+       builddir = argv[4];
 
        printf("cmd_%s := %s\n\n", target, cmdline);
 
-- 
2.17.0


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.