On Monday 25 July 2005 20:31, Ted Stern wrote:
> Try pattern rules instead, they're more flexible.  For example,
>
>     $(objdir)/%.o: $(srcdir)/%.cpp
>          command to build .o file
>
>     $(DEPSDIR)/%.moc: $(srcdir)/%.h
>          moc -o $@ $<

Perfect! Thanks.

On Monday 25 July 2005 20:38, Paul D. Smith wrote:
>   al> 2. I have, in the past seen some magic to include all the
> .deps al>    files in a simple rule, rather than
>
>   al> include  ./$(DEPSDIR)/foo.Plo
>   al> include  ./$(DEPSDIR)/bar.Plo
>   al> include  ./$(DEPSDIR)/baz.Plo
>
>   al> but I can't for the life of me either remember what it is or
> find al> it through google.
>
> There is a description of a "traditional" way to do this in the GNU
> make manual.  There is a description of a more advanced way to do
> it, based on the methods used in automake, on my website (see
> below).

Thanks, Paul. Got it.

OK, gentlemen, the only remaining problem with the attached makefile 
is that it fails if the .deps directory doesn't exist.

if g++ -MT documentPageCache.o -MD -MP -MF 
".deps/documentPageCache.Tpo" -c -o 
documentPageCache.o ../documentPageCache.cpp; \
then mv -f ".deps/documentPageCache.Tpo" 
".deps/documentPageCache.Plo"; else rm-f 
".deps/documentPageCache.Tpo"; exit 1; fi
../documentPageCache.cpp:350: fatal error: opening dependency 
file .deps/documentPageCache.Tpo: No such file or directory

Clearly, I can create a rule

mkdepsdir
        test -d $(depsdir) || mkdir $(depsdir)

$(objdir)/%.o: $(srcdir)/%.cpp $(MOCS) mkdepsdir

Indeed, it works. However, is it the "recognized" way to do this? I 
don't see anything equivalent in an automake generated makefile 
(although it does store dependencies in .deps).

Regards,
Angus



srcdir = ..
objdir = .
depsdir=.deps
AR = ar cru
RANLIB = ranlib
RM = rm -f
RMDIR = rm -rf
MOC = /usr/lib/qt-3.3/bin/moc
QTDIR = /usr/lib/qt-3.3/include
INCLUDES = -I. -I$(srcdir) -I$(srcdir)/../kde -I$(QTDIR)
CXX = g++
CXXFLAGS = $(INCLUDES) -DHAVE_CONFIG_H -DQT_THREAD_SUPPORT -D_REENTRANT -D_XOPEN_SOURCE=500 -D_BSD_SOURCE -DQT_CLEAN_NAMESPACE -DQT_NO_ASCII_CAST -DQT_NO_STL -DQT_NO_COMPAT -DQT_NO_TRANSLATION -Wnon-virtual-dtor -Wno-long-long -Wundef -Wcast-align -Wconversion -Wchar-subscripts -Wall -W -Wpointer-arith -Wno-non-virtual-dtor -Wformat-security -Wmissing-format-attribute -fno-exceptions -fno-check-new -fno-common -ansi -O2
CXXCOMPILE = $(CXX) $(CXXFLAGS)

MOCSRCS = documentPageCache.h \
    documentWidget.h \
    history.h \
    kmultipage.h \
    marklist.h \
    pageSize.h \
    pageView.h \
    renderedDocumentPage.h \
    renderedDocumentPagePixmap.h \
    searchWidget.h \
    tableOfContents.h

SRCS = documentPageCache.cpp \
    documentWidget.cpp \
    history.cpp \
    kmultipage.cpp \
    kprintDialogPage_pageoptions.cpp \
    kvsprefs.cpp \
    marklist.cpp \
    pageSize.cpp \
    pageView.cpp \
    renderedDocumentPage.cpp \
    renderedDocumentPagePixmap.cpp \
    renderedDocumentPagePrinter.cpp \
    searchWidget.cpp \
    selection.cpp \
    simplePageSize.cpp \
    tableOfContents.cpp \
    units.cpp

OBJS = $(SRCS:.cpp=.o)
MOCS = $(MOCSRCS:.h=.moc)

all: libkviewshell.a

libkviewshell.a: $(OBJS) $(DEPS)
	$(AR) $@ $(OBJS)
	$(RANLIB) $@

.PHONY: clean distclean

clean:
	$(RM) $(OBJS) $(MOCS) libkviewshell.a

distclean: clean
	$(RMDIR) $(depsdir)

$(objdir)/%.o: $(srcdir)/%.cpp $(MOCS)
	if $(CXXCOMPILE) -MT $@ -MD -MP -MF "$(depsdir)/$*.Tpo" -c -o $@ $<; \
	then mv -f "$(depsdir)/$*.Tpo" "$(depsdir)/$*.Plo"; else rm -f "$(depsdir)/$*.Tpo"; exit 1; fi

$(objdir)/%.moc: $(srcdir)/%.h
	$(MOC) -o $@ $<

-include $(SRCS:%.cpp=$(depsdir)/%.Plo)
_______________________________________________
Help-make mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-make

Reply via email to