-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
executable file
·152 lines (123 loc) · 3.29 KB
/
makefile
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/usr/bin/make -f
# Copyright (C) 2020 Antti Helminen
# This program is free software; you can redistribute
# it and/or modify it under the terms of the GNU
# General Public License
################################
# System configuration
################################
SHELL = /bin/sh
.SUFFIXES:
.SUFFIXES: .cpp .o .h .dep
CXX := g++
LD := ld
INSTALL := install
INSTALLDATA := install -m 644
OS := linux
CFLAGS = -g -Wall $(DEFS) $(INC)
DEFS = -std=c++17 -march=x86-64 -fPIC
INC = -iquote $(incdir)
LDFLAGS = -shared -Wl,-soname,$(SONAME)
prefix = /usr/local/
bindir = $(prefix)bin/
libdir = $(prefix)lib/
includedir = $(prefix)include/
################################
# Project files
################################
PROG_NAME = libbrb2.so
VERSION = $(lastword 0 $(shell grep "\#define BRB2_MAJOR_VERSION" $(incdir)brb2.h))
MINOR = $(lastword 0 $(shell grep "\#define BRB2_MINOR_VERSION" $(incdir)brb2.h))
PATCH = $(lastword 0 $(shell grep "\#define BRB2_PATCH_VERSION" $(incdir)brb2.h))
SONAME = $(PROG_NAME).$(VERSION)
REALNAME = $(SONAME).$(MINOR).$(PATCH)
builddir = ./bin/$(OS)/
incdir = ./inc/
src_basedir = ./src/
srcdirs = $(addsuffix /,$(shell find $(patsubst %/,%,$(src_basedir)) -type d))
resdir = ./res/
3libdir = ./lib/$(OS)/
depdir = ./dep/$(OS)/
objdir = ./obj/$(OS)/
dirs = $(builddir) $(incdir) $(src_basedir) $(resdir) \
$(3libdir) $(depdir) $(objdir)
SRCS := $(patsubst ./%,%,$(foreach dir, $(srcdirs),$(wildcard $(dir)*.cpp)))
RESS := \
LIBS := \
PCH := $(incdir)pch.h
################################
# Targets
################################
OBJS := $(addprefix $(objdir),$(SRCS:.cpp=.o))
DEPENDENCY := $(addprefix $(depdir),$(SRCS:.cpp=.dep))
GCH := $(PCH).gch
BUILD := $(objdir).lastbuild
vpath %.h $(incdir)
vpath %.cpp $(srcdirs)
vpath %.dep $(depdir)
vpath %.o $(objdir)
.PHONY: all build install clean realclean rebuild installdirs
################################
# Make
################################
all: $(GCH) build
# GNU specific precompiled header:
$(GCH): $(PCH)
@echo [PRECOMPILED HEADER]
$(CXX) -c $(CFLAGS) $<
@echo
build: $(BUILD)
@echo [PROJECT UP-TO-DATE]
@echo
$(BUILD): $(OBJS)
@echo [LINK]
$(CXX) $(LDFLAGS) $^ -o $(builddir)$(REALNAME)
@touch $@
@echo
$(objdir)%.o : %.cpp %.dep
@echo [COMPILE]
$(CXX) -c $(CFLAGS) \
-o $@ $<
@echo
# Dependency generation:
# dep/main.dep: src/main.cpp inc/header.h
$(depdir)%.dep : %.cpp | $(dirs)
@echo [DEPENDENCY]
$(CXX) -c $(CFLAGS) \
-MM -MP -MT $@ $< \
> $@
@echo
-include $(DEPENDENCY)
install: all
@echo [INSTALL]
$(INSTALLDATA) $(builddir)$(REALNAME) $(libdir)$(REALNAME)
mkdir -p $(includedir)brb2
$(INSTALLDATA) $(incdir)brb2.h $(includedir)brb2
rm -f $(libdir)$(PROG_NAME)
ln -s $(REALNAME) $(libdir)$(PROG_NAME)
ldconfig
@echo
clean:
@echo [CLEAN]
ifdef builddir
rm -f $(builddir)*
endif
rm -f $(OBJS) $(DEPENDENCY) $(GCH) $(BUILD)
@echo
realclean: clean
rm -f $(libdir)$(REALNAME)
rm -f $(libdir)$(SONAME)
rm -f $(libdir)$(PROG_NAME)
ldconfig
@echo
rebuild: clean
@echo [REBUILD]
$(MAKE)
@echo
# Directory structure
$(dirs) installdirs:
@echo [MKDIR dirs]
mkdir -p $(dirs)
mkdir -p $(foreach dir,$(patsubst ./%,%,$(srcdirs)),$(objdir)$(dir))
mkdir -p $(foreach dir,$(patsubst ./%,%,$(srcdirs)),$(depdir)$(dir))
@echo