help-make
[Top][All Lists]
Advanced

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

how to cheat with makefiles ... looking for feedback (kinda long)


From: Robert P. J. Day
Subject: how to cheat with makefiles ... looking for feedback (kinda long)
Date: Sat, 22 May 2004 08:25:13 -0400 (EDT)

  as a followup to a recent question i asked, i did a little more
poking around and i have a much more specific question.  is there a way 
with gnu make to tell the make process to ignore dependencies for specific 
targets in specific sub-make files?

  as an example, i'm looking at the make process to build/rebuild a 2.4
linux kernel.  in a nutshell, at the top of the kernel source tree, there
are two popular targets:

  $ make zImage                 # recompile kernel only
  $ make zImage.initrd          # kernel + ramdisk image = bootable image

  the first target runs through the source tree and subdirectories,
recompiling what needs to be recompiled and creates a kernel image.
even if everything is up to date, it still takes time to check all the 
dependencies for that target, which is normally fine, but it's that time
i want to avoid wasting.

  it's the second target that interests me -- this not only creates the
kernel image, but bundles it with a provided root filesystem image to 
create a runnable downloadable image.  in my case, i have a fairly stable 
kernel image that's not going to change -- i'm just playing with 
filesystem image.  yet, as you can imagine, every time i run 

  $ make zImage.initrd

there's all that time wasted as the make does all the zImage checking
first, only to find that everything's up to date, before combining that
with the filesystem image (which is the only thing that really needs to 
be done for each build).  so, how can i avoid this?

  first, there's the top-level kernel Makefile, with the "vmlinux" target 
that both of the above eventually depend on:

vmlinux: include/linux/version.h $(CONFIGURATION) init/main.o  \
                init/version.o init/do_mounts.o linuxsubdirs
        $(LD) $(LINKFLAGS) $(HEAD) init/main.o init/version.o \
                init/do_mounts.o \
                --start-group \
                $(CORE_FILES) \
                $(DRIVERS) \
                $(NETWORKS) \
                $(LIBS) \
                ...

so, as a first attempt, i can certainly speed things up by hacking that 
Makefile and removing the dependencies for that rule.  that would make a 
*small* difference in that, while i'm avoiding the dependencies, i'm still 
running the rules, which are doing a totally unnecessary relink to build a 
new kernel image.  so let's look further down the kernel source tree.  
(the other objection to this idea is that i really don't want to modify 
the kernel source tree in any way -- i'd like to control all of this from 
my own top-level makefile.)

  since i'm cross-compiling for the powerpc, here's an excerpt from the 
corresponding Makefile, further down the tree:
=================================================
arch/ppc/Makefile:

  BOOT_TARGETS = zImage zImage.initrd znetboot znetboot.initrd
  ...
  MAKEBOOT = $(MAKE) -C arch/$(ARCH)/boot
  ...
  $(BOOT_TARGETS): vmlinux
        @$(MAKEBOOT) $@
=================================================

  ah, so if i hack *this* Makefile, i could just remove the entire
"vmlinux" dependency from the $(BOOT-TARGETS) rule.  even faster.  but
let's keep going and follow that $(MAKEBOOT) command:

=================================================
arch/ppc/boot/Makefile:

  images/vmlinux.gz: $(TOPDIR)/vmlinux
        $(MAKE) -C images vmlinux.gz
=================================================

  argh.  ok, remove the dependency on *that* rule, since i'm assuming that
"vmlinuz", the basis for the new kernel, is just fine.

  cut to the chase, if i follow the build process far enough, i get to the
makefile, with the critical targets (sorry this has taken so long):

=================================================
arch/ppc/boot/simple/Makefile:

zvmlinux: $(obj-y) $(LIBS) ../ld.script ../images/vmlinux.gz ../common/dummy.o
        $(OBJCOPY) $(OBJCOPY_ARGS) \
        ...

zvmlinux.initrd: $(obj-y) $(LIBS) ../ld.script ../images/vmlinux.gz 
../common/dummy.o
        $(OBJCOPY) $(OBJCOPY_ARGS) \
        ...
=================================================

  FINALLY!  and these are the rules i care about.  first, it would be good 
to *totally* override the "zvmlinux:" rule, since all it does is rebuild a 
kernel image, but i'm going to assume that the kernel image is fine, so 
*nothing* has to be done by that rule.

  and i want to delete the dependencies on the "zvmlinux.initrd:" rule, 
and just run the commands, since they combine an existing kernel image 
with my constantly-changing filesystem image.  and that's exactly what i 
want and no more.

  so, how does one do this?  to get what i want, i need to be able to 
override rules at several places in the source tree, in some places just 
ignoring the dependencies, in other places blowing off the rule 
completely.  and i want to be able to do this without hacking the source
tree in any way, controlling it all from my top makefile.

  thoughts?  if there's a one-line solution to this, i'm going to be 
embarrassed.

rday




reply via email to

[Prev in Thread] Current Thread [Next in Thread]