Makefile question

Discussion in 'C++' started by Matthias Pieroth, Mar 4, 2004.

  1. Hi NG,

    I have the following MakeFile:

    # Compiler
    #---------------------------------------
    CC = g++

    APP = snake-client

    # Compilerflags
    #---------------------------------------
    #CFLAGS += -O2

    # Libraries
    #---------------------------------------
    LIB = -lncurses

    # Sourcedateien
    #---------------------------------------
    SRC = snake-client.cpp CCursesWrapper.cpp

    # Objektdateien
    #---------------------------------------
    OBJ = $(SRC:.cpp=.o)

    $(APP): $(OBJ)
    $(CC) $(OBJ) -o $(APP) $(LIB)

    clean:
    rm *.o

    My problem is, I have a CCursesWrapper.h. I want to add this file to the
    MakeFile, so that it will be included and newly compiled if I change the
    CCursesWrapper.h. How can I do this?

    Thank you

    Matthias
     
    Matthias Pieroth, Mar 4, 2004
    #1
    1. Advertisements

  2. Matthias Pieroth wrote:
    > My problem is, I have a CCursesWrapper.h. I want to add this file to the
    > MakeFile, so that it will be included and newly compiled if I change the
    > CCursesWrapper.h. How can I do this?


    I think you want to recompile CCursesWarpper.o whenever CCursesWarpper.cpp
    or CCursesWrapper.h is changed. So, you simply have to add a rule for
    CCursesWrapper.o like

    CCursesWrapper.o: CCursesWrapper.cpp CCursesWrapper.h
    $(CC) -c -o $@ $< $(LIB)

    if CCursesWrapper.h is located in the current directory (otherwise you have
    to add -I <includedir> to the compiler options, where <includedir> stands
    for the directory of CCursesWrapper.h).

    HTH
    Emanuel
     
    Emanuel Ziegler, Mar 4, 2004
    #2
    1. Advertisements

  3. Re: Makefile question [OFF TOPIC]

    Matthias Pieroth wrote:
    > Hi NG,
    >


    Hi NG,

    this is off-topic for comp.lang.c++. Try posting to comp.programming.

    > I have the following MakeFile:

    ....
    >
    > My problem is, I have a CCursesWrapper.h. I want to add this file to the
    > MakeFile, so that it will be included and newly compiled if I change the
    > CCursesWrapper.h. How can I do this?



    you'll need to add the rule

    $(OBJ) : CCursesWrapper.h
    # no commands...


    However - if you want all this to happen automagically, use MakeXS.

    (shameless plug)

    http://www.makexs.com
     
    Gianni Mariani, Mar 4, 2004
    #3
  4. Matthias Pieroth

    Jorge Rivera Guest

    Matthias Pieroth wrote:
    > Hi NG,
    >
    > I have the following MakeFile:
    >
    > # Compiler
    > #---------------------------------------
    > CC = g++
    >
    > APP = snake-client
    >
    > # Compilerflags
    > #---------------------------------------
    > #CFLAGS += -O2
    >
    > # Libraries
    > #---------------------------------------
    > LIB = -lncurses
    >
    > # Sourcedateien
    > #---------------------------------------
    > SRC = snake-client.cpp CCursesWrapper.cpp
    >
    > # Objektdateien
    > #---------------------------------------
    > OBJ = $(SRC:.cpp=.o)
    >
    > $(APP): $(OBJ)
    > $(CC) $(OBJ) -o $(APP) $(LIB)
    >
    > clean:
    > rm *.o
    >
    > My problem is, I have a CCursesWrapper.h. I want to add this file to the
    > MakeFile, so that it will be included and newly compiled if I change the
    > CCursesWrapper.h. How can I do this?
    >
    > Thank you
    >
    > Matthias
    >


    You can automate this process somewhat...

    Do a man on mkdepends. Read carefully. It writes rules, but it changes
    your Makefile while doing it. It is nice because it will run a
    preprocessor on your source files and determine all the header files it
    requires. It then proceeds to create rules and append them to your Makefile
     
    Jorge Rivera, Mar 5, 2004
    #4
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. MACEI'S
    Replies:
    0
    Views:
    1,560
    MACEI'S
    Jul 10, 2003
  2. jose luis fernandez diaz

    Question about simple gmake Makefile

    jose luis fernandez diaz, Apr 29, 2004, in forum: C++
    Replies:
    1
    Views:
    1,373
    Christopher Benson-Manica
    Apr 29, 2004
  3. Dan Bishop

    Python in Makefile Question

    Dan Bishop, Feb 11, 2005, in forum: Python
    Replies:
    4
    Views:
    791
    Bart van Deenen
    Feb 11, 2005
  4. Carson

    Makefile question

    Carson, Jul 4, 2005, in forum: C Programming
    Replies:
    1
    Views:
    416
    Rouben Rostamian
    Jul 4, 2005
  5. Replies:
    2
    Views:
    408
  6. xz

    Makefile question.

    xz, Jan 9, 2008, in forum: C++
    Replies:
    8
    Views:
    526
    Victor Bazarov
    Jan 14, 2008
  7. fl

    Question about makefile

    fl, Oct 11, 2010, in forum: C Programming
    Replies:
    5
    Views:
    480
    Jorgen Grahn
    Oct 12, 2010
  8. Upstart
    Replies:
    10
    Views:
    363
    Martien Verbruggen
    Dec 7, 2003
Loading...