Re: Build system


Subject: Re: Build system
From: Jesper Skov (jskov@redhat.com)
Date: Sun Jun 18 2000 - 04:18:35 CDT


>>>>> "Aaron" == Aaron Lehmann <aaronl@vitelus.com> writes:

Aaron> Building makefiles for you IS one of the things that autoconf
Aaron> does. According to my experimentation last night, when gcc is
Aaron> told to build dependencies, it IGNORES the pathname to the
Aaron> object file. So, running "g++ -Wp,-MMD,.deps/.ap_Ruler.pp -o
Aaron> ../../../myplatform/objs/ap_Ruler.o -c ap_Ruler.cpp" will
Aaron> produce a makefile rule for ap_Ruler.o. NOT
Aaron> ../../../myplatform/objs/ap_Ruler.o. And even if I edit this by
Aaron> hand to be the path to it, make seems to be ignoring the rule.

This is one of the make rules used in eCos. We also use different
build and source directories. Basically, this makes the .deps file but
replaces the target inserted by GCC by the target which is known to be
right by the build system.

$(PREFIX)/lib/vectors.o : $(PACKAGE)/src/vectors.S
        $(CC) -Wp,-MD,vectors.tmp $(INCLUDE_PATH) $(CFLAGS) -c -o $@ $<
        @echo $@ ": \\" > $(notdir $@).deps
        @tail +2 vectors.tmp >> $(notdir $@).deps
        @echo >> $(notdir $@).deps
        @rm vectors.tmp

These are the generic rules:

# pattern matching rules to generate a library object from source code
# object filenames are prefixed to avoid name clashes
# a single dependency rule is generated (file extension = ".o.d")
%.o.d : %.c
        @mkdir -p $(dir $@)
        $(CC) -c $(INCLUDE_PATH) -I$(dir $<) $(CFLAGS) -Wp,-MD,$(@:.o.d=.tmp) -o $(dir $@)$(OBJECT_PREFIX)_$(notdir $(@:.o.d=.o)) $<
        @echo $@ ':' $< '\' > $@
        @tail +2 $(@:.o.d=.tmp) >> $@
        @echo >> $@
        @rm $(@:.o.d=.tmp)

%.o.d : %.cxx
        @mkdir -p $(dir $@)
        $(CC) -c $(INCLUDE_PATH) -I$(dir $<) $(CFLAGS) -Wp,-MD,$(@:.o.d=.tmp) -o $(dir $@)$(OBJECT_PREFIX)_$(notdir $(@:.o.d=.o)) $<
        @echo $@ ':' $< '\' > $@
        @tail +2 $(@:.o.d=.tmp) >> $@
        @echo >> $@
        @rm $(@:.o.d=.tmp)

The default build rules are for libtarget.a.stamp, and there are these
rules to control the object/dependency usage:

LIBRARY := libtarget.a
COMPILE := src/generic-stub.c src/thread-packets.c src/hal_stub.c src/drv_api.c
src/dbg-threads-syscall.c src/hal_if.c src/hal_misc.c
OBJECTS := $(COMPILE:.cxx=.o.d)
OBJECTS := $(OBJECTS:.c=.o.d)
OBJECTS := $(OBJECTS:.S=.o.d)

$(LIBRARY).stamp: $(OBJECTS)
        $(AR) rcs $(PREFIX)/lib/$(@:.stamp=) $(foreach obj,$?,$(dir $(obj))$(OBJECT_PREFIX)_$(notdir $(obj:.o.d=.o)))
        @cat $^ > $(@:.stamp=.deps)
        @touch $@

As I understand it, the makefile controls building of the .d
files. The .o files are "just" a side effect of this process.

There may be more to it than this - I'm don't know enough of the
details to say. And there are a few caveats; for instance, to force a
.o file to rebuild, you must delete the .o.d file - not the .o file
itself as customary.

Anyway, this is just meant as inspiration. If you can get it to work,
and figure out how to allow deleting .o files to cause them to be
rebuilt, I'll be sure to bring those changes into the eCos build files ;)

Cheers,
Jesper



This archive was generated by hypermail 2b25 : Sun Jun 18 2000 - 04:18:41 CDT