LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* Skeleton, Makefile extension - Separate source tree with only valid source files
@ 2007-01-15  9:35 Pelle Svensson
  2007-01-15 12:43 ` Chris Smith
  0 siblings, 1 reply; 2+ messages in thread
From: Pelle Svensson @ 2007-01-15  9:35 UTC (permalink / raw)
  To: linux-kernel; +Cc: Sam Ravnborg

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) )
endif

PHONY += active_srctree validate_active_srctree $(edittree-alldir)

validate_active_srctree:
	$(if $(ACTIVE_SRCTREE),, $(error Must define ACTIVE_SRCTREE=...))
	
$(edittree-alldir):
	$(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
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)
$(subdir-ym):
	$(Q) $(MAKE) -f $(srctree)/scripts/Makefile.srctree
edittree=$(edittree) srctree=$(srctree) dst=$@

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

.PHONY: $(PHONY)

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Skeleton, Makefile extension - Separate source tree with only valid source files
  2007-01-15  9:35 Skeleton, Makefile extension - Separate source tree with only valid source files Pelle Svensson
@ 2007-01-15 12:43 ` Chris Smith
  0 siblings, 0 replies; 2+ messages in thread
From: Chris Smith @ 2007-01-15 12:43 UTC (permalink / raw)
  To: Pelle Svensson; +Cc: linux-kernel, Sam Ravnborg

On 1/15/07, Pelle Svensson <pelle2004@gmail.com> wrote:
> 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.
>
[snip]

Another interesting thought might be to have kbuild run all of the
files through the pre-processor, then indent.
Then one could have a clearer view of the kernel object as actually
seen by the compiler.
Thanks, Pelle.
--Chris

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-01-15 12:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-01-15  9:35 Skeleton, Makefile extension - Separate source tree with only valid source files Pelle Svensson
2007-01-15 12:43 ` Chris Smith

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).