Have a Makefile to compile your C programs..

Home Forums C-programming.. Have a Makefile to compile your C programs..

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #2101 Reply
    Humble
    Keymaster

    I have below makefile in my C programming path and it helps me to easily compile C programs..

    [root@node]$ cat Makefile 
    program_NAME := myprogram
    program_C_SRCS := $(wildcard *.c)
    program_OBJS := ${program_C_SRCS:.c=.o}
    program_INCLUDE_DIRS :=
    program_LIBRARY_DIRS :=
    program_LIBRARIES :=
    CC := gcc
    CFLAGS := -Wall
    CPPFLAGS += $(foreach includedir,$(program_INCLUDE_DIRS),-I$(includedir))
    LDFLAGS += $(foreach librarydir,$(program_LIBRARY_DIRS),-L$(librarydir))
    LDFLAGS += $(foreach library,$(program_LIBRARIES),-l$(library))
    
    .PHONY: all clean distclean
    
    all: $(program_NAME)
    
    $(program_NAME): $(program_OBJS)
    	$(CC) $(program_OBJS) $(CFLAGS) -o $(program_NAME)
    
    clean:
    	@- $(RM) $(program_NAME)
    	@- $(RM) $(program_OBJS)
    
    distclean: clean
    [root@node]$
    
    
    Now to compile I use :
    
    
    [root@node]$ make compile
    gcc -Wall   -c -o compile.o compile.c
    gcc    compile.o   -o compile
    [hchiramm@humbles-lap C-Pgm]$ ls
    compile  compile.c  compile.o  Makefile 
    [root@node]$ ./compile 
    
     I was told to compile!!
    
    
    
    
    Hope it helps.
Viewing 1 post (of 1 total)
Reply To: Have a Makefile to compile your C programs..
Your information: