[Top][All Lists]

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

Re: Cant seem to figure how to make header file dependencies

From: Ankur G35 Saxena
Subject: Re: Cant seem to figure how to make header file dependencies
Date: Fri, 23 Jun 2006 09:16:24 -0500

On 6/23/06, Leeuwesteijn,Joost <address@hidden> wrote:
Hi Ankur,

>    I have always been afraid of makefiles

Makefiles are cool :-) The alternative is to type all the compile/link
commands and flags at the command line every time, that's your choice :-)

> I am trying to make a generic makefile, in an effort to
> understand the makefile itself.
> I have written a makefile to make libraries.
> [...]
> INC_CFLAGS= -I/usr/include/mysql++ -I$(TOPDIR)/cncpbaseclass
> -I/usr/include/mysql -I$(TOPDIR)/oammsg
> -I$(TOPDIR)/neoamcomm -I../util_lib -I$(TOPDIR)/util

Makefile looks OK. You could use += to put all the flags on a separate line
to make it more readable. And use := where possible for immediate variable
expansion (see manual).

> #OBJS= $(SRCS:%.cpp=%.o)
> all: $(OUT_LIB_DIR)/$(OUT_LIB)
>         $(COMPILE) $(CFLAGS) -c $?
>         $(MKLIB) $(OUT_LIB_DIR)/$(OUT_LIB) $(OBJS)
>         $(RM) $(OBJS)

Not sure if I would have done it like this; I guess I would still have added
a rule for the .o files. But the $? makes sure only the modified .o's are
rebuilt so this works.

> This seems to work just fine for source file changes. But I
> cant seem to figure out how to add header file dependencies
> to it?
> How can I achieve this?

You really need to add a rule that says which .o files depend on which .h
files. Make will then only compile the .c's that have a modified .h file.
You can still remove all the .o files after the lib is created, but that
wouldn't make much sense because everything will have to be rebuilt at the
next make invocation; the whole purpose of make is to save time and only
rebuild things that need to be rebuilt; reusing already created files.

I would suggest to take a look at Paul's website:
It might look tricky at first and might require some modification depending
on your build environment. I use the (advanced) mechanism as described on
the webpage and it works fine.

Good luck.

Joost Leeuwesteijn

Important Note:

This e-mail message and any attachments are confidential any may be privileged or otherwised protected from disclosure. If you are not the intendent recipient you must not use, copy, disclose or take any action based on this e-mail or any information and attachment contained in the message. If you have received this material in error, please advise the sender immediately by reply e-mail or telephone and delete this message and any attachments from your system.

Thank you.

Thanks Joost, but what if a header file changes and I would like all the code to be redone? Considering I am already breaking down the code into small sub components which have few files per sub component and are seperated in different directories, so if a header file in that directory changes then I want all the .cpp files in that directory to be made.

How do I achieve this? The chances of a header file change are very small and hence all the code would only be compiled less than 10% of the times. I didnt want to add the .o's because i have been able to achieve compiling of only changed cpp's with this makefile as the library archive(.a) depends on the cpp's, so if a cpp changes it compiles only the changed file and adds to the library and removes the .o. So this is working just fine, but i still cant get to make all the cpp files when any of the header files change? Any suggestions?

And thanks for your suggestion on how to make it more readable, I will make the changes you mentioned.


reply via email to

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