Makefiles

Captured at: 2013-05-23 06:57:59 UTC

When I’m working on a new project and need to throw a quick and dirty implementation of some C++ code together, I usually rely a makefile like this one to compile my code for me. I’m putting it here so I can find it more easily the next time I need a simple Makefile for a QAD implementation.

Generic Makefile

# Makefile
# Author: Arvind Pereira

# Modify the includes, sources, headers, executable and
# other flags accordingly!
INCLUDES = -I ./ -I/usr/local/include
LIBS = -L/usr/lib/ -lm

CC = g++
DEBUG = -g
LFLAGS = -Wall $(DEBUG)
CFLAGS = -Wall -c

SOURCES = File1.cpp \
	  File2.cpp \
	  File3.cpp

HEADERS = File1.h \
	  File2.h

OBJ = $(SOURCES:.cpp=.o)

EXE = MyExecutable

all: MyExecutable

$(EXE):	$(OBJ)
	$(CC) -o $(EXE) $(OBJ) $(LFLAGS) $(LIBS)    

.cpp.o:
	$(CC) $(CFLAGS) $(INCLUDES) $< -o $@

tar:
	tar -czf $(EXE).tar.gz $(SOURCES) $(HEADERS) Makefile

clean:
	rm -f $(OBJ)
	rm -f $(EXE)