xref: /trunk/main/solenv/gbuild/platform/linux.mk (revision 5f3b9f77)
1#**************************************************************
2#
3#  Licensed to the Apache Software Foundation (ASF) under one
4#  or more contributor license agreements.  See the NOTICE file
5#  distributed with this work for additional information
6#  regarding copyright ownership.  The ASF licenses this file
7#  to you under the Apache License, Version 2.0 (the
8#  "License"); you may not use this file except in compliance
9#  with the License.  You may obtain a copy of the License at
10#
11#    http://www.apache.org/licenses/LICENSE-2.0
12#
13#  Unless required by applicable law or agreed to in writing,
14#  software distributed under the License is distributed on an
15#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16#  KIND, either express or implied.  See the License for the
17#  specific language governing permissions and limitations
18#  under the License.
19#
20#**************************************************************
21
22
23
24GUI := UNX
25
26gb_MKTEMP := mktemp -t gbuild.XXXXXX
27
28gb_CC := gcc
29gb_CXX := g++
30gb_GCCP := gcc
31gb_AR := ar
32gb_AWK := awk
33gb_CLASSPATHSEP := :
34
35# normalize setsolar and configure env.
36ifeq ($(CPU),X)
37CPUNAME := X86_64
38endif
39
40# use CC/CXX if they are nondefaults
41ifneq ($(origin CC),default)
42gb_CC := $(CC)
43gb_GCCP := $(CC)
44endif
45ifneq ($(origin CXX),default)
46gb_CXX := $(CXX)
47endif
48
49gb_OSDEFS := \
50	-D$(OS) \
51	-D_PTHREADS \
52	-DUNIX \
53	-DUNX \
54	$(PTHREAD_CFLAGS) \
55
56gb_COMPILERDEFS := \
57	-D$(COM) \
58	-DHAVE_GCC_VISIBILITY_FEATURE \
59	-DCPPU_ENV=$(COMNAME) \
60
61gb_CPUDEFS := -D$(ALIGN) -D$(CPUNAME)
62ifeq ($(CPUNAME),INTEL)
63gb_CPUDEFS += -DX86
64endif
65
66gb_CFLAGS := \
67	-Wall \
68	-Wendif-labels \
69	-Wextra \
70	-Wshadow \
71	-fPIC \
72	-fmessage-length=0 \
73	-fno-common \
74	-fno-strict-aliasing \
75	-fvisibility=hidden \
76	-pipe \
77
78gb_CXXFLAGS := \
79	-Wall \
80	-Wendif-labels \
81	-Wextra \
82	-Wno-ctor-dtor-privacy \
83	-Wno-non-virtual-dtor \
84	-Wshadow \
85	-fPIC \
86	-fmessage-length=0 \
87	-fno-common \
88	-fno-strict-aliasing \
89	-fuse-cxa-atexit \
90	-fvisibility-inlines-hidden \
91	-fvisibility=hidden \
92	-std=gnu++98 \
93	-pipe \
94
95ifneq ($(EXTERNAL_WARNINGS_NOT_ERRORS),TRUE)
96gb_CFLAGS_WERROR := -Werror
97gb_CXXFLAGS_WERROR := -Werror
98endif
99
100ifneq ($(strip $(SYSBASE)),)
101gb_CXXFLAGS += --sysroot=$(SYSBASE)
102gb_CFLAGS += --sysroot=$(SYSBASE)
103gb_LinkTarget_LDFLAGS := -Wl,--sysroot=$(SYSBASE)
104endif
105gb_LinkTarget_EXCEPTIONFLAGS := \
106	-DEXCEPTIONS_ON \
107	-fexceptions
108ifeq ($(COM),GCC)
109gb_LinkTarget_EXCEPTIONFLAGS +=  -fno-enforce-eh-specs
110endif
111
112gb_LinkTarget_NOEXCEPTIONFLAGS := \
113	-DEXCEPTIONS_OFF \
114	-fno-exceptions \
115
116gb_LinkTarget_LDFLAGS += \
117	-Wl,-rpath-link,$(SYSBASE)/lib:$(SYSBASE)/usr/lib \
118	-Wl,-z,combreloc \
119	-Wl,-z,defs \
120	$(subst -L../lib , ,$(SOLARLIB)) \
121
122ifeq ($(HAVE_LD_HASH_STYLE),TRUE)
123gb_LinkTarget_LDFLAGS += \
124	-Wl,--hash-style=both \
125
126endif
127
128ifneq ($(HAVE_LD_BSYMBOLIC_FUNCTIONS),)
129gb_LinkTarget_LDFLAGS += \
130	-Wl,--dynamic-list-cpp-new \
131	-Wl,--dynamic-list-cpp-typeinfo \
132	-Wl,-Bsymbolic-functions \
133
134endif
135
136ifeq ($(gb_DEBUGLEVEL),0)
137gb_LinkTarget_LDFLAGS += -Wl,-O1
138endif
139
140ifeq ($(COM),CLANG)
141ifeq ($(ENABLE_SYMBOLS),SMALL)
142gb_DEBUG_CFLAGS := -ggdb1 -fno-inline
143else
144gb_DEBUG_CFLAGS := -ggdb3 -fno-inline
145endif
146else
147ifeq ($(ENABLE_SYMBOLS),SMALL)
148gb_DEBUG_CFLAGS := -ggdb1 -finline-limit=0 -fno-inline -fno-default-inline
149else
150gb_DEBUG_CFLAGS := -ggdb3 -finline-limit=0 -fno-inline -fno-default-inline
151endif
152endif
153
154ifeq ($(gb_DEBUGLEVEL),2)
155gb_COMPILEROPTFLAGS := -O0
156gb_COMPILEROPT1FLAGS := -O0
157else
158gb_COMPILEROPTFLAGS := -Os
159gb_COMPILEROPT1FLAGS := -O1
160endif
161
162gb_COMPILERNOOPTFLAGS := -O0
163
164# Helper class
165
166gb_Helper_abbreviate_dirs_native = $(gb_Helper_abbreviate_dirs)
167
168# convert parametters filesystem root to native notation
169# does some real work only on windows, make sure not to
170# break the dummy implementations on unx*
171define gb_Helper_convert_native
172$(1)
173endef
174
175# AsmObject class
176
177gb_AsmObject_EXT := .s
178
179define gb_AsmObject__command
180$(call gb_Output_announce,$(2),$(true),ASM,3)
181$(call gb_Helper_abbreviate_dirs,\
182	mkdir -p $(dir $(1)) && \
183	$(gb_CC) \
184		$(DEFS) \
185		$(T_CFLAGS) \
186		$(CFLAGS) \
187		-c $(3) \
188		-o $(1) \
189		-MT $(1) \
190		-I$(dir $(3)) \
191		$(INCLUDE))
192endef
193
194# CObject class
195
196# $(call gb_CObject__command,object,relative-source,source,dep-file)
197define gb_CObject__command
198$(call gb_Output_announce,$(2),$(true),C  ,3)
199$(call gb_Helper_abbreviate_dirs,\
200	mkdir -p $(dir $(1)) $(dir $(4)) && \
201	$(gb_CC) \
202		$(DEFS) \
203		$(T_CFLAGS) \
204		$(CFLAGS) \
205		-c $(3) \
206		-o $(1) \
207		-MMD -MT $(1) \
208		-MF $(4) \
209		-I$(dir $(3)) \
210		$(INCLUDE))
211endef
212
213# convert parametters filesystem root to native notation
214# does some real work only on windows, make sure not to
215# break the dummy implementations on unx*
216define gb_Helper_convert_native
217$(1)
218endef
219
220# CxxObject class
221
222# $(call gb_CxxObject__command,object,relative-source,source,dep-file)
223define gb_CxxObject__command
224$(call gb_Output_announce,$(2),$(true),CXX,3)
225$(call gb_Helper_abbreviate_dirs,\
226	mkdir -p $(dir $(1)) $(dir $(4)) && \
227	$(gb_CXX) \
228		$(DEFS) \
229		$(T_CXXFLAGS) \
230		$(CXXFLAGS) \
231		-c $(3) \
232		-o $(1) \
233		-MMD -MT $(1) \
234		-MF $(4) \
235		-I$(dir $(3)) \
236		$(INCLUDE_STL) $(INCLUDE))
237endef
238
239
240# LinkTarget class
241
242define gb_LinkTarget__get_rpath_for_layer
243$(patsubst $(1):%,%,$(filter $(1):%,$(gb_LinkTarget__RPATHS)))
244endef
245
246gb_LinkTarget__RPATHS := \
247	URELIB:\dORIGIN \
248	UREBIN:\dORIGIN/../lib:\dORIGIN \
249	OOO:\dORIGIN:\dORIGIN/../ure-link/lib \
250	BRAND:\dORIGIN:\dORIGIN/../basis-link/program:\dORIGIN/../basis-link/ure-link/lib \
251	SDKBIN:\dORIGIN/../../ure-link/lib \
252	NONEBIN:\dORIGIN/../lib:\dORIGIN \
253
254gb_LinkTarget_CFLAGS := $(gb_CFLAGS) $(gb_CFLAGS_WERROR)
255gb_LinkTarget_CXXFLAGS := $(gb_CXXFLAGS) $(gb_CXXFLAGS_WERROR)
256
257
258gb_LinkTarget_INCLUDE := $(filter-out %/stl, $(subst -I. , ,$(SOLARINC)))
259gb_LinkTarget_INCLUDE_STL := $(filter %/stl, $(subst -I. , ,$(SOLARINC)))
260
261define gb_LinkTarget__command_dynamiclink
262$(call gb_Helper_abbreviate_dirs,\
263	mkdir -p $(dir $(1)) && \
264	$(gb_CXX) \
265		$(if $(filter Library,$(TARGETTYPE)),$(gb_Library_TARGETTYPEFLAGS)) \
266		$(if $(VERSIONMAP),$(gb_Library_VERSIONMAPFLAG) $(VERSIONMAP)) \
267		$(if $(call gb_Library_is_udk_versioned,$(1)),-Wl$(COMMA)-h$(notdir $(1)).$(gb_UDK_MAJOR)) \
268		$(subst \d,$$,$(RPATH)) \
269		$(T_LDFLAGS) \
270		$(foreach object,$(ASMOBJECTS),$(call gb_AsmObject_get_target,$(object))) \
271		$(foreach object,$(COBJECTS),$(call gb_CObject_get_target,$(object))) \
272		$(foreach object,$(CXXOBJECTS),$(call gb_CxxObject_get_target,$(object))) \
273		$(foreach object,$(GENCOBJECTS),$(call gb_GenCObject_get_target,$(object))) \
274		$(foreach object,$(GENCXXOBJECTS),$(call gb_GenCxxObject_get_target,$(object))) \
275		-Wl$(COMMA)--start-group $(foreach lib,$(LINKED_STATIC_LIBS),$(call gb_StaticLibrary_get_target,$(lib))) -Wl$(COMMA)--end-group \
276		$(patsubst lib%.so,-l%,$(foreach lib,$(LINKED_LIBS),$(call gb_Library_get_filename,$(lib)))) \
277		$(patsubst %,-l%,$(EXTERNAL_LIBS)) \
278		$(LIBS) \
279		-lc \
280		-o $(if $(call gb_Library_is_udk_versioned,$(1)),$(1).$(gb_UDK_MAJOR),$(1)))
281endef
282
283define gb_LinkTarget__command_symlink_udk_versioned_library
284	$(if $(call gb_Library_is_udk_versioned,$(1)),
285		$(call gb_Helper_abbreviate_dirs,\
286			rm -f $(1) && ln -s $(notdir $(1)).$(gb_UDK_MAJOR) $(1)))
287endef
288
289define gb_LinkTarget__command_staticlink
290$(call gb_Helper_abbreviate_dirs,\
291	mkdir -p $(dir $(1)) && \
292	$(gb_AR) -rsu $(1) \
293		$(foreach object,$(COBJECTS),$(call gb_CObject_get_target,$(object))) \
294		$(foreach object,$(CXXOBJECTS),$(call gb_CxxObject_get_target,$(object))) \
295		$(foreach object,$(GENCOBJECTS),$(call gb_GenCObject_get_target,$(object))) \
296		$(foreach object,$(GENCXXOBJECTS),$(call gb_GenCxxObject_get_target,$(object))) \
297		2> /dev/null)
298endef
299
300define gb_LinkTarget__command
301$(call gb_Output_announce,$(2),$(true),LNK,4)
302$(if $(filter Library GoogleTest Executable,$(TARGETTYPE)),$(call gb_LinkTarget__command_dynamiclink,$(1)))
303$(if $(filter Library,$(TARGETTYPE)),$(call gb_LinkTarget__command_symlink_udk_versioned_library,$(1)))
304$(if $(filter StaticLibrary,$(TARGETTYPE)),$(call gb_LinkTarget__command_staticlink,$(1)))
305endef
306
307
308# Library class
309
310gb_Library_DEFS :=
311gb_Library_TARGETTYPEFLAGS := -shared -Wl,-z,noexecstack
312gb_Library_SYSPRE := lib
313gb_Library_UNOVERPRE := $(gb_Library_SYSPRE)uno_
314gb_Library_PLAINEXT := .so
315gb_Library_RTEXT := gcc3$(gb_Library_PLAINEXT)
316ifeq ($(gb_PRODUCT),$(true))
317gb_Library_STLEXT := port_gcc$(gb_Library_PLAINEXT)
318else
319gb_Library_STLEXT := port_gcc_stldebug$(gb_Library_PLAINEXT)
320endif
321gb_Library_VERSIONMAPFLAG := -Wl,--version-script
322
323ifeq ($(CPUNAME),X86_64)
324gb_Library_OOOEXT := $(gb_Library_PLAINEXT)
325gb_Library_UNOEXT := .uno$(gb_Library_PLAINEXT)
326else
327gb_Library_OOOEXT := $(gb_Library_PLAINEXT)
328gb_Library_UNOEXT := .uno$(gb_Library_PLAINEXT)
329endif
330
331gb_Library_PLAINLIBS_NONE += \
332	fontconfig \
333	Xrender \
334	dl \
335	freetype \
336	m \
337	pthread \
338	X11 \
339	Xext \
340	SM \
341	ICE
342
343gb_Library_FILENAMES := \
344	$(foreach lib,$(gb_Library_OOOLIBS),$(lib):$(gb_Library_SYSPRE)$(lib)$(gb_Library_OOOEXT)) \
345	$(foreach lib,$(gb_Library_PLAINLIBS_NONE),$(lib):$(gb_Library_SYSPRE)$(lib)$(gb_Library_PLAINEXT)) \
346	$(foreach lib,$(gb_Library_PLAINLIBS_URE),$(lib):$(gb_Library_SYSPRE)$(lib)$(gb_Library_PLAINEXT)) \
347	$(foreach lib,$(gb_Library_PLAINLIBS_OOO),$(lib):$(gb_Library_SYSPRE)$(lib)$(gb_Library_PLAINEXT)) \
348	$(foreach lib,$(gb_Library_RTLIBS),$(lib):$(gb_Library_SYSPRE)$(lib)$(gb_Library_RTEXT)) \
349	$(foreach lib,$(gb_Library_RTVERLIBS),$(lib):$(gb_Library_SYSPRE)$(lib)$(gb_Library_RTEXT)) \
350	$(foreach lib,$(gb_Library_STLLIBS),$(lib):$(gb_Library_SYSPRE)$(lib)$(gb_Library_STLEXT)) \
351	$(foreach lib,$(gb_Library_UNOLIBS_URE),$(lib):$(lib)$(gb_Library_UNOEXT)) \
352	$(foreach lib,$(gb_Library_UNOLIBS_OOO),$(lib):$(lib)$(gb_Library_UNOEXT)) \
353	$(foreach lib,$(gb_Library_UNOVERLIBS),$(lib):$(gb_Library_UNOVERPRE)$(lib)$(gb_Library_PLAINEXT)) \
354
355
356gb_Library_LAYER := \
357	$(foreach lib,$(gb_Library_OOOLIBS),$(lib):OOO) \
358	$(foreach lib,$(gb_Library_PLAINLIBS_URE),$(lib):URELIB) \
359	$(foreach lib,$(gb_Library_PLAINLIBS_OOO),$(lib):OOO) \
360	$(foreach lib,$(gb_Library_RTLIBS),$(lib):OOO) \
361	$(foreach lib,$(gb_Library_RTVERLIBS),$(lib):URELIB) \
362	$(foreach lib,$(gb_Library_STLLIBS),$(lib):URELIB) \
363	$(foreach lib,$(gb_Library_UNOLIBS_URE),$(lib):URELIB) \
364	$(foreach lib,$(gb_Library_UNOLIBS_OOO),$(lib):OOO) \
365	$(foreach lib,$(gb_Library_UNOVERLIBS),$(lib):URELIB) \
366
367define gb_Library_get_rpath
368'-Wl,-rpath,$(call gb_LinkTarget__get_rpath_for_layer,$(call gb_Library_get_layer,$(1)))' \
369'-Wl,-rpath-link,$(gb_Library_OUTDIRLOCATION)'
370endef
371
372define gb_Library_Library_platform
373$(call gb_LinkTarget_get_target,$(2)) : RPATH := $(call gb_Library_get_rpath,$(1))
374
375ifneq (,$(call gb_Library_is_udk_versioned,$(call gb_Library_get_target,$(1))))
376$(call gb_Library_get_target,$(1)) \
377$(call gb_Library_get_clean_target,$(1)) : AUXTARGETS +=  \
378	$(call gb_Library_get_target,$(1)).$(gb_UDK_MAJOR)
379endif
380endef
381
382
383# StaticLibrary class
384
385gb_StaticLibrary_DEFS :=
386gb_StaticLibrary_SYSPRE := lib
387gb_StaticLibrary_PLAINEXT := .a
388gb_StaticLibrary_JPEGEXT := lib$(gb_StaticLibrary_PLAINEXT)
389
390gb_StaticLibrary_FILENAMES := \
391	$(foreach lib,$(gb_StaticLibrary_JPEGLIBS),$(lib):$(gb_StaticLibrary_SYSPRE)$(lib)$(gb_StaticLibrary_JPEGEXT)) \
392	$(foreach lib,$(gb_StaticLibrary_PLAINLIBS),$(lib):$(gb_StaticLibrary_SYSPRE)$(lib)$(gb_StaticLibrary_PLAINEXT)) \
393
394gb_StaticLibrary_StaticLibrary_platform =
395
396
397# Executable class
398
399gb_Executable_EXT :=
400
401gb_InBuild_Library_Path := $(OUTDIR)/lib
402gb_Augment_Library_Path := LD_LIBRARY_PATH=$(gb_InBuild_Library_Path)
403
404gb_Executable_LAYER := \
405	$(foreach exe,$(gb_Executable_UREBIN),$(exe):UREBIN) \
406	$(foreach exe,$(gb_Executable_SDK),$(exe):SDKBIN) \
407	$(foreach exe,$(gb_Executable_OOO),$(exe):OOO) \
408	$(foreach exe,$(gb_Executable_BRAND),$(exe):BRAND) \
409	$(foreach exe,$(gb_Executable_NONE),$(exe):NONEBIN) \
410
411
412define gb_Executable_get_rpath
413'-Wl,-rpath,$(call gb_LinkTarget__get_rpath_for_layer,$(call gb_Executable_get_layer,$(1)))' \
414-Wl,-rpath-link,$(gb_Library_OUTDIRLOCATION)
415endef
416
417define gb_Executable_Executable_platform
418$(call gb_LinkTarget_get_target,$(2)) : RPATH := $(call gb_Executable_get_rpath,$(1))
419
420endef
421
422
423# GoogleTest class
424
425gb_GoogleTest_GTESTPRECOMMAND := LD_LIBRARY_PATH=$(OUTDIR)/lib
426gb_GoogleTest_get_filename = $(1)$(gb_Executable_EXT)
427
428define gb_GoogleTest_GoogleTest_platform
429$(call gb_LinkTarget_get_target,$(2)) : RPATH := -Wl,-rpath-link,$(gb_Library_OUTDIRLOCATION)
430endef
431
432# JunitTest class
433
434define gb_JunitTest_JunitTest_platform
435$(call gb_JunitTest_get_target,$(1)) : DEFS := \
436	-Dorg.openoffice.test.arg.soffice="$$$${OOO_TEST_SOFFICE:-path:$(SRCDIR)/instsetoo_native/$(INPATH)/Apache_OpenOffice/installed/install/en-US/openoffice4/program/soffice}" \
437    -Dorg.openoffice.test.arg.env=LD_LIBRARY_PATH \
438    -Dorg.openoffice.test.arg.user=file://$(call gb_JunitTest_get_userdir,$(1)) \
439
440endef
441
442
443# Ant class
444
445define gb_Ant_add_dependencies
446__ant_out:=$(shell $(gb_Ant_ANTCOMMAND) -v -Ddependencies.outfile=$(WORKDIR)/Ant/$(1)/deps -f $(2) dependencies)
447$$(eval $(foreach dep,$(shell cat $(WORKDIR)/Ant/$(1)/deps),$$(call gb_Ant_add_dependency,$(call gb_Ant_get_target,$(1)),$(dep))))
448
449endef
450
451
452# SdiTarget class
453
454gb_SdiTarget_SVIDLPRECOMMAND := LD_LIBRARY_PATH=$(OUTDIR)/lib
455
456# SrsPartMergeTarget
457
458gb_SrsPartMergeTarget_TRANSEXPRECOMMAND := LD_LIBRARY_PATH=$(OUTDIR)/lib
459
460# SrsPartTarget class
461
462gb_SrsPartTarget_RSCTARGET := $(OUTDIR)/bin/rsc
463gb_SrsPartTarget_RSCCOMMAND := LD_LIBRARY_PATH=$(OUTDIR)/lib SOLARBINDIR=$(OUTDIR)/bin $(gb_SrsPartTarget_RSCTARGET)
464
465define gb_SrsPartTarget__command_dep
466$(call gb_Helper_abbreviate_dirs,\
467	$(gb_GCCP) \
468		-MM -MT $(call gb_SrsPartTarget_get_target,$(1)) \
469		$(INCLUDE) \
470		$(DEFS) \
471		-c -x c++-header $(2) \
472		-o $(call gb_SrsPartTarget_get_dep_target,$(1)))
473endef
474
475
476# ComponentTarget
477
478gb_XSLTPROCPRECOMMAND := LD_LIBRARY_PATH=$(OUTDIR)/lib
479gb_Library_COMPONENTPREFIXES := \
480    OOO:vnd.sun.star.expand:\dOOO_BASE_DIR/program/ \
481    URELIB:vnd.sun.star.expand:\dURE_INTERNAL_LIB_DIR/ \
482    NONE:vnd.sun.star.expand:\dOOO_INBUILD_SHAREDLIB_DIR/ \
483
484# UnoApiTarget
485
486gb_UnoApiTarget_IDLCTARGET := $(OUTDIR)/bin/idlc
487gb_UnoApiTarget_IDLCCOMMAND := LD_LIBRARY_PATH=$(OUTDIR)/lib SOLARBINDIR=$(OUTDIR)/bin $(gb_UnoApiTarget_IDLCTARGET)
488gb_UnoApiTarget_REGMERGETARGET := $(OUTDIR)/bin/regmerge
489gb_UnoApiTarget_REGMERGECOMMAND := LD_LIBRARY_PATH=$(OUTDIR)/lib SOLARBINDIR=$(OUTDIR)/bin $(gb_UnoApiTarget_REGMERGETARGET)
490gb_UnoApiTarget_REGCOMPARETARGET := $(OUTDIR)/bin/regcompare
491gb_UnoApiTarget_REGCOMPARECOMMAND := LD_LIBRARY_PATH=$(OUTDIR)/lib SOLARBINDIR=$(OUTDIR)/bin $(gb_UnoApiTarget_REGCOMPARETARGET)
492gb_UnoApiTarget_CPPUMAKERTARGET := $(OUTDIR)/bin/cppumaker
493gb_UnoApiTarget_CPPUMAKERCOMMAND := LD_LIBRARY_PATH=$(OUTDIR)/lib SOLARBINDIR=$(OUTDIR)/bin $(gb_UnoApiTarget_CPPUMAKERTARGET)
494gb_UnoApiTarget_REGVIEWTARGET := $(OUTDIR)/bin/regview
495gb_UnoApiTarget_REGVIEWCOMMAND := LD_LIBRARY_PATH=$(OUTDIR)/lib SOLARBINDIR=$(OUTDIR)/bin $(gb_UnoApiTarget_REGVIEWTARGET)
496
497# vim: set noet sw=4 ts=4:
498