unusual makefiles - problems with rules - Linux

This is a discussion on unusual makefiles - problems with rules - Linux ; Hi, I'm trying to compile my C++ code in such a way, that I get all .o files directly to specified folder. I want to avoid creation of .o files in current dir and then copy them over to desired ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: unusual makefiles - problems with rules

  1. unusual makefiles - problems with rules

    Hi,
    I'm trying to compile my C++ code in such a way, that I get all .o
    files directly to specified folder.
    I want to avoid creation of .o files in current dir and then copy them
    over to desired one.
    Could someone please tell me, why the follwoing makefile does nothing?
    make says: Nothing to be done for 'lib'

    I do not have any .o files created...


    #
    # compile help modules used in .so and main server classes
    # these modules are included in liasut.a library stored in ./output/
    lib
    # folder

    # Include CPP, CC settings and others common flags
    include ../make.conf.linux

    ..SUFFIXES : .o .cpp .c

    CPPFLAGS= -c -I"../Include"
    CFLAGS= -c -I"../Include"
    CDEFS=

    OUTL = ../output/Libs

    ..cpp.o:
    @echo "C++ Libs source compilation $<"
    @$(CPP) $(CPPFLAGS) $(CDEFS) $<

    ..c.$(OUTL)/%.o:
    @echo "C Libs source compilation $*.c ==> $(OUTL)/$*.o"
    @$(CC) $(CFLAGS) $(CDEFS) $*.c -o $(OUTL)/$*.o

    $(OUTL)/%.cpp.$(OUTL)/%.o:
    @echo "C++ Libs source compilation $*.cpp ==> $(OUTL)/$*.o"
    @$(CPP) $(CPPFLAGS) $(CDEFS) $*.cpp -o $(OUTL)/$*.o

    MODULES=$(OUTL)/AmaSocket.o \
    $(OUTL)/DbgLIB.o

    lib: $(MODULES)
    # @echo "lib $?"
    @echo "Done!"

    clean:
    @echo "Cleaning $(OUTL)/*.o ..."
    @rm -f $(OUTL)/*.o *.o
    @echo "Cleaned"

    $(OUTL)/AmaSocket.o: AmaSocket.cpp
    $(OUTL)/DbgLIB.o : DbgLIB.cpp DbgLIB.h Dbg.h


  2. Re: unusual makefiles - problems with rules

    Zbigniew wrote:
    > Hi,
    > I'm trying to compile my C++ code in such a way, that I get all .o
    > files directly to specified folder.
    > I want to avoid creation of .o files in current dir and then copy them
    > over to desired one.
    > Could someone please tell me, why the follwoing makefile does nothing?
    > make says: Nothing to be done for 'lib'
    >
    > I do not have any .o files created...
    >
    >
    > #
    > # compile help modules used in .so and main server classes
    > # these modules are included in liasut.a library stored in ./output/
    > lib
    > # folder
    >
    > # Include CPP, CC settings and others common flags
    > include ../make.conf.linux
    >
    > .SUFFIXES : .o .cpp .c
    >
    > CPPFLAGS= -c -I"../Include"
    > CFLAGS= -c -I"../Include"
    > CDEFS=
    >
    > OUTL = ../output/Libs
    >
    > .cpp.o:
    > @echo "C++ Libs source compilation $<"
    > @$(CPP) $(CPPFLAGS) $(CDEFS) $<
    >
    > .c.$(OUTL)/%.o:
    > @echo "C Libs source compilation $*.c ==> $(OUTL)/$*.o"
    > @$(CC) $(CFLAGS) $(CDEFS) $*.c -o $(OUTL)/$*.o
    >
    > $(OUTL)/%.cpp.$(OUTL)/%.o:
    > @echo "C++ Libs source compilation $*.cpp ==> $(OUTL)/$*.o"
    > @$(CPP) $(CPPFLAGS) $(CDEFS) $*.cpp -o $(OUTL)/$*.o
    >
    > MODULES=$(OUTL)/AmaSocket.o \
    > $(OUTL)/DbgLIB.o
    >
    > lib: $(MODULES)
    > # @echo "lib $?"
    > @echo "Done!"
    >
    > clean:
    > @echo "Cleaning $(OUTL)/*.o ..."
    > @rm -f $(OUTL)/*.o *.o
    > @echo "Cleaned"
    >
    > $(OUTL)/AmaSocket.o: AmaSocket.cpp
    > $(OUTL)/DbgLIB.o : DbgLIB.cpp DbgLIB.h Dbg.h
    >

    Two problems.

    One is you're using the old Unix style pattern rules. GNU Make provides
    more flexible pattern rules (see 'info make "pattern rules"'). The old
    style pattern rules are not flexible enough to do what you want. This is
    still not enough, which leads to problem two - you've got the cart
    before the horse.

    The usual idiom is to put the Makefile where you want to create your
    targets are and pull sources from somewhere else. That's because make
    assumes that targets are in the current directory. If that's not what
    you want, then you have to be explicit about it. For example, in your
    case the following pattern rule should work:

    $(LIB)/%.o: %.cpp
    $(COMPILE.cpp) $(OUTPUT_OPTION) $<

    Note that the "%" will not expand into a pathname with slashes. There's
    no way to tell make where to look for targets - only where it should
    look for prerequisites.

    The script portion of the rule above is a cut and paste of the implicit
    rule that GNU Make defines for .cpp files (see 'make -p'). You would not
    have to include this rule at all if you put your Makefile where the
    targets are and not where the sources are.

    John

+ Reply to Thread