Common Makefile for all C/C++ programs.

   P_NAME          :=  <Name of your program>
   P_C_SRCS        :=  $(wildcard *.c)
   P_C_OBJS        :=  ${P_C_SRCS:.c=.o}
   P_OBJS          :=  $(P_C_OBJS) 
   P_INCLUDE_DIRS  :=  <Include directory path>
   CPPFLAGS        +=  $(foreach includedir,$(P_INCLUDE_DIRS),-I$(includedir))
   LDFLAGS         +=  $(foreach librarydir,$(P_LIBRARY_DIRS),-L$(librarydir))
   LDFLAGS         +=  $(foreach library,$(P_LIBRARIES),-l$(library))
   CXX             :=  gcc
   CC              :=  gcc -g -Wall -Wextra -Wparentheses -pedantic
 .PHONY:         all clean
 all:            $(P_NAME)
 $(P_NAME):      $(P_OBJS)
         ar rcs $(P_NAME) $(P_OBJS)
 clean:
         @- $(RM) $(P_NAME)
         @- $(RM) $(P_OBJS)
         @- $(RM) core*
         @- $(RM) tags
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s