aboutsummaryrefslogtreecommitdiff
path: root/Makefile.vars
blob: 90e3a51b02a15889271b4f8dd34ee1d8c09920fc (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
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#!/usr/bin/make -f
-include Makefile.cfg

# ---
# Informations principales concernant le projet.
# ---
# Nom et description.

 NAME := weshd
 DESC := Démon et utilitaires de gestion de serveurs WES.

# Informations concernant le mainteneur.

 MAINTAINER_NAME := Thomas Touhey
 MAINTAINER_MAIL := thomas@touhey.fr

 MAINTAINER := $(MAINTAINER_NAME) <$(MAINTAINER_MAIL)>

# Version du projet.

 MAJOR := 0
 MINOR := 1
 INDEV := y

 VERSION := $(MAJOR).$(MINOR)$(if $(INDEV),-indev)

# Noms des composants.

 DAEMON := weshd
 LIB := wesh
 CLIENT := weshclient

# ---
# Utilitaires.
# ---

 CC := clang
 LD := clang
 CWARN := -Weverything -Wno-disabled-macro-expansion \
	-Wno-switch-enum -Wno-missing-field-initializers -Wno-format-nonliteral \
	-Wno-reserved-id-macro -Wno-padded -Wno-covered-switch-default
 CFLAGS := -pedantic$(if $(DEBUG_SYMS), -g) $(CWARN)
 CXXWARN := $(CWARN) -Wno-c++98-compat -Wno-c++98-compat-pedantic \
	-Wno-vla -Wno-vla-extension -Wno-weak-vtables -Wno-covered-switch-default

 CXX := clang++
 LDXX := clang++
 CXXFLAGS := $(CXXWARN)

 RM := rm -f
 CP := cp
 MV := mv
 LN := ln -sf
 MD := mkdir -p
 INST := install

 RPCGEN := rpcgen

# ---
# Dépendances.
# ---
# libcurl, pour accéder au serveur en HTTP et FTP.

 DEP_libcurl_CFLAGS := $(shell pkg-config libcurl --cflags)
 DEP_libcurl_LIBS := $(shell pkg-config libcurl --libs)

# SunRPC, pour l'IPC entre la bibliothèque client et le démon.

 DEP_rpc_CFLAGS :=
 DEP_rpc_LIBS := -lnsl

# libwesh, soit la bibliothèque client.

 DEP_lib_CFLAGS := -I include/
 DEP_lib_LIBS := -L build -l$(LIB)

# ---
# Informations concernant les fichiers générés par SunRPC.
# ---
# Fichiers et dossiers concernés.

 S_FROM := ./weshd.x
 S_OBJDIR := ./build/rpc

 S_NAME := $(patsubst %.x,%,$(notdir $(S_FROM)))

# ---
# Informations concernant le démon.
# ---
# Dépendances et options.

 D_DEPS := libcurl rpc

 D_CFLAGS := $(CFLAGS) $(foreach x,$(D_DEPS),$(DEP_$(x)_CFLAGS)) \
	-I $(S_OBJDIR) -D NOLOGO=$(NO_LOGO) -D DEFAULT_LOGLEVEL=WL$(LOG_LEVEL) \
	-D WESHD_VERSION="\"$(VERSION)\"" -D WESHD_MAINT="\"$(MAINTAINER)\"" \
	-D DELETE_SCRIPTS="$(if $(DELETE_SCRIPTS),$(DELETE_SCRIPTS),1)" \
	-D CURLHTTPVERBOSE="$(if $(CURL_HTTP_VERBOSE),$(CURL_HTTP_VERBOSE),0)L" \
	-D CURLFTPVERBOSE="$(if $(CURL_FTP_VERBOSE),$(CURL_FTP_VERBOSE),0)L"
 D_LIBS := $(foreach x,$(D_DEPS),$(DEP_$(x)_LIBS))

# Dossiers le concernant.

 D_DEST := ./build/$(DAEMON)
 D_SRCDIR := ./daemon
 D_OBJDIR := ./build/daemon

# Recherche de ses sources.

 D_SRC := \
	$(patsubst $(D_SRCDIR)/%,%,$(wildcard $(D_SRCDIR)/*.c $(D_SRCDIR)/**/*.c))
 D_OBJ := $(D_SRC:%=$(D_OBJDIR)/%.o) \
	$(S_OBJDIR)/$(S_NAME)_xdr.c.o $(S_OBJDIR)/$(S_NAME)_svc.c.o
 D_INC := $(wildcard $(D_SRCDIR)/*.h $(D_SRCDIR)/**/*.h) \
	$(S_OBJDIR)/$(S_NAME).h

# ---
# Informations concernant la bibliothèque client.
# ---
# Dossiers la concernant.

 L_DEST := ./build/lib$(LIB).so
 L_PKG := ./build/lib$(LIB).pc

 L_SRCDIR := ./lib
 L_INCDIR := ./include
 L_OBJDIR := ./build/lib

# Recherche de ses sources.

 L_SRC := \
	$(patsubst $(L_SRCDIR)/%,%,$(wildcard $(L_SRCDIR)/*.cpp))
 L_OBJ := $(L_SRC:%=$(L_OBJDIR)/%.o) \
	$(S_OBJDIR)/$(S_NAME)_xdr.c.o $(S_OBJDIR)/$(S_NAME)_clnt.c.o
 L_INCp := $(patsubst $(L_INCDIR)/%,%,$(wildcard \
	$(L_INCDIR)/*.hpp $(L_INCDIR)/**/*.hpp))
 L_INC := $(L_INCp:%=$(L_INCDIR)) $(S_OBJDIR)/$(S_NAME).h \
	$(wildcard $(L_SRCDIR)/*.hpp $(L_SRCDIR)/**/*.hpp)

# Dépendances et options.

 L_DEPS :=

 L_CXXFLAGS := $(CXXFLAGS) $(foreach x,$(L_DEPS),$(DEP_$(x)_CFLAGS)) \
	-I $(S_OBJDIR) -fPIC -I $(L_INCDIR)
 L_LIBS := $(foreach x,$(L_DEPS),$(DEP_$(x)_LIBS))
 L_LDFLAGS := $(L_LIBS) -shared -Wl,-z,relro -Wl,-z,combreloc -Wl,-z,defs \
	-Wl,-soname,lib$(LIB).so.$(MAJOR)

# ---
# Informations concernant le client de base.
# ---
# Dossiers le concernant.

 C_DEST := ./build/$(CLIENT)
 C_SRCDIR := ./client
 C_OBJDIR := ./build/client

# Recherche de ses sources.

 C_SRC := \
	$(patsubst $(C_SRCDIR)/%,%,$(wildcard $(C_SRCDIR)/*.cpp))
 C_OBJ := $(C_SRC:%=$(C_OBJDIR)/%.o) \
	$(S_OBJDIR)/$(S_NAME)_xdr.c.o $(S_OBJDIR)/$(S_NAME)_clnt.c.o
 C_INC := $(wildcard $(C_SRCDIR)/*.hpp) $(wildcard $(L_INCDIR)/*.hpp) \
	$(S_OBJDIR)/$(S_NAME).h

# Dépendances et options.

 C_DEPS := lib

 C_CXXFLAGS := $(CXXFLAGS) $(foreach x,$(C_DEPS),$(DEP_$(x)_CFLAGS))
 C_LIBS := $(foreach x,$(C_DEPS),$(DEP_$(x)_LIBS))
 C_LDFLAGS := $(C_LIBS)

# ---
# Vérification du DESTDIR (comme préfixe aux racines d'installation).
# ---

 OINCDIR := $(IINCDIR)
 OLIBDIR := $(ILIBDIR)

define add-dest-dir
 $1 = $(DESTDIR)$($1)
endef

$(if $(DESTDIR),$(foreach idir,IBINDIR IPKGDIR ILIBDIR IINCDIR,\
$(eval $(call add-dest-dir,$(idir)))))

# End of file.