-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile.base
More file actions
executable file
·217 lines (173 loc) · 5.85 KB
/
Makefile.base
File metadata and controls
executable file
·217 lines (173 loc) · 5.85 KB
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# Base Makefile providing various standard targets
# Part of mklove suite but may be used independently.
MKL_RED?= \033[031m
MKL_GREEN?= \033[032m
MKL_YELLOW?= \033[033m
MKL_BLUE?= \033[034m
MKL_CLR_RESET?= \033[0m
DEPS= $(OBJS:%.o=%.d)
# TOPDIR is "TOPDIR/mklove/../" i.e., TOPDIR.
# We do it with two dir calls instead of /.. to support mklove being symlinked.
MKLOVE_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
TOPDIR = $(MKLOVE_DIR:mklove/=.)
# Convert LIBNAME ("libxyz") to "xyz"
LIBNAME0=$(LIBNAME:lib%=%)
# Silence lousy default ARFLAGS (rv)
ARFLAGS=
ifndef MKL_MAKEFILE_CONFIG
-include $(TOPDIR)/Makefile.config
endif
_UNAME_S := $(shell uname -s)
ifeq ($(_UNAME_S),Darwin)
LIBFILENAME=$(LIBNAME).$(LIBVER)$(SOLIB_EXT)
LIBFILENAMELINK=$(LIBNAME)$(SOLIB_EXT)
else
LIBFILENAME=$(LIBNAME)$(SOLIB_EXT).$(LIBVER)
LIBFILENAMELINK=$(LIBNAME)$(SOLIB_EXT)
endif
INSTALL?= install
INSTALL_PROGRAM?= $(INSTALL)
INSTALL_DATA?= $(INSTALL) -m 644
prefix?= /usr/local
exec_prefix?= $(prefix)
bindir?= $(exec_prefix)/bin
sbindir?= $(exec_prefix)/sbin
libexecdir?= $(exec_prefix)/libexec/ # append PKGNAME on install
datarootdir?= $(prefix)/share
datadir?= $(datarootdir) # append PKGNAME on install
sysconfdir?= $(prefix)/etc
sharedstatedir?=$(prefix)/com
localestatedir?=$(prefix)/var
runstatedir?= $(localestatedir)/run
includedir?= $(prefix)/include
docdir?= $(datarootdir)/doc/$(PKGNAME)
infodir?= $(datarootdir)/info
libdir?= $(prefix)/lib
localedir?= $(datarootdir)/locale
pkgconfigdir?= $(libdir)/pkgconfig
mandir?= $(datarootdir)/man
man1dir?= $(mandir)/man1
man2dir?= $(mandir)/man2
man3dir?= $(mandir)/man3
man4dir?= $(mandir)/man4
man5dir?= $(mandir)/man5
man6dir?= $(mandir)/man6
man7dir?= $(mandir)/man7
man8dir?= $(mandir)/man8
# Checks that mklove is set up and ready for building
mklove-check:
@if [ ! -f "$(TOPDIR)/Makefile.config" ]; then \
printf "$(MKL_RED)$(TOPDIR)/Makefile.config missing: please run ./configure$(MKL_CLR_RESET)\n" ; \
exit 1 ; \
fi
%.o: %.c
$(CC) -MD -MP $(CPPFLAGS) $(CFLAGS) -c $< -o $@
%.o: %.cpp
$(CXX) -MD -MP $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@
lib: $(LIBFILENAME) $(LIBNAME).a $(LIBFILENAMELINK) lib-gen-pkg-config
$(LIBNAME).lds: #overridable
$(LIBFILENAME): $(OBJS) $(LIBNAME).lds
@printf "$(MKL_YELLOW)Creating shared library $@$(MKL_CLR_RESET)\n"
$(CC) $(LDFLAGS) $(LIB_LDFLAGS) $(OBJS) -o $@ $(LIBS)
$(LIBNAME).a: $(OBJS)
@printf "$(MKL_YELLOW)Creating static library $@$(MKL_CLR_RESET)\n"
$(AR) rcs$(ARFLAGS) $@ $(OBJS)
$(LIBFILENAMELINK): $(LIBFILENAME)
@printf "$(MKL_YELLOW)Creating $@ symlink$(MKL_CLR_RESET)\n"
rm -f "$@" && ln -s "$^" "$@"
# pkg-config .pc file definition
ifeq ($(GEN_PKG_CONFIG),y)
define _PKG_CONFIG_DEF
prefix=$(prefix)
libdir=$(libdir)
includedir=$(includedir)
Name: $(LIBNAME)
Description: $(MKL_APP_DESC_ONELINE)
Version: $(MKL_APP_VERSION)
Cflags: -I$${includedir}
Libs: -L$${libdir} -l$(LIBNAME0)
Libs.private: $(LIBS)
endef
export _PKG_CONFIG_DEF
define _PKG_CONFIG_STATIC_DEF
prefix=$(prefix)
libdir=$(libdir)
includedir=$(includedir)
Name: $(LIBNAME)-static
Description: $(MKL_APP_DESC_ONELINE) (static)
Version: $(MKL_APP_VERSION)
Cflags: -I$${includedir}
Libs: -L$${libdir} $${libdir}/$(LIBNAME).a $(LIBS)
endef
export _PKG_CONFIG_STATIC_DEF
$(LIBNAME0).pc: $(TOPDIR)/Makefile.config
@printf "$(MKL_YELLOW)Generating pkg-config file $@$(MKL_CLR_RESET)\n"
@echo "$$_PKG_CONFIG_DEF" > $@
$(LIBNAME0)-static.pc: $(TOPDIR)/Makefile.config
@printf "$(MKL_YELLOW)Generating pkg-config file $@$(MKL_CLR_RESET)\n"
@echo "$$_PKG_CONFIG_STATIC_DEF" > $@
lib-gen-pkg-config: $(LIBNAME0).pc $(LIBNAME0)-static.pc
lib-clean-pkg-config:
rm -f $(LIBNAME0).pc $(LIBNAME0)-static.pc
else
lib-gen-pkg-config:
lib-clean-pkg-config:
endif
$(BIN): $(OBJS)
@printf "$(MKL_YELLOW)Creating program $@$(MKL_CLR_RESET)\n"
$(CC) $(CPPFLAGS) $(LDFLAGS) $(OBJS) -o $@ $(LIBS)
file-check:
@printf "$(MKL_YELLOW)Checking $(LIBNAME) integrity$(MKL_CLR_RESET)\n"
@RET=true ; \
for f in $(CHECK_FILES) ; do \
printf "%-30s " $$f ; \
if [ -f "$$f" ]; then \
printf "$(MKL_GREEN)OK$(MKL_CLR_RESET)\n" ; \
else \
printf "$(MKL_RED)MISSING$(MKL_CLR_RESET)\n" ; \
RET=false ; \
fi ; \
done ; \
$$RET
lib-install:
@printf "$(MKL_YELLOW)Install $(LIBNAME) to $$DESTDIR$(prefix)$(MKL_CLR_RESET)\n"
$(INSTALL) -d $$DESTDIR$(includedir)/$(PKGNAME) ; \
$(INSTALL) -d $$DESTDIR$(libdir) ; \
$(INSTALL) $(HDRS) $$DESTDIR$(includedir)/$(PKGNAME) ; \
$(INSTALL) $(LIBNAME).a $$DESTDIR$(libdir) ; \
$(INSTALL) $(LIBFILENAME) $$DESTDIR$(libdir) ; \
[ -f "$(LIBNAME0).pc" ] && ( \
$(INSTALL) -d $$DESTDIR$(pkgconfigdir) ; \
$(INSTALL) -m 0644 $(LIBNAME0).pc $$DESTDIR$(pkgconfigdir) \
) ; \
[ -f "$(LIBNAME0)-static.pc" ] && ( \
$(INSTALL) -d $$DESTDIR$(pkgconfigdir) ; \
$(INSTALL) -m 0644 $(LIBNAME0)-static.pc $$DESTDIR$(pkgconfigdir) \
) ; \
(cd $$DESTDIR$(libdir) && ln -sf $(LIBFILENAME) $(LIBFILENAMELINK))
lib-uninstall:
@printf "$(MKL_YELLOW)Uninstall $(LIBNAME) from $$DESTDIR$(prefix)$(MKL_CLR_RESET)\n"
for hdr in $(HDRS) ; do \
rm -f $$DESTDIR$(includedir)/$(PKGNAME)/$$hdr ; done
rm -f $$DESTDIR$(libdir)/$(LIBNAME).a
rm -f $$DESTDIR$(libdir)/$(LIBFILENAME)
rm -f $$DESTDIR$(libdir)/$(LIBFILENAMELINK)
rmdir $$DESTDIR$(includedir)/$(PKGNAME) || true
rm -f $$DESTDIR$(pkgconfigdir)/$(LIBNAME0).pc
rm -f $$DESTDIR$(pkgconfigdir)/$(LIBNAME0)-static.pc
rmdir $$DESTDIR$(pkgconfigdir) || true
bin-install:
@printf "$(MKL_YELLOW)Install $(BIN) to $$DESTDIR$(prefix)$(MKL_CLR_RESET)\n"
$(INSTALL) -d $$DESTDIR$(bindir) && \
$(INSTALL) $(BIN) $$DESTDIR$(bindir)
bin-uninstall:
@printf "$(MKL_YELLOW)Uninstall $(BIN) from $$DESTDIR$(prefix)$(MKL_CLR_RESET)\n"
rm -f $$DESTDIR$(bindir)/$(BIN)
rmdir $$DESTDIR$(bindir) || true
generic-clean:
rm -f $(OBJS) $(DEPS)
lib-clean: generic-clean lib-clean-pkg-config
rm -f $(LIBNAME)*.a $(LIBFILENAME) $(LIBFILENAMELINK) \
$(LIBNAME).lds
bin-clean: generic-clean
rm -f $(BIN)