Template makefile.


I did this so many times during school that I just needed a quick Makefile, here it is. If you have any suggestions please feel free to make them!

#  Comments
#  @author gnucom.cc
CC=gcc
CPP=g++
SUS3=-D_POSIX_SOURCE -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600
HARDEN=-D_FORTIFY_SOURCE
CFLAGS=-Wall -Werror -g -std=gnu99 -pedantic $(SUS3) $(HARDEN)
LDFLAGS=
 
ALL=myprogram
 
all:    $(ALL)
 
myprogram: myobject.o helpers.o
        $(CC) $(LDFLAGS) -o $@ $^
 
myobject.o: mysource.c myheader.h
        $(CC) $(CFLAGS) -c $<
 
helpers.o: helpers.c helpers.h
        $(CC) $(CFLAGS) -c $<
 
test:
        MALLOC_CHECK=1 valgrind \
          --leak-check=full            \
          --show-reachable=yes ./myprogram
 
clean:
        rm -rf core* *.o *.gch $(ALL)
This entry was posted in Programming and tagged , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.