LKML Archive on
help / color / mirror / Atom feed
From: "Pelle Svensson" <>
Cc: "Sam Ravnborg" <>
Subject: Skeleton, Makefile extension - Separate source tree with only valid source files
Date: Mon, 15 Jan 2007 10:35:25 +0100	[thread overview]
Message-ID: <> (raw)

Did some hacks to the Makefile which might be of interest for those who
feel like there are too many source files in the Linux tree. Running following
make will create a separate directory including only the files which are
active i.e. they are include in the final build configuration.

source = /home/john/src/linux-2.6.20
build_dir = /home/john/src/linux-2.6.20-build
edit_dir = /home/john/src/linux-2.6.20-edit

cd $(source)
make O=$(build_dir) ACTIVE_SRC=$(edit_dir) active_srctree

Links will be create in $(edit_dir) and what ever IDE that are in use for
editing should target the $(edit_dir). The good thing is that grep will only
hit valid files not 50 other files which are not in my interest.

Due to lack of time this is not complete. Phrasing the dependency need to
be added for all the include files.

Part added to root Makefile

# Generate source tree with only active files based on the configuration
# ---------------------------------------------------------------------------

ifneq ($(ACTIVE_SRCTREE),)
edittree	:= $(ACTIVE_SRCTREE)
edittree-alldir	:= $(subst usr,,$(vmlinux-alldirs))
edittree-alldir	:= $(addprefix $(edittree)/, $(edittree-alldir) )

PHONY += active_srctree validate_active_srctree $(edittree-alldir)

	$(if $(ACTIVE_SRCTREE),, $(error Must define ACTIVE_SRCTREE=...))
	$(Q) $(MAKE) -f $(srctree)/scripts/Makefile.srctree
edittree=$(edittree) srctree=$(srctree) dst=$@

active_srctree: validate_active_srctree $(edittree-alldir)

New file created scripts/Makefile.srctree

# ==========================================================================
# Building a source tree consisting of links into main source.
# Links are only created for files currently in use by the configuration
# ==========================================================================

#src := $(src)
sdir := $(subst $(edittree)/,,$(dst))
sdir := $(subst %/,%,$(sdir))

PHONY := link

# Read .config if it exist, otherwise ignore
-include include/config/auto.conf

include $(srctree)/scripts/Kbuild.include

include $(srctree)/$(sdir)/Makefile

__subdir-y	:= $(patsubst %/,%,$(filter %/, $(obj-y)))
subdir-y	+= $(__subdir-y)
__subdir-m	:= $(patsubst %/,%,$(filter %/, $(obj-m)))
subdir-m	+= $(__subdir-m)

subdir-ym	:= $(sort $(subdir-y) $(subdir-m))
subdir-ym	:= $(addprefix $(sdir)/, $(subdir-ym))

obj-y		:= $(filter-out %/, $(obj-y))
obj-m		:= $(filter-out %/, $(obj-m))

obj-names := $(patsubst %.o,%,$(obj-y) $(obj-m) $(head-y))
obj-names := $(filter-out /% , $(obj-names))
src-files := $(addprefix $(srctree)/$(sdir)/, $(obj-names))
src-files := $(wildcard $(addsuffix .*, $(src-files)))
dst-files := $(subst $(srctree)/,,$(src-files))
dst-files := $(addprefix $(edittree)/, $(dst-files))

link: $(dst-files) $(subdir-ym)

$(dst-files): $(edittree)/%: $(srctree)/%
	$(Q) mkdir -p $(@D)
	$(Q) if test -f $@; then touch $@; else cp -l $< $@; fi

# Descending
# ---------------------------------------------------------------------------

PHONY += $(subdir-ym)
	$(Q) $(MAKE) -f $(srctree)/scripts/Makefile.srctree
edittree=$(edittree) srctree=$(srctree) dst=$@

# ---------------------------------------------------------------------------


# ---------------------------------------------------------------------------

             reply	other threads:[~2007-01-15  9:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-01-15  9:35 Pelle Svensson [this message]
2007-01-15 12:43 ` Chris Smith

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \
    --subject='Re: Skeleton, Makefile extension - Separate source tree with only valid source files' \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).