summaryrefslogtreecommitdiff
path: root/Makefile
blob: 9f489a4c3ae38f40f9eb3a14edaa98ed810dfedd (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
CC		= clang
CPPFLAGS	= -Wall -std=c++11  -fPIC
LDFLAGS		= -shared
SONAME		= termgl

BUILDDIR	= build
SOURCEDIR	= src
OBJECTDIR	= obj
TESTSOURCE	= test
OUTPUT		= lib$(SONAME).so.$(VERSION).$(PATCHLEVEL)

#VERSION
VERSION		= 1
PATCHLEVEL	= 1

SRCS = $(wildcard $(SOURCEDIR)/*.cpp)  
OBJS = $(SRCS:.cpp=.o)
OBJ  = $(OBJS:$(SOURCEDIR)/%=$(OBJECTDIR)/%)

PREFIX		= /

build: dir genversion $(OBJ) 
	@echo [LD] $(OBJ) 
	@$(CC) $(CPPFLAGS) -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 $(OBJECTDIR)
	@mkdir -p $(BUILDDIR)
	@mkdir -p $(BUILDDIR)/lib
	@mkdir -p $(BUILDDIR)/inc

debug: CFLAGS += -g -D _DEBUG
debug: build;

$(OBJECTDIR)/%.o: $(SOURCEDIR)/%.cpp
	@echo [CC] $<
	@$(CC) $(CPPFLAGS) -c $< -o $@

$(OBJECTDIR)/%.o: example/%.cpp
	@echo [CC] $<
	@$(CC) $(CPPFLAGS) -I$(SOURCEDIR) -c $<

debug: CPPFLAGS+=-g
debug: build

all: clean build

.PHONY: clean
clean:
	@echo [ RM ] $(OBJ)
	@echo [ RM ] $(TESTSOURCE).o
	@echo [ RM ] src/version.h
	@echo [ RM ] $(BUILDDIR)/lib $(BUILDDIR)/inc $(BUILDDIR)/test doc/
	@rm -df  $(OBJ) $(TESTSOURCE).o src/version.h
	@rm -Rdf $(BUILDDIR)/lib $(BUILDDIR)/inc $(BUILDDIR)/test doc/

genversion:
	@echo [GEN ] 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: debug $(OBJECTDIR)/$(TESTSOURCE).o
	@echo [LD] $(TESTSOURCE).o
	@mkdir -p $(BUILDDIR)/test
	@$(CC) $(CPPFLAGS) -g -o $(BUILDDIR)/test/test $(TESTSOURCE).o $(OBJ) -lstdc++ -lm

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

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

.PHONY: doc
doc: genversion
	@mkdir -p doc
	@doxygen .doxygen

.PHONY: install
install: build
	@echo "Installing..."
	@install -D $(BUILDDIR)/lib/$(OUTPUT) $(PREFIX)/usr/lib/$(OUTPUT)
	@ln -sf $(PREFIX)/usr/lib/$(OUTPUT) $(PREFIX)/usr/lib/lib$(SONAME).so.$(VERSION)
	@ln -sf $(PREFIX)/usr/lib/$(OUTPUT) $(PREFIX)/usr/lib/lib$(SONAME).so
	@echo "Finished!"

.PHONY: uninstall
uninstall:
	@echo "Removing..."
	@rm $(PREFIX)/usr/lib/lib$(SONAME)*
	@echo "Finished"

.PHONY: install-headers
install-headers:
	@echo Installing headers...