help-make
[Top][All Lists]
Advanced

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

Re: problem with updating a static library using make/makefiles


From: Noel Yap
Subject: Re: problem with updating a static library using make/makefiles
Date: Wed, 10 Dec 2003 09:16:45 -0500

I'm CC'ing make-help since others may have other comments or suggestions about 
this.

Thomas Lavergne wrote:
> 
> Hi Noel,
> I come back to you. I tried to have a non-recursive makefile for
> building a static library (using ar on all my .o). It is working fine
> when starting from scratch (after a make clean statement) But, I also
> tried to add a basic auto-dependencies management script: For each .c
> file, a .P is created containing the dependencies:
> for example in brdpp.P

I'm not sure where it originated, but I see .d as the most common suffix for 
these.  Unless you're using .P for any particular reason, you may want to 
conform to, IME, the de facto standard.  That said, I'll stick to your naming 
convention for the rest of
the reply.

> --------------------------------------
> bdrpp.o bdrpp.P:  libfray/libmeasure/bdrpp.c libfray/libcommon/common.h
> config.h \
>   libfray/libcommon/expr.h libfray/libcommon/vector.h \
>   libfray/libcommon/ray.h libfray/libcommon/transform.h \
>   libfray/libcommon/error.h libfray/libcommon/rng.h \
>   libfray/libcommon/verbose.h libfray/libcommon/path.h \
>   libfray/libsource/source.h libfray/libsource/origin.h \
>   libfray/libdistr/distribution.h libfray/libdistr/density.h \
>   libfray/libcommon/tag.h libfray/libobj/geom.h libfray/libobj/bounds.h \
>   libfray/libcommon/context.h libfray/libmeasure/measure.h \
>   libfray/libfilter/filter.h libfray/libmeasure/bdrpp.h

If you take a look at http://make.paulandlesley.org/autodep.html.  The gist is 
that, rather than having a dependency rule for .P, just have the .o rule 
generate the .P.  The benefits are:
1. one reparse of the makefiles is avoided
2. many C and C++ compilers can generate the .P and the .o in one command

> ---------------------------------------
> You can see that every .o is linked to a corresponding .P. These .P
> makefiles are included in my main makefile with make's include rule.

That's correct.

> ---------------------------------------
> #include the C include dependencies
> include $(SRC:.c=.P)

You should be using -include to avoid misleading output about non-existent .P's.

> ----------------------------------------
> Everything is fine if I modify a .c file. But, it does not do anything
> if I modify a .h file, because the implicit rule for creating a .P rely
> only on .c which are unchanged.

I'm not sure why you're experiencing this since the generated dependency rule 
clearly states that the .P is also dependent on some .h's.

> --------------------------------------------
> #calculate the C include dependencies
> %.P: %.c
>     $(MAKEDEPEND) $*.c | sed -e 's/\(.*\)\.o[ :]/\1\.o \1\.P: /g' > $@

It should use the autogenerated dependency rule for the .P as well.  I've seen 
some unexpected behaviour with regards to the order in which rules are seen.  
Maybe that's what you're running into?

> ----------------------------------------------
> 
> I do not see what is missing. I am not totally confident in the order
> following which I wrote all these rules. Do you have a quick clue of
> what is happening?

Try reading the "Advanced Auto-Dependency Generation" article.  It'll clean up 
your makefile some (by getting rid of the .P rule.

Oh, I just noticed that the generated dependency rule looks incorrect.  I think 
it should be:

libfray/libmeasure/bdrpp.o libfray/libmeasure/bdrpp.P:  
libfray/libmeasure/bdrpp.c libfray/libcommon/common.h
config.h \
  libfray/libcommon/expr.h libfray/libcommon/vector.h \
  libfray/libcommon/ray.h libfray/libcommon/transform.h \
  libfray/libcommon/error.h libfray/libcommon/rng.h \
  libfray/libcommon/verbose.h libfray/libcommon/path.h \
  libfray/libsource/source.h libfray/libsource/origin.h \
  libfray/libdistr/distribution.h libfray/libdistr/density.h \
  libfray/libcommon/tag.h libfray/libobj/geom.h libfray/libobj/bounds.h \
  libfray/libcommon/context.h libfray/libmeasure/measure.h \
  libfray/libfilter/filter.h libfray/libmeasure/bdrpp.h


Note the paths for the .o and .P files.

HTH,
Noel

> thanks
> thomas
> 
> PS: I include now my whole Makefile. the SRC variable is updated in each
> module.mk $(MKINCLUDE) makefile
> ===============================================
> #
> # Makefile
> # T. Lavergne 12/2003
> #
> 
> MODULES_FRAY = libcommon libdistr libfilter libintera libmeasure libobj
> libsource
> CINCLUDE0 = -I.
> CINCLUDE1 = -I./libfray
> MKINCLUDE = ./libfray/libcommon/libcommon.mk
> ./libfray/libdistr/libdistr.mk  ./libfray/libfilter/libfilter.mk
> ./libfray/libintera/libintera.mk  ./libfray/libmeasure/libmeasure.mk
> ./libfray/libobj/libobj.mk  ./libfray/libsource/libsource.mk
> 
> OPTIMIZE = -O2
> CCFLAGS =
> ARFLAGS=curSv
> RANLIB = /usr/bin/ranlib
> CC = /usr/bin/gcc
> MAKEDEPEND = /home1/laverth/RAYTRAN/DEV/rayspread/mkdep_l
> 
> LIBFRAY = ./libfray/libfray.a
> CFLAGS = $(CCFLAGS) $(CINCLUDE0) $(CINCLUDE1) $(OPTIMIZE)
> SHELL = /bin/sh
> 
> #each module will add sources to this variable
> SRC :=
> 
> #include the .mk files located in each module
> include $(MKINCLUDE)
> 
> OBJ := $(SRC:.c=.o)
> 
> $(LIBFRAY): $(OBJ)
>     ar $(ARFLAGS) $(LIBFRAY) $(OBJ)
>     $(RANLIB) $(LIBFRAY)
> 
> #calculate the C include dependencies
> %.P: %.c
>     $(MAKEDEPEND) $*.c | sed -e 's/\(.*\)\.o[ :]/\1\.o \1\.P: /g' > $@
> 
> #include the C include dependencies
> include $(SRC:.c=.P)
> 
> clean :
>     rm -f `find . -name *.o`
> ==========================================
> mkdep_l is :
> ==========================================
> #!/bin/sh
> /usr/bin/cpp -I. -I./libfray -MM $1

-- 
NOTICE: If received in error, please destroy and notify sender.  Sender does 
not waive confidentiality or privilege, and use is prohibited.




reply via email to

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