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) > $(OUT_LIB_DIR)/$(OUT_LIB): $(SRCS) > $(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: http://make.paulandlesley.org/autodep.html 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. _______________________________________________ Help-make mailing list [email protected] http://lists.gnu.org/mailman/listinfo/help-make
