Makefile with flags

This is a discussion on Makefile with flags within the C Programming forums, part of the General Programming Boards category; Hi, Small question regarding makefiles: I want to add a new target: release that will compile my driver with additional ...

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    12

    Makefile with flags

    Hi,

    Small question regarding makefiles:
    I want to add a new target: release
    that will compile my driver with additional flag
    (EXTRA_CFLAGS += -Drelease_flag)

    how can i do that on this example:


    Code:
    KERNELPATH := /home/kernel-2.6.24/
    
    .PHONY: all clean
    
    EXTRA_CFLAGS += -Werror
    EXTRA_CFLAGS += -I$(src)/dir1
    EXTRA_CFLAGS += -I$(src)/dir2
    
    all: modules
    
    obj-m := driver.o
    
    driver-objs := file1.o
    driver-objs += file2.o
    
    modules:
     make -C $(KERNELPATH) M=$(PWD) modules
    
    clean:
     make -C $(KERNELPATH) M=$(PWD) clean


    thanks

  2. #2
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,252
    Quote Originally Posted by amitbern View Post
    Hi,

    Small question regarding makefiles:
    I want to add a new target: release
    that will compile my driver with additional flag
    (EXTRA_CFLAGS += -Drelease_flag)
    Recursively invoke make.

    Code:
    ...
    EXTRA_CFLAGS += -Werror
    EXTRA_CFLAGS += -I$(src)/dir1
    EXTRA_CFLAGS += -I$(src)/dir2
    EXTRA_CFLAGS += $BUILD_CONFIG_FLAGS
    ...
    
    release:
            $(MAKE) all BUILD_CONFIG_FLAGS=-Drelease_flag
    ...
    EDIT: The problem is that the makefile is not aware that you've changed your flags, so it won't rebuild if you've already built some other configuration. You have to "make clean" first. There are ways to set it up automatically but they are more complicated than what I've shown here, involving external scripts, etc.
    Last edited by brewbuck; 01-26-2009 at 11:01 AM.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Building a project using a Makefile
    By starcatcher in forum Windows Programming
    Replies: 2
    Last Post: 11-23-2008, 10:50 PM
  2. Need help with Makefile
    By xshapirox in forum C++ Programming
    Replies: 14
    Last Post: 09-28-2004, 03:32 PM
  3. Bit Flags
    By Padawan in forum C Programming
    Replies: 15
    Last Post: 03-30-2004, 09:38 PM
  4. about Makefile and Macro
    By tom_mk in forum C++ Programming
    Replies: 1
    Last Post: 09-18-2003, 01:07 PM
  5. Flags, the ambiguity of
    By Jeremy G in forum C++ Programming
    Replies: 1
    Last Post: 01-25-2003, 10:41 PM

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