Help with makefile.

This is a discussion on Help with makefile. within the C Programming forums, part of the General Programming Boards category; Hello everybody! I need help with makefiles. I read almost every guide I found ( I liked very much the ...

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    106

    Help with makefile.

    Hello everybody!

    I need help with makefiles. I read almost every guide I found ( I liked very much the GNU Make documentation ) but I need some hints by an experienced programmer.

    Can I write a makefile such that I can use a command line like these examples:

    Code:
    make platform1 debug
    make platform2 release
    make debug platform3 serialNum
    and so on: I would like to be able to specify different options on the command line instead #defining them in my main.h definitions file. Is this possible with make? Or should I do this in another way?

    I tried two days, but I can't reach this result. Also I find much behaviors which are not descripted in docs ( some vars loose their value from a 'goal' to another, for example ).

    I'm using Cygwin to run GCC.

    Thank you very much for your help.
    Last edited by BrownB; 05-24-2005 at 01:54 AM.

  2. #2
    .
    Join Date
    Nov 2003
    Posts
    307
    It depends on your compiler. There are -Dxxxxx flags for most compilers to tell them which platform to build for.

    In your make file (mymakefile.mk):
    Code:
    CC=gcc         <- or whatever compiler
    CCOPTS= 
    GEXE=/path/to/exectuable
    LDFLAGS= -L.
    CFLAGS= -I.
    
    .....
    
    .c:
            @ rm -f make.log
            $(CC) $(CFLAGS) $*.c -o $(GEXE)/$* $(LDFLAGS)  $(CCOPT) 
            @ echo "Successful Compilation of $*.c"
            @ echo " "
    invoke it this way to compile executable.c into executable
    make -f mymakefile.mk executable CCOPT=-DPLAT_UNIX

    he DPLAT thing is the platform you want. Consult your compiler for information.

  3. #3
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    Yes, you can do this.

    Code:
    platform1_debug: gcc -platform1 -debug file.c
    If that's your makefile, you can invoke that particular option like so:
    $> make platform1_debug

    You can make as many as those as you like.

    That's how make install works. There's just a portion of the makefile that beings install:
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

  4. #4
    Registered User
    Join Date
    Oct 2003
    Posts
    106
    Thank you Josh, but it's the way I did as last chance: I created a goal for each possible combination.

    From the answers, I must imagine that there's no simple way to do what I was looking to do with make, using with "flags" on the command line in such a way to avoid the writing of all the n! combinations of the n parameters...

    I was trying something as this:

    Code:
    param1: FLAGS += -DFLAG1
    param1: MAKECMDGOALS := $(MAKECMDGOALS: param1 = )
    param1: .scanCommands
    param1: .done
    
    param2: FLAGS += -DFLAG2
    param1: MAKECMDGOALS := $(MAKECMDGOALS: param2 = )
    param2: .scanCommands
    param2: .done
    
    ....
    
    .scanCommands: 
    ifneq (,$(findstring param1,$(MAKECMDGOALS)))
    .scanCommands: FLAGS += -DFLAG1
    .scanCommands: MAKECMDGOALS := $(MAKECMDGOALS: param1 = )
    endif
    
    ifneq (,$(findstring param2,$(MAKECMDGOALS)))
    .scanCommands: FLAGS += -DFLAG2
    .scanCommands: MAKECMDGOALS := $(MAKECMDGOALS: param2 = )
    endif
    
    ....
    
    
    .done: 
         $(CC) $(FLAGS) source.c
    but unfortunately MAKE doesn't accept this:
    Code:
    ifneq (,$(findstring param1,$(MAKECMDGOALS)))
    .scanCommands: FLAGS += -DFLAG1
    .scanCommands: MAKECMDGOALS := $(MAKECMDGOALS: param1 = )
    endif
    or, better, accept it but not in the way I was expected: it executes the goal in the 'if' branch always...

    BrownB
    Last edited by BrownB; 05-24-2005 at 09:34 AM.

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. Building a project using a Makefile
    By starcatcher in forum Windows Programming
    Replies: 2
    Last Post: 11-23-2008, 10:50 PM
  3. unix makefile won't work but works in Dev C++
    By jk1998 in forum C++ Programming
    Replies: 1
    Last Post: 06-09-2007, 03:54 PM
  4. makefile blues....
    By WaterNut in forum C Programming
    Replies: 6
    Last Post: 05-30-2005, 08:22 PM
  5. Need help with Makefile
    By xshapirox in forum C++ Programming
    Replies: 14
    Last Post: 09-28-2004, 03:32 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21