Thread: Help with makefile.

  1. #1
    Registered User
    Join Date
    Oct 2003

    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:

    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
    It depends on your compiler. There are -Dxxxxx flags for most compilers to tell them which platform to build for.

    In your make file (
    CC=gcc         <- or whatever compiler
    LDFLAGS= -L.
    CFLAGS= -I.
            @ 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 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
    Phildelphia, PA
    Yes, you can do this.

    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:

    "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
    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:

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

    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, 11: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