c Makefile

Note that you have to set TARGET with your executable name, and list the .c files to compile in SRCS. Also, note that Makefile indents must be tabs, not spaces.

    TARGET  := <<your executable name>> 
    SRCS    := <<one ore more of your .c files>> 
    OBJS    := ${SRCS:.c=.o} 
    DEPS    := ${SRCS:.c=.dep} 
    XDEPS   := $(wildcard ${DEPS}) 
    CCFLAGS = -std=gnu99 -O2 -Wall -Werror -ggdb 
    LDFLAGS = 
    LIBS    = 
    .PHONY: all clean distclean 
    all:: ${TARGET} 
    ifneq (${XDEPS},) 
    include ${XDEPS} 
    ${TARGET}: ${OBJS} 
        ${CC} ${LDFLAGS} -o $@ $^ ${LIBS} 
    ${OBJS}: %.o: %.c %.dep 
        ${CC} ${CCFLAGS} -o $@ -c $< 
    ${DEPS}: %.dep: %.c Makefile 
        ${CC} ${CCFLAGS} -MM $< > $@ 
       -rm -f *~ *.o ${TARGET} 
    distclean:: clean

Leave a Reply