xref: /trunk/main/solenv/gbuild/platform/freebsd.mk (revision e3393df0)
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
22GUI := UNX
23
24# BSD mktemp -t expects a prefix, not a pattern
25gb_MKTEMP ?= /usr/bin/mktemp -t gbuild.
26
27gb_CC := cc
28gb_CXX := c++
29gb_GCCP := cc
30gb_AR := ar
31gb_AWK := awk
32gb_CLASSPATHSEP := :
33
34# normalize setsolar and configure env.
35ifeq ($(CPU),X)
36CPUNAME := X86_64
37endif
38
39ifeq ($(CPU),P)
40CPUNAME := POWERPC64
41endif
42
43# use CC/CXX if they are nondefaults
44ifneq ($(origin CC),default)
45gb_CC := $(CC)
46gb_GCCP := $(CC)
47endif
48ifneq ($(origin CXX),default)
49gb_CXX := $(CXX)
50endif
51
52gb_OSDEFS := \
53	-D$(OS) \
54	-D_PTHREADS \
55	-DUNIX \
56	-DUNX \
57	$(PTHREAD_CFLAGS) \
58
59gb_COMPILERDEFS := \
60	-D$(COM) \
61	-DHAVE_GCC_VISIBILITY_FEATURE \
62	-DCPPU_ENV=$(COMNAME) \
63
64gb_CPUDEFS := -D$(CPUNAME)
65ifeq ($(CPUNAME),INTEL)
66gb_CPUDEFS += -DX86
67endif
68
69gb_CFLAGS := \
70	-Wall \
71	-Wendif-labels \
72	-Wextra \
73	-Wshadow \
74	-fPIC \
75	-fmessage-length=0 \
76	-fno-common \
77	-fno-strict-aliasing \
78	-fvisibility=hidden \
79	-pipe \
80
81gb_CXXFLAGS := \
82	-Wall \
83	-Wendif-labels \
84	-Wextra \
85	-Wno-ctor-dtor-privacy \
86	-Wno-non-virtual-dtor \
87	-Wshadow \
88	-fPIC \
89	-fmessage-length=0 \
90	-fno-common \
91	-fno-strict-aliasing \
92	-fno-use-cxa-atexit \
93	-fvisibility-inlines-hidden \
94	-fvisibility=hidden \
95	-std=gnu++98 \
96	-pipe
97ifeq ($(COM),CLANG)
98gb_CXXFLAGS += -DHAVE_STL_INCLUDE_PATH
99else
100gb_CXXFLAGS += -DBOOST_TR1_DISABLE_INCLUDE_NEXT -DBOOST_TR1_GCC_INCLUDE_PATH=c++
101endif
102
103ifneq ($(EXTERNAL_WARNINGS_NOT_ERRORS),TRUE)
104gb_CFLAGS_WERROR := -Werror
105gb_CXXFLAGS_WERROR := -Werror
106endif
107
108ifneq ($(strip $(SYSBASE)),)
109gb_CXXFLAGS += --sysroot=$(SYSBASE)
110gb_CFLAGS += --sysroot=$(SYSBASE)
111gb_LinkTarget_LDFLAGS := -Wl,--sysroot=$(SYSBASE)
112endif
113gb_LinkTarget_EXCEPTIONFLAGS := \
114	-DEXCEPTIONS_ON \
115	-fexceptions
116ifeq ($(COM),GCC)
117gb_LinkTarget_EXCEPTIONFLAGS +=  -fno-enforce-eh-specs
118endif
119
120gb_LinkTarget_NOEXCEPTIONFLAGS := \
121	-DEXCEPTIONS_OFF \
122	-fno-exceptions \
123
124gb_LinkTarget_LDFLAGS += \
125	-Wl,-rpath-link,$(SYSBASE)/lib:$(SYSBASE)/usr/lib \
126	-Wl,-z,combreloc \
127	-Wl,-z,defs \
128	$(subst -L../lib , ,$(SOLARLIB)) \
129	${FBSD_GCC_RPATH} \
130	 \
131
132ifeq ($(HAVE_LD_HASH_STYLE),TRUE)
133gb_LinkTarget_LDFLAGS += \
134	-Wl,--hash-style=both \
135
136endif
137
138ifneq ($(HAVE_LD_BSYMBOLIC_FUNCTIONS),)
139gb_LinkTarget_LDFLAGS += \
140	-Wl,--dynamic-list-cpp-new \
141	-Wl,--dynamic-list-cpp-typeinfo \
142	-Wl,-Bsymbolic-functions \
143
144endif
145
146ifneq ($(filter $(CPUNAME),INTEL X86_64),)
147gb_CFLAGS += -fstack-protector
148gb_CXXFLAGS += -fstack-protector
149gb_LinkTarget_LDFLAGS += -fstack-protector
150endif
151
152ifeq ($(gb_DEBUGLEVEL),2)
153gb_COMPILEROPTFLAGS := -O0
154gb_COMPILEROPT1FLAGS := -O0
155else
156# Clang versions 3.6.x and 3.7.x generate bad DWARF CFI for stack unwinding
157# on 32-bit Intel when compiling with -Os optimization.  See
158# <https://llvm.org/bugs/show_bug.cgi?id=24792>
159# Work around this by using "-O2 -fno-unroll-loops" instead.
160ifeq ($(COM)$(CPUNAME)$(shell expr $(CCNUMVER) '>=' 000300060000 '&' $(CCNUMVER) '<' 000300080000),CLANGINTEL1)
161gb_COMPILEROPTFLAGS := -O2 -fno-unroll-loops
162else
163gb_COMPILEROPTFLAGS := -Os
164endif
165gb_COMPILEROPT1FLAGS := -O1
166endif
167
168gb_COMPILERNOOPTFLAGS := -O0
169
170# Helper class
171
172gb_Helper_abbreviate_dirs_native = $(gb_Helper_abbreviate_dirs)
173
174# convert parametters filesystem root to native notation
175# does some real work only on windows, make sure not to
176# break the dummy implementations on unx*
177define gb_Helper_convert_native
178$(1)
179endef
180
181# CObject class
182
183# $(call gb_CObject__command,object,relative-source,source,dep-file)
184define gb_CObject__command
185$(call gb_Output_announce,$(2),$(true),C  ,3)
186$(call gb_Helper_abbreviate_dirs,\
187	mkdir -p $(dir $(1)) $(dir $(4)) && \
188	$(gb_CC) \
189		$(DEFS) \
190		$(T_CFLAGS) \
191		$(CFLAGS) \
192		-c $(3) \
193		-o $(1) \
194		-MMD -MT $(1) \
195		-MF $(4) \
196		-I$(dir $(3)) \
197		$(INCLUDE))
198endef
199
200# convert parametters filesystem root to native notation
201# does some real work only on windows, make sure not to
202# break the dummy implementations on unx*
203define gb_Helper_convert_native
204$(1)
205endef
206
207# CxxObject class
208
209# $(call gb_CxxObject__command,object,relative-source,source,dep-file)
210define gb_CxxObject__command
211$(call gb_Output_announce,$(2),$(true),CXX,3)
212$(call gb_Helper_abbreviate_dirs,\
213	mkdir -p $(dir $(1)) $(dir $(4)) && \
214	$(gb_CXX) \
215		$(DEFS) \
216		$(T_CXXFLAGS) \
217		$(CXXFLAGS) \
218		-c $(3) \
219		-o $(1) \
220		-MMD -MT $(1) \
221		-MF $(4) \
222		-I$(dir $(3)) \
223		$(INCLUDE_STL) $(INCLUDE))
224endef
225
226
227# LinkTarget class
228
229define gb_LinkTarget__get_rpath_for_layer
230$(patsubst $(1):%,%,$(filter $(1):%,$(gb_LinkTarget__RPATHS)))
231endef
232
233gb_LinkTarget__RPATHS := \
234	URELIB:\dORIGIN \
235	UREBIN:\dORIGIN/../lib:\dORIGIN \
236	OOO:\dORIGIN:\dORIGIN/../ure-link/lib \
237	BRAND:\dORIGIN:\dORIGIN/../basis-link/program:\dORIGIN/../basis-link/ure-link/lib \
238	SDKBIN:\dORIGIN/../../ure-link/lib \
239	NONEBIN:\dORIGIN/../lib:\dORIGIN \
240
241gb_LinkTarget_CFLAGS := $(gb_CFLAGS) $(gb_CFLAGS_WERROR)
242gb_LinkTarget_CXXFLAGS := $(gb_CXXFLAGS) $(gb_CXXFLAGS_WERROR)
243
244ifeq ($(gb_DEBUGLEVEL),0)
245gb_LinkTarget_LDFLAGS += -Wl,-O1
246endif
247
248ifeq ($(COM),CLANG)
249ifeq ($(ENABLE_SYMBOLS),SMALL)
250gb_DEBUG_CFLAGS := -ggdb1 -fno-inline
251else
252gb_DEBUG_CFLAGS := -ggdb3 -fno-inline
253endif
254else
255ifeq ($(ENABLE_SYMBOLS),SMALL)
256gb_DEBUG_CFLAGS := -ggdb1 -finline-limit=0 -fno-inline -fno-default-inline
257else
258gb_DEBUG_CFLAGS := -ggdb3 -finline-limit=0 -fno-inline -fno-default-inline
259endif
260endif
261
262gb_LinkTarget_INCLUDE := $(filter-out %/stl, $(subst -I. , ,$(SOLARINC)))
263gb_LinkTarget_INCLUDE_STL := $(filter %/stl, $(subst -I. , ,$(SOLARINC)))
264
265define gb_LinkTarget__command_dynamiclink
266$(call gb_Helper_abbreviate_dirs,\
267	mkdir -p $(dir $(1)) && \
268	$(gb_CXX) \
269		$(if $(filter Library,$(TARGETTYPE)),$(gb_Library_TARGETTYPEFLAGS)) \
270		$(if $(VERSIONMAP),$(gb_Library_VERSIONMAPFLAG) $(VERSIONMAP)) \
271		$(if $(call gb_Library_is_udk_versioned,$(1)),-Wl$(COMMA)-h$(notdir $(1)).$(gb_UDK_MAJOR)) \
272		$(subst \d,$$,$(RPATH)) \
273		$(T_LDFLAGS) \
274		$(foreach object,$(COBJECTS),$(call gb_CObject_get_target,$(object))) \
275		$(foreach object,$(CXXOBJECTS),$(call gb_CxxObject_get_target,$(object))) \
276		$(foreach object,$(GENCXXOBJECTS),$(call gb_GenCxxObject_get_target,$(object))) \
277		-Wl$(COMMA)--start-group $(foreach lib,$(LINKED_STATIC_LIBS),$(call gb_StaticLibrary_get_target,$(lib))) -Wl$(COMMA)--end-group \
278		$(patsubst lib%.so,-l%,$(foreach lib,$(LINKED_LIBS),$(call gb_Library_get_filename,$(lib)))) \
279		$(patsubst %,-l%,$(EXTERNAL_LIBS)) \
280		$(LIBS) \
281		-o $(if $(call gb_Library_is_udk_versioned,$(1)),$(1).$(gb_UDK_MAJOR),$(1)))
282endef
283
284define gb_LinkTarget__command_symlink_udk_versioned_library
285	$(if $(call gb_Library_is_udk_versioned,$(1)),
286		$(call gb_Helper_abbreviate_dirs,\
287			rm -f $(1) && ln -s $(notdir $(1)).$(gb_UDK_MAJOR) $(1)))
288endef
289
290define gb_LinkTarget__command_staticlink
291$(call gb_Helper_abbreviate_dirs,\
292	mkdir -p $(dir $(1)) && \
293	$(gb_AR) -rsu $(1) \
294		$(foreach object,$(COBJECTS),$(call gb_CObject_get_target,$(object))) \
295		$(foreach object,$(CXXOBJECTS),$(call gb_CxxObject_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,-z,origin '-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)
379
380endif
381endef
382
383
384# StaticLibrary class
385
386gb_StaticLibrary_DEFS :=
387gb_StaticLibrary_SYSPRE := lib
388gb_StaticLibrary_PLAINEXT := .a
389gb_StaticLibrary_JPEGEXT := lib$(gb_StaticLibrary_PLAINEXT)
390
391gb_StaticLibrary_FILENAMES := \
392	$(foreach lib,$(gb_StaticLibrary_JPEGLIBS),$(lib):$(gb_StaticLibrary_SYSPRE)$(lib)$(gb_StaticLibrary_JPEGEXT)) \
393	$(foreach lib,$(gb_StaticLibrary_PLAINLIBS),$(lib):$(gb_StaticLibrary_SYSPRE)$(lib)$(gb_StaticLibrary_PLAINEXT)) \
394
395gb_StaticLibrary_StaticLibrary_platform =
396
397
398# Executable class
399
400gb_Executable_EXT :=
401
402gb_Executable_LAYER := \
403	$(foreach exe,$(gb_Executable_UREBIN),$(exe):UREBIN) \
404	$(foreach exe,$(gb_Executable_SDK),$(exe):SDKBIN) \
405	$(foreach exe,$(gb_Executable_OOO),$(exe):OOO) \
406	$(foreach exe,$(gb_Executable_BRAND),$(exe):BRAND) \
407	$(foreach exe,$(gb_Executable_NONE),$(exe):NONEBIN) \
408
409
410define gb_Executable_get_rpath
411'-Wl,-rpath,$(call gb_LinkTarget__get_rpath_for_layer,$(call gb_Executable_get_layer,$(1)))' \
412-Wl,-rpath-link,$(gb_Library_OUTDIRLOCATION)
413endef
414
415define gb_Executable_Executable_platform
416$(call gb_LinkTarget_get_target,$(2)) : RPATH := $(call gb_Executable_get_rpath,$(1))
417
418endef
419
420
421# GoogleTest class
422
423gb_GoogleTest_GTESTPRECOMMAND := LD_LIBRARY_PATH=$(OUTDIR)/lib
424gb_GoogleTest_get_filename = $(1)$(gb_Executable_EXT)
425
426define gb_GoogleTest_GoogleTest_platform
427$(call gb_LinkTarget_get_target,$(2)) : RPATH := -Wl,-rpath-link,$(gb_Library_OUTDIRLOCATION)
428endef
429
430# JunitTest class
431
432define gb_JunitTest_JunitTest_platform
433$(call gb_JunitTest_get_target,$(1)) : DEFS := \
434	-Dorg.openoffice.test.arg.soffice="$$$${OOO_TEST_SOFFICE:-path:$(SRCDIR)/instsetoo_native/$(INPATH)/Apache_OpenOffice/installed/install/en-US/openoffice4/program/soffice}" \
435    -Dorg.openoffice.test.arg.env=LD_LIBRARY_PATH \
436    -Dorg.openoffice.test.arg.user=file://$(call gb_JunitTest_get_userdir,$(1)) \
437
438endef
439
440# SdiTarget class
441
442gb_SdiTarget_SVIDLPRECOMMAND := LD_LIBRARY_PATH=$(OUTDIR)/lib
443
444# SrsPartMergeTarget
445
446gb_SrsPartMergeTarget_TRANSEXPRECOMMAND := LD_LIBRARY_PATH=$(OUTDIR)/lib
447
448# SrsPartTarget class
449
450gb_SrsPartTarget_RSCTARGET := $(OUTDIR)/bin/rsc
451gb_SrsPartTarget_RSCCOMMAND := LD_LIBRARY_PATH=$(OUTDIR)/lib SOLARBINDIR=$(OUTDIR)/bin $(gb_SrsPartTarget_RSCTARGET)
452
453define gb_SrsPartTarget__command_dep
454$(call gb_Helper_abbreviate_dirs,\
455	$(gb_GCCP) \
456		-MM -MT $(call gb_SrsPartTarget_get_target,$(1)) \
457		$(INCLUDE) \
458		$(DEFS) \
459		-c -x c++-header $(2) \
460		-o $(call gb_SrsPartTarget_get_dep_target,$(1)))
461endef
462
463
464# ComponentTarget
465
466gb_XSLTPROCPRECOMMAND := LD_LIBRARY_PATH=$(OUTDIR)/lib
467gb_Library_COMPONENTPREFIXES := \
468    OOO:vnd.sun.star.expand:\dOOO_BASE_DIR/program/ \
469    URELIB:vnd.sun.star.expand:\dURE_INTERNAL_LIB_DIR/ \
470    NONE:vnd.sun.star.expand:\dOOO_INBUILD_SHAREDLIB_DIR/ \
471
472# UnoApiTarget
473
474gb_UnoApiTarget_IDLCTARGET := $(OUTDIR)/bin/idlc
475gb_UnoApiTarget_IDLCCOMMAND := LD_LIBRARY_PATH=$(OUTDIR)/lib SOLARBINDIR=$(OUTDIR)/bin $(gb_UnoApiTarget_IDLCTARGET)
476gb_UnoApiTarget_REGMERGETARGET := $(OUTDIR)/bin/regmerge
477gb_UnoApiTarget_REGMERGECOMMAND := LD_LIBRARY_PATH=$(OUTDIR)/lib SOLARBINDIR=$(OUTDIR)/bin $(gb_UnoApiTarget_REGMERGETARGET)
478gb_UnoApiTarget_REGCOMPARETARGET := $(OUTDIR)/bin/regcompare
479gb_UnoApiTarget_REGCOMPARECOMMAND := LD_LIBRARY_PATH=$(OUTDIR)/lib SOLARBINDIR=$(OUTDIR)/bin $(gb_UnoApiTarget_REGCOMPARETARGET)
480gb_UnoApiTarget_CPPUMAKERTARGET := $(OUTDIR)/bin/cppumaker
481gb_UnoApiTarget_CPPUMAKERCOMMAND := LD_LIBRARY_PATH=$(OUTDIR)/lib SOLARBINDIR=$(OUTDIR)/bin $(gb_UnoApiTarget_CPPUMAKERTARGET)
482gb_UnoApiTarget_REGVIEWTARGET := $(OUTDIR)/bin/regview
483gb_UnoApiTarget_REGVIEWCOMMAND := LD_LIBRARY_PATH=$(OUTDIR)/lib SOLARBINDIR=$(OUTDIR)/bin $(gb_UnoApiTarget_REGVIEWTARGET)
484
485# vim: set noet sw=4 ts=4:
486