#
# Makefile
#
# A Makefile for projects that requires minimal adaptation.
# Only the variables before the line of #'s should be changed.
# Be sure to have all your source files in the same directory
# as this Makefile, and no extra source files, as it will try
# to compile all files with $(SUFFIX) as its suffix.
#
# Author : J.I.v.Hemert
# Version: 1.2
#


### Targets ###

TITLE = src-project
BIN = gga
DISTNAME = project
TAGSFILE = tags
TARSUFFIX = .tar.gz


### Directories ###

BINDIR = ../bin
DEBUGDIR = ../debug


### Misc ###

SUFFIX = cc
VPATH = .
MACHINE = `uname`


### Flags ###
#-ldmalloc 
LIBS = -lm #-lccmalloc -ldl
LIBPATH = -L/home/jvhemert/lib/$(MACHINE)
INCPATH = -I/home/jvhemert/include
LDFLAGS = -g
CFLAGS = -Wall -O3
CPPFLAGS = -Wall -O3
TAGSFLAGS = -t -o $(TAGSFILE)
DEFINES = -D$(MACHINE)
TARFLAGS = cfz
RMFLAGS = -f


### Progs ###

RM = rm $(RMFLAGS)
CC = g++
LINKER = $(CC)
CTAGS = ctags $(TAGSFLAGS)
TAR = tar $(TARFLAGS)
SHELL = /bin/sh
MOVE = mv


#############################################################
#               NO CHANGES FROM HERE ON                     #
#############################################################


OFILES = $(patsubst %.$(SUFFIX),%.o,$(wildcard *.$(SUFFIX)))
HFILES = $(patsubst %.$(SUFFIX),%.h,$(wildcard *.$(SUFFIX)))
CFILES = $(wildcard *.$(SUFFIX))

.PHONY: clean proper all backup tags dist showdeps realclean install


### Program ###

$(BIN): $(OFILES)
	$(LINKER) $(LDFLAGS) -o $@ $^ $(LIBPATH) $(LIBS)

%.o: %.$(SUFFIX)
	$(CC) $(CPPFLAGS) $(DEFINES) $(INCPATH) -c $^ -o $@

tags:
	-$(RM) $(TAGSFILE)
	$(CTAGS) $(CFILES)

showdeps:
	$(CC) -MM $(CFILES)

all install: $(BIN)
	-strip $(BIN)
	-$(MOVE) $(BIN) $(BINDIR)

### Clean ###

realclean proper: clean
	-$(RM) $(BINDIR)/$(BIN) $(BIN)

clean:
	-$(RM) $(OFILES) $(DEBUGDIR)/* $(TAGSFILE)


### Misc ###

backup: proper
	-$(RM) ../$(TITLE)-`date +'%d%m%y-%H%M'`$(TARSUFFIX)
	$(TAR) ../$(TITLE)-`date +'%d%m%y-%H%M'`$(TARSUFFIX) *

dist: proper
	-$(RM) ../$(DISTNAME)$(TARSUFFIX)
	$(TAR) ../$(DISTNAME)$(TARSUFFIX) *

# eof() Makefile

