summaryrefslogtreecommitdiff
path: root/Makefile
blob: 8f90431929dd0f5e67d4a0c56be3819ef0536324 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
CC      = clang
CFLAGS  = -Wall -g -std=c++11  -fPIC
DEBUGFLAGS = -Wall -g -std=c++11
LDFLAGS = -shared
SONAME = engine
BUILDDIR = build
SOURCEDIR = src
TESTSOURCE = test
#VERSION
VERSION = 0
PATCHLEVEL = 4
OUTPUT = lib$(SONAME).so.$(VERSION).$(PATCHLEVEL)

OBJ = cObject.o cObjectHandler.o cRender.o cInput.o cWiremesh.o

build: dir genversion $(OBJ)
	$(CC) $(CFLAGS) -o $(BUILDDIR)/lib/$(OUTPUT) $(OBJ) $(LDFLAGS) -Wl,-soname=lib$(SONAME).so.$(VERSION)
	ln -sf $(OUTPUT) $(BUILDDIR)/lib/lib$(SONAME).so.$(VERSION)
	ln -sf $(OUTPUT) $(BUILDDIR)/lib/lib$(SONAME).so
	cp $(SOURCEDIR)/c*.h $(BUILDDIR)/inc
	cp $(SOURCEDIR)/version.h $(BUILDDIR)/inc

dir:
	mkdir -p $(BUILDDIR)
	mkdir -p $(BUILDDIR)/lib
	mkdir -p $(BUILDDIR)/inc


%.o: $(SOURCEDIR)/%.cpp
	@echo
	@echo Building $<
	@echo ==============
	@echo
	$(CC) $(CFLAGS) -c $<

%.o: example/%.cpp
	$(CC) $(CFLAGS) -I$(SOURCEDIR) -c $<


all: clean build

.PHONY: clean doc

clean:
	rm -df  $(OBJ) $(TESTSOURCE).o src/version.h
	rm -Rdf $(BUILDDIR)/lib $(BUILDDIR)/inc $(BUILDDIR)/test doc/

genversion:
	@echo Building Version
	@echo "//Generated by MAKEFILE. DO NOT Edit." > $(SOURCEDIR)/version.h
	@echo "#pragma once" >> $(SOURCEDIR)/version.h
	@echo "#define VERSION $(VERSION)" >> $(SOURCEDIR)/version.h
	@echo "#define PATCHLEVEL $(PATCHLEVEL)" >> $(SOURCEDIR)/version.h
	@echo "#define VERSTRING \"`git describe`\"" >> $(SOURCEDIR)/version.h
	@echo "#define DATE \"`date +'%d.%m.20%y'`\"" >> $(SOURCEDIR)/version.h
	@echo "#define TIME \"`date +'%H:%M:%S'`\"" >> $(SOURCEDIR)/version.h
	@echo "#define BUILDER \"`git config user.name`\"" >> $(SOURCEDIR)/version.h
	@echo "#define BUILDERMAIL \"`git config user.email`\"" >> $(SOURCEDIR)/version.h

gentest: build $(TESTSOURCE).o
	mkdir -p $(BUILDDIR)/test
	$(CC) $(DEBUGFLAGS) -o $(BUILDDIR)/test/test $(TESTSOURCE).o $(OBJ) -lstdc++ -lm

run: gentest
	./$(BUILDDIR)/test/test

memleak: gentest
	valgrind -v --track-origins=yes "./$(BUILDDIR)/test/test"

doc:
	mkdir -p doc
	doxygen .doxygen