1# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
2#
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License, version 2.0,
5# as published by the Free Software Foundation.
6#
7# This program is also distributed with certain software (including
8# but not limited to OpenSSL) that is licensed under separate terms,
9# as designated in a particular file or component or in included license
10# documentation.  The authors of MySQL hereby grant you an additional
11# permission to link the program and your derivative works with the
12# separately licensed software that they have included with MySQL.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17# GNU General Public License, version 2.0, for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program; if not, write to the Free Software
21# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
22#------------------------------------------------------------------------------
23
24# Default Variables Section:
25
26# to avoid problems where SHELL is inherited from the environment
27  SHELL = /bin/sh
28
29######	Target:
30  TARGET_ARCH	=
31
32######	C Preprocessor:
33#  CPP		= cpp
34  CPP		= $(CC) -E
35  CPPFLAGS	= $(DDEFINES) $(INCLUDES)
36
37# gnu ccp:
38# -M Generates make dependencies.
39# -MM Similar to -M, but ignores system header files.
40# -MD Similar to -M, but puts output in a .d file.
41# -MMD Similar to -MD, but ignores system header files.
42# -MG Treats missing header files as generated files.
43  MAKEDEPEND	= $(CPP) -MM $(CPPFLAGS)
44#  MAKEDEPEND	= makedepend
45
46######	C Compiler:
47
48  CC	   	= gcc
49# plain cc, debug:
50#  CFLAGS	= -g -DDEBUG
51# gnu gcc, general: -pedantic -ansi -std=c89 -std=c99 -std=gnu89 -std=gnu99
52  CFLAGS.gen	= -Wall
53# gnu gcc, default:
54  CFLAGS	= $(CFLAGS.gen) -g -O
55# gnu gcc, debug:
56  CFLAGS.dbg	= $(CFLAGS.gen) -g -DDEBUG
57# gnu gcc, optimize: -funroll-all-loops -fomit-frame-pointer
58  CFLAGS.opt 	= $(CFLAGS.gen) -DNDEBUG -O3
59# gnu gcc, profile:
60  CFLAGS.prf 	= $(CFLAGS.opt) -pg
61
62#  CC	   	= cc
63# Sun cc, debug:
64#  CFLAGS	= -g -v -Xc -DDEBUG
65# Sun cc, optimize:
66#  CFLAGS	= -fast -xO4 -Xc -DNDEBUG
67
68######	C++ Compiler:
69
70  CXX  		= g++
71# gnu g++, general: -pedantic -ansi -std=c++98 -std=gnu++98
72#   -fabi-version=2 -fabi-version=1 -fabi-version=0
73#   -fno-implicit-templates -fno-implicit-inline-templates -frepo
74#   -Weffc++
75#      Unfortunately, -Weffc++ issues broad warnings that cannot be
76#      individually suppressed by -Wno-... (e.g. -Wno-non-virtual-dtor);
77#      therefore, we generally leave out -Weffc++
78#   -Wold-style-cast
79#   -Woverloaded-virtual
80#      Unfortunately, too many warnings from NDB includes
81  CXXFLAGS.gen	= -ansi -Wall -Wstrict-null-sentinel \
82		  -Wsign-promo
83# gnu g++, default:
84  CXXFLAGS	= $(CXXFLAGS.gen) -g -O
85  CXXFLAGS.dbg	= $(CXXFLAGS.gen) -g -DDEBUG
86# gnu g++, optimize: -fomit-frame-pointer
87  CXXFLAGS.opt 	= $(CXXFLAGS.gen) -O3 -DNDEBUG
88# gnu g++, profile:
89  CXXFLAGS.prf 	= $(CXXFLAGS.opt) -pg
90
91#  CXX  	= CC
92# Sun CC, debug: not used: -ptv, particularly -pta !
93#  CXXFLAGS 	= -g +d +w +p -DDEBUG
94# Sun CC, optimize:
95#  CXXFLAGS 	=  -fast -O4 -DNDEBUG
96
97######	Java Compiler:
98
99  JAVAC  	= javac
100  JAVACFLAGS  	=
101
102  JAVAH  	= javah
103  JAVAHFLAGS  	= -jni -force
104
105  JAVA  	= java
106  JAVAFLAGS  	=
107
108  JAR		= jar
109  JARFLAGS  	=
110
111######	Linker:
112#  LD		= ld
113  LD		= $(CC)
114#  LD		= $(CXX)
115# gnu ld, general: -static
116  LDFLAGS.gen	=
117# gnu ld, default:
118  LDFLAGS	= $(LDFLAGS.gen)
119# gnu ld, debug:
120  LDFLAGS.dbg	= $(LDFLAGS.gen)
121# gnu ld, optimize: -s
122  LDFLAGS.opt	= $(LDFLAGS.gen)
123# gnu ld, profile: -S
124  LDFLAGS.prf	= $(LDFLAGS.gen)
125
126# -Bdynamic, -dy, -call_shared
127# link against dynamic libraries.
128
129# -Bstatic, -dn, -non_shared, -static
130# do not link against shared libraries; can be used with -shared;
131# means that a shared library is being created but that all of the
132# library’s external references must be resolved by pulling in
133# entries from static libraries.
134
135# -shared, -Bshareable
136# create a shared library. On SunOS, the linker will automatically
137# create a shared library if the -e option is not used and there are
138# undefined symbols in the link.
139
140# can link some libraries statically and others dynamically:
141#  gcc -o some-program some-program.c -Xlinker
142#      -Bstatic -llib1 -lib2 -Xlinker -Bdynamic -llib3
143
144# to check the dynamic load library: use ldd to invoke executables, which
145# dumps their library dependencies
146#
147# by default (Linux) only /lib and /usr/lib are searched for shared libs;
148# can use -W1, -rpath option when linking or set the LD_LIBRARY_PATH
149# environment variable when running the program
150
151######	Library-Archiver:
152  AR		= ar
153  ARFLAGS	= rv
154#  ARFLAGS	= rvu
155#  RANLIB	= ranlib
156
157# r	insert the files member... into archive (with replacement)
158# u	only insert those files newer than existing members of the same names
159# v	request the verbose version of an operation
160
161# ranlib updates '__.SYMDEF' member (directory of the external symbol names)
162# not needed with GNU ar, which updates the `__.SYMDEF' member automatically
163
164#------------------------------------------------------------------------------
165
166# Default Targets Section:
167
168.PHONY:	dep depend dbg opt prf clean mostlyclean clobber distclean check
169
170help:
171
172dep depend:
173	@set -e; \
174	rm -f .depend .depend$$$$ ; touch _dummy.c _dummy.cc _dummy.cpp; \
175	$(MAKEDEPEND) *.c *.cc *.cpp > .depend.$$$$; \
176	rm -f _dummy.c _dummy.cc _dummy.cpp; mv .depend.$$$$ .depend
177
178# other options:
179#	$(CXX) -E -MM $(CPPFLAGS) *.cpp > .tmp
180
181dbg:
182	@$(MAKE) $(MFLAGS) \
183		CFLAGS='$(CFLAGS.dbg)' \
184		CXXFLAGS='$(CXXFLAGS.dbg)' \
185		LDFLAGS='$(LDFLAGS.dbg)' \
186		all
187opt:
188	@$(MAKE) $(MFLAGS) \
189		CFLAGS='$(CFLAGS.opt)' \
190		CXXFLAGS='$(CXXFLAGS.opt)' \
191		LDFLAGS='$(LDFLAGS.opt)' \
192		all
193
194prf:
195	@$(MAKE) $(MFLAGS) \
196		CFLAGS='$(CFLAGS.prf)' \
197		CXXFLAGS='$(CXXFLAGS.prf)' \
198		LDFLAGS='$(LDFLAGS.prf)' \
199		all
200
201clean:
202	rm -rf $(CLEAN) .tmp
203
204# library-archiving removes .o files with empty .depend file,
205# so, better delete it only as part of mostlyclean
206mostlyclean clobber:	clean
207	rm -rf $(MOSTLYCLEAN) .depend
208
209distclean:	mostlyclean
210	rm -rf $(DISTCLEAN)
211
212#------------------------------------------------------------------------------
213
214# Default Rules Section:
215
216# for Solaris make compatibility check:
217#   http://www.ibm.com/developerworks/eserver/articles/porting_linux/
218
219# good idea to clear&set the suffix list explicitly with only the ones needed
220.SUFFIXES:
221.SUFFIXES: .h .c .cc .cpp .o .a .so .dylib
222
223# use "$<" and "$@", not hardcoded names for `VPATH' to work correctly
224
225# better not use single- or double-suffix rules, for:
226#	".c.o:" == "%.o: %.c"
227#	".c"	== "% : %.c"
228# but:	".c.o: foo.h" != "%.o: %.c foo.h"
229
230######	Generate Dependencies:
231  ADD_D_TARGET	= sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g'
232
233  GENERATE.c	= @set -e; rm -f $@; \
234		$(CC) -MM $(CFLAGS) $(CPPFLAGS) $< | \
235		$(ADD_D_TARGET) > $@
236
237  GENERATE.cc	= @set -e; rm -f $@; \
238		$(CXX) -MM $(CXXFLAGS) $(CPPFLAGS) $< | \
239		$(ADD_D_TARGET) > $@
240
241  GENERATE.cpp	= $(GENERATE.cc)
242
243%.d: %.c
244	$(GENERATE.c)
245
246%.d: %.cc
247	$(GENERATE.cc)
248
249%.d: %.cpp
250	$(GENERATE.cpp)
251
252######	Compile:
253  COMPILE.c	= $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c
254
255  COMPILE.cc	= $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c
256
257  COMPILE.cpp	= $(COMPILE.cc)
258
259  OUTPUT_OPTION	= -o $@
260
261  COMPILE.java	= $(JAVAC) $(JAVACFLAGS) -classpath $(CLASSPATH)
262
263  COMPILE.javah	= $(JAVAH) $(JAVAHFLAGS) -classpath $(CLASSPATH)
264
265%.o: %.c
266	$(COMPILE.c) $(OUTPUT_OPTION) $<
267
268%.o: %.cc
269	$(COMPILE.cc) $(OUTPUT_OPTION) $<
270
271%.o: %.cpp
272	$(COMPILE.cpp) $(OUTPUT_OPTION) $<
273
274%.class: %.java
275	$(COMPILE.java) $<
276
277######	Link:
278  LINK.c	= $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)
279
280  LINK.cc	= $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)
281
282  LINK.cpp	= $(LINK.cc)
283
284  LINK.o	= $(CC) $(LDFLAGS) $(TARGET_ARCH)
285
286%: %.c
287	$(LINK.c) $^ $(LOADLIBES) $(LDLIBS) -o $@
288
289%: %.cc
290	$(LINK.cc) $^ $(LOADLIBES) $(LDLIBS) -o $@
291
292%: %.cpp
293	$(LINK.cpp) $^ $(LOADLIBES) $(LDLIBS) -o $@
294
295%: %.o
296	$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@
297
298# support shared libraries:
299
300#DLL_SUFFIX=dylib
301#DLL_SUFFIX=so
302DLL_SUFFIX=$(if $(findstring Darwin,$(shell uname)),dylib,so)
303
304# XXX unify shared lib rules in makefile using DLL_FLAGS
305# however, it might be, that .so is/works the same on MacOS X
306ifeq (findstring Darwin,$(shell uname))
307DLL_FLAGS=-fPIC -dynamiclib
308else
309DLL_FLAGS=-fPIC -shared
310endif
311#
312# XXX check against compiler/linker flags descriptions above...
313# GCC man on -fPIC v -fpic:
314# to build shared libraries with -fast, specify -fPIC at compilation
315#   XXX cannot use -fast, not supported on MacOS X gcc
316# Mac OS X: -fpic is not supported, -fPIC is the default
317# SPARC, m68k, PowerPC: -fpic has size limits but faster (?) than -fPIC
318# 386: -fpic (if supported) same (?) performance as -fPIC
319#
320# XXX try:
321#xxx.dylib:
322#	libtool -dynamic -undefined dynamic_lookup -o $@ yyy.o ...
323#
324#xxx.so:
325#	$(LINK.cpp) -shared -o $@ yyy.o ... VERSION
326
327######	Library-Archive:
328
329# general form
330# lib.a: $(OBJ)
331#        $(AR) rvu $@ $<
332#        $(RANLIB) $@
333
334# gnu make has special support for lib(o) targets; this rule
335# (%): %
336#	$(AR) $(ARFLAGS) $@ $<
337# allows to specify lib targets simply as:
338# lib.a: lib.a(a.o b.o ...) lib.a(c.o)...
339#
340# !!! be careful when using parallel make execution and archives !!!
341# If multiple ar commands run at the same time on the same archive file,
342# they will not know about each other and can corrupt the file.
343# May be fixed in future.
344
345(%): %
346	$(AR) $(ARFLAGS) $@ $<
347
348#------------------------------------------------------------------------------
349