Thread: C Makefile Help needed

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    1

    Lightbulb C Makefile Help needed

    Hello,

    I have a C code of about 5 files.
    main.c & main.h
    typeA.c & typeA.h
    typeB.c & typeB.h

    The problem is that I have to make a makefile that compiles for typeA or typeB but not both.
    A further complication is that I can have typeB compiled for either N (a variable in code ) = 10 or = 56 (This controls the number of decimal places the code works into ).
    I need to encapsulate all this in a single makefile and as I am a n00b , need help here.

    Anything that points me in correct direction is much appreciated.

    Thanks,
    Ace

  2. #2
    uint64_t...think positive xuftugulus's Avatar
    Join Date
    Feb 2008
    Location
    Pacem
    Posts
    355
    Pretty confusing, but Makefile's are a whole different thing than C.
    I would say you need two targets, and the variable that needs to change in the typeB.c file, should be a #define that will not be #defined in the file but from the command line.
    Code:
    A guess on my side
    > make main A
    > make main B 10
    Is that what you would like to be able to do?
    Code:
    ...
        goto johny_walker_red_label;
    johny_walker_blue_label: exit(-149$);
    johny_walker_red_label : exit( -22$);
    A typical example of ...cheap programming practices.

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    I am probably a wimp, but I might make three targets, if I knew that N could only ever be 10 or 56 (and not anything in between). You can use -D N=10 or -D N=56 flags for the B cases (assuming gcc), and the A case would just be its own thing.

  4. #4
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by MasteAceVentura View Post
    The problem is that I have to make a makefile that compiles for typeA or typeB but not both.
    Okay, so make those two targets. It's not going to build both unless you make it happen.

    A further complication is that I can have typeB compiled for either N (a variable in code ) = 10 or = 56 (This controls the number of decimal places the code works into ).
    In your code, you will need to initialize this variable N like so:

    Code:
    #ifndef N_INITIAL_VALUE
    #define N_INITIAL_VALUE 10
    #endif
    int N = N_INITIAL_VALUE;
    Then in your makefile you must add -DN_INITIAL_VALUE=10 or -DN_INITIAL_VALUE=56 to the CFLAGS.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Makefile Problem: None rule to make target
    By chris24300 in forum Linux Programming
    Replies: 25
    Last Post: 06-17-2009, 09:45 AM
  2. Need help with makefile
    By New_Programmer in forum C++ Programming
    Replies: 5
    Last Post: 03-31-2009, 04:55 PM
  3. Building a project using a Makefile
    By starcatcher in forum Windows Programming
    Replies: 2
    Last Post: 11-23-2008, 11:50 PM
  4. G++ Makefile Help Needed
    By OWD2k7 in forum Linux Programming
    Replies: 17
    Last Post: 04-30-2007, 06:43 PM
  5. Need help with Makefile
    By xshapirox in forum C++ Programming
    Replies: 14
    Last Post: 09-28-2004, 03:32 PM