xref: /trunk/main/solenv/gbuild/platform/linux.mk (revision 7f6ffbef)
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	-pipe \
93
94ifneq ($(EXTERNAL_WARNINGS_NOT_ERRORS),TRUE)
95gb_CFLAGS_WERROR := -Werror
96gb_CXXFLAGS_WERROR := -Werror
97endif
98
99ifneq ($(strip $(SYSBASE)),)
100gb_CXXFLAGS += --sysroot=$(SYSBASE)
101gb_CFLAGS += --sysroot=$(SYSBASE)
102gb_LinkTarget_LDFLAGS := -Wl,--sysroot=$(SYSBASE)
103endif
104gb_LinkTarget_EXCEPTIONFLAGS := \
105	-DEXCEPTIONS_ON \
106	-fexceptions
107ifeq ($(COM),GCC)
108gb_LinkTarget_EXCEPTIONFLAGS +=  -fno-enforce-eh-specs
109endif
110
111gb_LinkTarget_NOEXCEPTIONFLAGS := \
112	-DEXCEPTIONS_OFF \
113	-fno-exceptions \
114
115gb_LinkTarget_LDFLAGS += \
116	-Wl,-rpath-link,$(SYSBASE)/lib:$(SYSBASE)/usr/lib \
117	-Wl,-z,combreloc \
118	-Wl,-z,defs \
119	$(subst -L../lib , ,$(SOLARLIB)) \
120
121ifeq ($(HAVE_LD_HASH_STYLE),TRUE)
122gb_LinkTarget_LDFLAGS += \
123	-Wl,--hash-style=both \
124
125endif
126
127ifneq ($(HAVE_LD_BSYMBOLIC_FUNCTIONS),)
128gb_LinkTarget_LDFLAGS += \
129	-Wl,--dynamic-list-cpp-new \
130	-Wl,--dynamic-list-cpp-typeinfo \
131	-Wl,-Bsymbolic-functions \
132
133endif
134
135ifeq ($(gb_DEBUGLEVEL),0)
136gb_LinkTarget_LDFLAGS += -Wl,-O1
137endif
138
139ifeq ($(COM),CLANG)
140ifeq ($(ENABLE_SYMBOLS),SMALL)
141gb_DEBUG_CFLAGS := -ggdb1 -fno-inline
142else
143gb_DEBUG_CFLAGS := -ggdb3 -fno-inline
144endif
145else
146ifeq ($(ENABLE_SYMBOLS),SMALL)
147gb_DEBUG_CFLAGS := -ggdb1 -finline-limit=0 -fno-inline -fno-default-inline
148else
149gb_DEBUG_CFLAGS := -ggdb3 -finline-limit=0 -fno-inline -fno-default-inline
150endif
151endif
152
153ifeq ($(gb_DEBUGLEVEL),2)
154gb_COMPILEROPTFLAGS := -O0
155gb_COMPILEROPT1FLAGS := -O0
156else
157gb_COMPILEROPTFLAGS := -Os
158gb_COMPILEROPT1FLAGS := -O1
159endif
160
161gb_COMPILERNOOPTFLAGS := -O0
162
163# Helper class
164
165gb_Helper_abbreviate_dirs_native = $(gb_Helper_abbreviate_dirs)
166
167# convert parametters filesystem root to native notation
168# does some real work only on windows, make sure not to
169# break the dummy implementations on unx*
170define gb_Helper_convert_native
171$(1)
172endef
173
174# AsmObject class
175
176gb_AsmObject_EXT := .s
177
178define gb_AsmObject__command
179$(call gb_Output_announce,$(2),$(true),ASM,3)
180$(call gb_Helper_abbreviate_dirs,\
181	mkdir -p $(dir $(1)) && \
182	$(gb_CC) \
183		$(DEFS) \
184		$(T_CFLAGS) \
185		$(CFLAGS) \
186		-c $(3) \
187		-o $(1) \
188		-MT $(1) \
189		-I$(dir $(3)) \
190		$(INCLUDE))
191endef
192
193# CObject class
194
195# $(call gb_CObject__command,object,relative-source,source,dep-file)
196define gb_CObject__command
197$(call gb_Output_announce,$(2),$(true),C  ,3)
198$(call gb_Helper_abbreviate_dirs,\
199	mkdir -p $(dir $(1)) $(dir $(4)) && \
200	$(gb_CC) \
201		$(DEFS) \
202		$(T_CFLAGS) \
203		$(CFLAGS) \
204		-c $(3) \
205		-o $(1) \
206		-MMD -MT $(1) \
207		-MF $(4) \
208		-I$(dir $(3)) \
209		$(INCLUDE))
210endef
211
212# convert parametters filesystem root to native notation
213# does some real work only on windows, make sure not to
214# break the dummy implementations on unx*
215define gb_Helper_convert_native
216$(1)
217endef
218
219# CxxObject class
220
221# $(call gb_CxxObject__command,object,relative-source,source,dep-file)
222define gb_CxxObject__command
223$(call gb_Output_announce,$(2),$(true),CXX,3)
224$(call gb_Helper_abbreviate_dirs,\
225	mkdir -p $(dir $(1)) $(dir $(4)) && \
226	$(gb_CXX) \
227		$(DEFS) \
228		$(T_CXXFLAGS) \
229		$(CXXFLAGS) \
230		-c $(3) \
231		-o $(1) \
232		-MMD -MT $(1) \
233		-MF $(4) \
234		-I$(dir $(3)) \
235		$(INCLUDE_STL) $(INCLUDE))
236endef
237
238
239# LinkTarget class
240
241define gb_LinkTarget__get_rpath_for_layer
242$(patsubst $(1):%,%,$(filter $(1):%,$(gb_LinkTarget__RPATHS)))
243endef
244
245gb_LinkTarget__RPATHS := \
246	URELIB:\dORIGIN \
247	UREBIN:\dORIGIN/../lib:\dORIGIN \
248	OOO:\dORIGIN:\dORIGIN/../ure-link/lib \
249	BRAND:\dORIGIN:\dORIGIN/../basis-link/program:\dORIGIN/../basis-link/ure-link/lib \
250	SDKBIN:\dORIGIN/../../ure-link/lib \
251	NONEBIN:\dORIGIN/../lib:\dORIGIN \
252
253gb_LinkTarget_CFLAGS := $(gb_CFLAGS) $(gb_CFLAGS_WERROR)
254gb_LinkTarget_CXXFLAGS := $(gb_CXXFLAGS) $(gb_CXXFLAGS_WERROR)
255
256
257gb_LinkTarget_INCLUDE := $(filter-out %/stl, $(subst -I. , ,$(SOLARINC)))
258gb_LinkTarget_INCLUDE_STL := $(filter %/stl, $(subst -I. , ,$(SOLARINC)))
259
260define gb_LinkTarget__command_dynamiclink
261$(call gb_Helper_abbreviate_dirs,\
262	mkdir -p $(dir $(1)) && \
263	$(gb_CXX) \
264		$(if $(filter Library,$(TARGETTYPE)),$(gb_Library_TARGETTYPEFLAGS)) \
265		$(if $(VERSIONMAP),$(gb_Library_VERSIONMAPFLAG) $(VERSIONMAP)) \
266		$(if $(call gb_Library_is_udk_versioned,$(1)),-Wl$(COMMA)-h$(notdir $(1)).$(gb_UDK_MAJOR)) \
267		$(subst \d,$$,$(RPATH)) \
268		$(T_LDFLAGS) \
269		$(foreach object,$(ASMOBJECTS),$(call gb_AsmObject_get_target,$(object))) \
270		$(foreach object,$(COBJECTS),$(call gb_CObject_get_target,$(object))) \
271		$(foreach object,$(CXXOBJECTS),$(call gb_CxxObject_get_target,$(object))) \
272		$(foreach object,$(GENCOBJECTS),$(call gb_GenCObject_get_target,$(object))) \
273		$(foreach object,$(GENCXXOBJECTS),$(call gb_GenCxxObject_get_target,$(object))) \
274		-Wl$(COMMA)--start-group $(foreach lib,$(LINKED_STATIC_LIBS),$(call gb_StaticLibrary_get_target,$(lib))) -Wl$(COMMA)--end-group \
275		$(patsubst lib%.so,-l%,$(foreach lib,$(LINKED_LIBS),$(call gb_Library_get_filename,$(lib)))) \
276		$(patsubst %,-l%,$(EXTERNAL_LIBS)) \
277		$(LIBS) \
278		-lc \
279		-o $(if $(call gb_Library_is_udk_versioned,$(1)),$(1).$(gb_UDK_MAJOR),$(1)))
280endef
281
282define gb_LinkTarget__command_symlink_udk_versioned_library
283	$(if $(call gb_Library_is_udk_versioned,$(1)),
284		$(call gb_Helper_abbreviate_dirs,\
285			rm -f $(1) && ln -s $(notdir $(1)).$(gb_UDK_MAJOR) $(1)))
286endef
287
288define gb_LinkTarget__command_staticlink
289$(call gb_Helper_abbreviate_dirs,\
290	mkdir -p $(dir $(1)) && \
291	$(gb_AR) -rsu $(1) \
292		$(foreach object,$(COBJECTS),$(call gb_CObject_get_target,$(object))) \
293		$(foreach object,$(CXXOBJECTS),$(call gb_CxxObject_get_target,$(object))) \
294		$(foreach object,$(GENCOBJECTS),$(call gb_GenCObject_get_target,$(object))) \
295		$(foreach object,$(GENCXXOBJECTS),$(call gb_GenCxxObject_get_target,$(object))) \
296		2> /dev/null)
297endef
298
299define gb_LinkTarget__command
300$(call gb_Output_announce,$(2),$(true),LNK,4)
301$(if $(filter Library GoogleTest Executable,$(TARGETTYPE)),$(call gb_LinkTarget__command_dynamiclink,$(1)))
302$(if $(filter Library,$(TARGETTYPE)),$(call gb_LinkTarget__command_symlink_udk_versioned_library,$(1)))
303$(if $(filter StaticLibrary,$(TARGETTYPE)),$(call gb_LinkTarget__command_staticlink,$(1)))
304endef
305
306
307# Library class
308
309gb_Library_DEFS :=
310gb_Library_TARGETTYPEFLAGS := -shared -Wl,-z,noexecstack
311gb_Library_SYSPRE := lib
312gb_Library_UNOVERPRE := $(gb_Library_SYSPRE)uno_
313gb_Library_PLAINEXT := .so
314gb_Library_RTEXT := gcc3$(gb_Library_PLAINEXT)
315ifeq ($(gb_PRODUCT),$(true))
316gb_Library_STLEXT := port_gcc$(gb_Library_PLAINEXT)
317else
318gb_Library_STLEXT := port_gcc_stldebug$(gb_Library_PLAINEXT)
319endif
320gb_Library_VERSIONMAPFLAG := -Wl,--version-script
321
322ifeq ($(CPUNAME),X86_64)
323gb_Library_OOOEXT := $(gb_Library_PLAINEXT)
324gb_Library_UNOEXT := .uno$(gb_Library_PLAINEXT)
325else
326gb_Library_OOOEXT := $(gb_Library_PLAINEXT)
327gb_Library_UNOEXT := .uno$(gb_Library_PLAINEXT)
328endif
329
330gb_Library_PLAINLIBS_NONE += \
331	fontconfig \
332	Xrender \
333	dl \
334	freetype \
335	m \
336	pthread \
337	X11 \
338	Xext \
339	SM \
340	ICE
341
342gb_Library_FILENAMES := \
343	$(foreach lib,$(gb_Library_OOOLIBS),$(lib):$(gb_Library_SYSPRE)$(lib)$(gb_Library_OOOEXT)) \
344	$(foreach lib,$(gb_Library_PLAINLIBS_NONE),$(lib):$(gb_Library_SYSPRE)$(lib)$(gb_Library_PLAINEXT)) \
345	$(foreach lib,$(gb_Library_PLAINLIBS_URE),$(lib):$(gb_Library_SYSPRE)$(lib)$(gb_Library_PLAINEXT)) \
346	$(foreach lib,$(gb_Library_PLAINLIBS_OOO),$(lib):$(gb_Library_SYSPRE)$(lib)$(gb_Library_PLAINEXT)) \
347	$(foreach lib,$(gb_Library_RTLIBS),$(lib):$(gb_Library_SYSPRE)$(lib)$(gb_Library_RTEXT)) \
348	$(foreach lib,$(gb_Library_RTVERLIBS),$(lib):$(gb_Library_SYSPRE)$(lib)$(gb_Library_RTEXT)) \
349	$(foreach lib,$(gb_Library_STLLIBS),$(lib):$(gb_Library_SYSPRE)$(lib)$(gb_Library_STLEXT)) \
350	$(foreach lib,$(gb_Library_UNOLIBS_URE),$(lib):$(lib)$(gb_Library_UNOEXT)) \
351	$(foreach lib,$(gb_Library_UNOLIBS_OOO),$(lib):$(lib)$(gb_Library_UNOEXT)) \
352	$(foreach lib,$(gb_Library_UNOVERLIBS),$(lib):$(gb_Library_UNOVERPRE)$(lib)$(gb_Library_PLAINEXT)) \
353
354
355gb_Library_LAYER := \
356	$(foreach lib,$(gb_Library_OOOLIBS),$(lib):OOO) \
357	$(foreach lib,$(gb_Library_PLAINLIBS_URE),$(lib):URELIB) \
358	$(foreach lib,$(gb_Library_PLAINLIBS_OOO),$(lib):OOO) \
359	$(foreach lib,$(gb_Library_RTLIBS),$(lib):OOO) \
360	$(foreach lib,$(gb_Library_RTVERLIBS),$(lib):URELIB) \
361	$(foreach lib,$(gb_Library_STLLIBS),$(lib):URELIB) \
362	$(foreach lib,$(gb_Library_UNOLIBS_URE),$(lib):URELIB) \
363	$(foreach lib,$(gb_Library_UNOLIBS_OOO),$(lib):OOO) \
364	$(foreach lib,$(gb_Library_UNOVERLIBS),$(lib):URELIB) \
365
366define gb_Library_get_rpath
367'-Wl,-rpath,$(call gb_LinkTarget__get_rpath_for_layer,$(call gb_Library_get_layer,$(1)))' \
368'-Wl,-rpath-link,$(gb_Library_OUTDIRLOCATION)'
369endef
370
371define gb_Library_Library_platform
372$(call gb_LinkTarget_get_target,$(2)) : RPATH := $(call gb_Library_get_rpath,$(1))
373
374ifneq (,$(call gb_Library_is_udk_versioned,$(call gb_Library_get_target,$(1))))
375$(call gb_Library_get_target,$(1)) \
376$(call gb_Library_get_clean_target,$(1)) : AUXTARGETS +=  \
377	$(call gb_Library_get_target,$(1)).$(gb_UDK_MAJOR)
378endif
379endef
380
381
382# StaticLibrary class
383
384gb_StaticLibrary_DEFS :=
385gb_StaticLibrary_SYSPRE := lib
386gb_StaticLibrary_PLAINEXT := .a
387gb_StaticLibrary_JPEGEXT := lib$(gb_StaticLibrary_PLAINEXT)
388
389gb_StaticLibrary_FILENAMES := \
390	$(foreach lib,$(gb_StaticLibrary_JPEGLIBS),$(lib):$(gb_StaticLibrary_SYSPRE)$(lib)$(gb_StaticLibrary_JPEGEXT)) \
391	$(foreach lib,$(gb_StaticLibrary_PLAINLIBS),$(lib):$(gb_StaticLibrary_SYSPRE)$(lib)$(gb_StaticLibrary_PLAINEXT)) \
392
393gb_StaticLibrary_StaticLibrary_platform =
394
395
396# Executable class
397
398gb_Executable_EXT :=
399
400gb_InBuild_Library_Path := $(OUTDIR)/lib
401gb_Augment_Library_Path := LD_LIBRARY_PATH=$(gb_InBuild_Library_Path)
402
403gb_Executable_LAYER := \
404	$(foreach exe,$(gb_Executable_UREBIN),$(exe):UREBIN) \
405	$(foreach exe,$(gb_Executable_SDK),$(exe):SDKBIN) \
406	$(foreach exe,$(gb_Executable_OOO),$(exe):OOO) \
407	$(foreach exe,$(gb_Executable_BRAND),$(exe):BRAND) \
408	$(foreach exe,$(gb_Executable_NONE),$(exe):NONEBIN) \
409
410
411define gb_Executable_get_rpath
412'-Wl,-rpath,$(call gb_LinkTarget__get_rpath_for_layer,$(call gb_Executable_get_layer,$(1)))' \
413-Wl,-rpath-link,$(gb_Library_OUTDIRLOCATION)
414endef
415
416define gb_Executable_Executable_platform
417$(call gb_LinkTarget_get_target,$(2)) : RPATH := $(call gb_Executable_get_rpath,$(1))
418
419endef
420
421
422# GoogleTest class
423
424gb_GoogleTest_GTESTPRECOMMAND := LD_LIBRARY_PATH=$(OUTDIR)/lib
425gb_GoogleTest_get_filename = $(1)$(gb_Executable_EXT)
426
427define gb_GoogleTest_GoogleTest_platform
428$(call gb_LinkTarget_get_target,$(2)) : RPATH := -Wl,-rpath-link,$(gb_Library_OUTDIRLOCATION)
429endef
430
431# JunitTest class
432
433define gb_JunitTest_JunitTest_platform
434$(call gb_JunitTest_get_target,$(1)) : DEFS := \
435	-Dorg.openoffice.test.arg.soffice="$$$${OOO_TEST_SOFFICE:-path:$(SRCDIR)/instsetoo_native/$(INPATH)/Apache_OpenOffice/installed/install/en-US/openoffice4/program/soffice}" \
436    -Dorg.openoffice.test.arg.env=LD_LIBRARY_PATH \
437    -Dorg.openoffice.test.arg.user=file://$(call gb_JunitTest_get_userdir,$(1)) \
438
439endef
440
441
442# Ant class
443
444define gb_Ant_add_dependencies
445__ant_out:=$(shell $(gb_Ant_ANTCOMMAND) -v -Ddependencies.outfile=$(WORKDIR)/Ant/$(1)/deps -f $(2) dependencies)
446$$(eval $(foreach dep,$(shell cat $(WORKDIR)/Ant/$(1)/deps),$$(call gb_Ant_add_dependency,$(call gb_Ant_get_target,$(1)),$(dep))))
447
448endef
449
450
451# SdiTarget class
452
453gb_SdiTarget_SVIDLPRECOMMAND := LD_LIBRARY_PATH=$(OUTDIR)/lib
454
455# SrsPartMergeTarget
456
457gb_SrsPartMergeTarget_TRANSEXPRECOMMAND := LD_LIBRARY_PATH=$(OUTDIR)/lib
458
459# SrsPartTarget class
460
461gb_SrsPartTarget_RSCTARGET := $(OUTDIR)/bin/rsc
462gb_SrsPartTarget_RSCCOMMAND := LD_LIBRARY_PATH=$(OUTDIR)/lib SOLARBINDIR=$(OUTDIR)/bin $(gb_SrsPartTarget_RSCTARGET)
463
464define gb_SrsPartTarget__command_dep
465$(call gb_Helper_abbreviate_dirs,\
466	$(gb_GCCP) \
467		-MM -MT $(call gb_SrsPartTarget_get_target,$(1)) \
468		$(INCLUDE) \
469		$(DEFS) \
470		-c -x c++-header $(2) \
471		-o $(call gb_SrsPartTarget_get_dep_target,$(1)))
472endef
473
474
475# ComponentTarget
476
477gb_XSLTPROCPRECOMMAND := LD_LIBRARY_PATH=$(OUTDIR)/lib
478gb_Library_COMPONENTPREFIXES := \
479    OOO:vnd.sun.star.expand:\dOOO_BASE_DIR/program/ \
480    URELIB:vnd.sun.star.expand:\dURE_INTERNAL_LIB_DIR/ \
481    NONE:vnd.sun.star.expand:\dOOO_INBUILD_SHAREDLIB_DIR/ \
482
483# UnoApiTarget
484
485gb_UnoApiTarget_IDLCTARGET := $(OUTDIR)/bin/idlc
486gb_UnoApiTarget_IDLCCOMMAND := LD_LIBRARY_PATH=$(OUTDIR)/lib SOLARBINDIR=$(OUTDIR)/bin $(gb_UnoApiTarget_IDLCTARGET)
487gb_UnoApiTarget_REGMERGETARGET := $(OUTDIR)/bin/regmerge
488gb_UnoApiTarget_REGMERGECOMMAND := LD_LIBRARY_PATH=$(OUTDIR)/lib SOLARBINDIR=$(OUTDIR)/bin $(gb_UnoApiTarget_REGMERGETARGET)
489gb_UnoApiTarget_REGCOMPARETARGET := $(OUTDIR)/bin/regcompare
490gb_UnoApiTarget_REGCOMPARECOMMAND := LD_LIBRARY_PATH=$(OUTDIR)/lib SOLARBINDIR=$(OUTDIR)/bin $(gb_UnoApiTarget_REGCOMPARETARGET)
491gb_UnoApiTarget_CPPUMAKERTARGET := $(OUTDIR)/bin/cppumaker
492gb_UnoApiTarget_CPPUMAKERCOMMAND := LD_LIBRARY_PATH=$(OUTDIR)/lib SOLARBINDIR=$(OUTDIR)/bin $(gb_UnoApiTarget_CPPUMAKERTARGET)
493gb_UnoApiTarget_REGVIEWTARGET := $(OUTDIR)/bin/regview
494gb_UnoApiTarget_REGVIEWCOMMAND := LD_LIBRARY_PATH=$(OUTDIR)/lib SOLARBINDIR=$(OUTDIR)/bin $(gb_UnoApiTarget_REGVIEWTARGET)
495
496# vim: set noet sw=4 ts=4:
497