2007-01-15 09:35:27

by Pelle Svensson

[permalink] [raw]
Subject: Skeleton, Makefile extension - Separate source tree with only valid source files

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)

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


2007-01-15 12:43:57

by Chris Smith

[permalink] [raw]
Subject: Re: Skeleton, Makefile extension - Separate source tree with only valid source files

On 1/15/07, Pelle Svensson <[email protected]> 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