summaryrefslogtreecommitdiff
path: root/mk/compiler.mk
blob: 9e49242ac63bad24de601021c6e2f86419fbb65c (plain)
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
218
219
220
221
# $NetBSD: compiler.mk,v 1.82 2014/12/09 23:43:29 joerg Exp $
#
# This Makefile fragment implements handling for supported C/C++/Fortran
# compilers.
#
# The following variables may be set by the pkgsrc user in mk.conf:
#
# PKGSRC_COMPILER
#	A list of values specifying the chain of compilers to be used by
#	pkgsrc to build packages.
#
#	Valid values are:
#		ccc		Compaq C Compilers (Tru64)
#		ccache		compiler cache (chainable)
#		clang		Clang C and Objective-C compiler
#		distcc		distributed C/C++ (chainable)
#		f2c		Fortran 77 to C compiler (chainable)
#		icc		Intel C++ Compiler (Linux)
#		ido		SGI IRIS Development Option cc (IRIX 5)
#		gcc		GNU
#		hp		HP-UX C/aC++ compilers
#		mipspro		Silicon Graphics, Inc. MIPSpro (n32/n64)
#		mipspro-ucode	Silicon Graphics, Inc. MIPSpro (o32)
#		pcc		Portable C Compiler
#		sunpro		Sun Microsystems, Inc. WorkShip/Forte/Sun
#				ONE Studio
#		xlc		IBM's XL C/C++ compiler suite (Darwin/MacOSX)
#
#	The default is "gcc".  You can use ccache and/or distcc with
#	an appropriate PKGSRC_COMPILER setting, e.g. "ccache distcc
#	gcc".  You can also use "f2c" to overlay the lang/f2c package
#	over the C compiler instead of using the system Fortran
#	compiler.  The chain should always end in a real compiler.
#	This should only be set in /etc/mk.conf.
#
# COMPILER_USE_SYMLINKS
#	If set to yes, use symlinks for the compiler drivers, otherwise
#	shell scripts are created.  The default is yes.
#
# The following variables may be set by a package:
#
# USE_LANGUAGES
#	Lists the languages used in the source code of the package,
#	and is used to determine the correct compilers to install.
#	Valid values are: c, c99, c++, fortran, fortran77, java, objc,
#	obj-c++, and ada.  The default is "c".
#
# The following variables are defined, and available for testing in
# package Makefiles:
#
# CC_VERSION
#	The compiler and version being used, e.g.,
#
#	.include "../../mk/compiler.mk"
#
#	.if !empty(CC_VERSION:Mgcc-3*)
#	...
#	.endif
#
# Keywords: compiler

.if !defined(BSD_COMPILER_MK)
BSD_COMPILER_MK=	defined

_VARGROUPS+=		compiler
_USER_VARS.compiler=	PKGSRC_COMPILER USE_PKGSRC_GCC ABI COMPILER_USE_SYMLINKS
_PKG_VARS.compiler=	USE_LANGUAGES GCC_REQD NOT_FOR_COMPILER ONLY_FOR_COMPILER
_SYS_VARS.compiler=	CC_VERSION

.include "bsd.fast.prefs.mk"

# Since most packages need a C compiler, this is the default value.
USE_LANGUAGES?=	c

# Add c support if c99 is set
.if !empty(USE_LANGUAGES:Mc99)
USE_LANGUAGES+=	c
.endif

COMPILER_USE_SYMLINKS?=	yes

_COMPILERS=		ccc gcc icc ido mipspro mipspro-ucode \
			sunpro xlc hp pcc clang
_PSEUDO_COMPILERS=	ccache distcc f2c g95

.if defined(NOT_FOR_COMPILER) && !empty(NOT_FOR_COMPILER)
.  for _compiler_ in ${_COMPILERS}
.    if ${NOT_FOR_COMPILER:M${_compiler_}} == ""
_ACCEPTABLE_COMPILERS+=	${_compiler_}
.    endif
.  endfor
.elif defined(ONLY_FOR_COMPILER) && !empty(ONLY_FOR_COMPILER)
.  for _compiler_ in ${_COMPILERS}
.    if ${ONLY_FOR_COMPILER:M${_compiler_}} != ""
_ACCEPTABLE_COMPILERS+=	${_compiler_}
.    endif
.  endfor
.else
_ACCEPTABLE_COMPILERS+=	${_COMPILERS}
.endif

# Currently only gcc-based compilers support Ada
# Override PKGSRC_COMPILER if Ada language specified
.if !empty(USE_LANGUAGES:Mada)
PKGSRC_COMPILER=	gcc
.endif

.if defined(_ACCEPTABLE_COMPILERS)
.  for _acceptable_ in ${_ACCEPTABLE_COMPILERS}
.    for _compiler_ in ${PKGSRC_COMPILER}
.      if !empty(_ACCEPTABLE_COMPILERS:M${_compiler_}) && !defined(_COMPILER)
_COMPILER=	${_compiler_}
.      endif
.    endfor
.  endfor
.endif

.if !defined(_COMPILER)
PKG_FAIL_REASON+=	"No acceptable compiler found for ${PKGNAME}."
.endif

.for _compiler_ in ${PKGSRC_COMPILER}
.  if !empty(_PSEUDO_COMPILERS:M${_compiler_})
_PKGSRC_COMPILER:=	${_compiler_} ${_PKGSRC_COMPILER}
.  endif
.endfor
_PKGSRC_COMPILER:=	${_COMPILER} ${_PKGSRC_COMPILER}

_COMPILER_STRIP_VARS=	# empty

.for _compiler_ in ${_PKGSRC_COMPILER}
.  include "compiler/${_compiler_}.mk"
.endfor
.undef _compiler_

.if !defined(PKG_CPP)
PKG_CPP:=${CPP}
.endif

# Ensure the Solaris linker is used by default.
.if ${OPSYS} == "SunOS"
.  if exists(/usr/ccs/bin/ld)
PKG_LD?=       /usr/ccs/bin/ld
.  elif exists(/usr/bin/ld)
PKG_LD?=       /usr/bin/ld
.  endif
.endif

# Strip the leading paths from the toolchain variables since we manipulate
# the PATH to use the correct executable.
#
.for _var_ in ${_COMPILER_STRIP_VARS}
.  if empty(${_var_}:C/^/_asdf_/1:N_asdf_*)
${_var_}:=	${${_var_}:C/^/_asdf_/1:M_asdf_*:S/^_asdf_//:T}
.  else
${_var_}:=	${${_var_}:C/^/_asdf_/1:M_asdf_*:S/^_asdf_//:T} ${${_var_}:C/^/_asdf_/1:N_asdf_*}
.  endif
.endfor

.if defined(ABI) && !empty(ABI)
_WRAP_EXTRA_ARGS.CC+=	${_COMPILER_ABI_FLAG.${ABI}}
_WRAP_EXTRA_ARGS.CXX+=	${_COMPILER_ABI_FLAG.${ABI}}
_WRAP_EXTRA_ARGS.FC+=	${_COMPILER_ABI_FLAG.${ABI}}
CWRAPPERS_APPEND.cc+=	${_COMPILER_ABI_FLAG.${ABI}}
CWRAPPERS_APPEND.cxx+=	${_COMPILER_ABI_FLAG.${ABI}}
CWRAPPERS_APPEND.f77+=	${_COMPILER_ABI_FLAG.${ABI}}
.endif

# If the languages are not requested, force them not to be available
# in the generated wrappers.
#
_FAIL_WRAPPER.CC=	${WRKDIR}/.compiler/bin/c-fail-wrapper
_FAIL_WRAPPER.CXX=	${WRKDIR}/.compiler/bin/c++-fail-wrapper
_FAIL_WRAPPER.FC=	${WRKDIR}/.compiler/bin/fortran-fail-wrapper
_FAIL_WRAPPER.ADA=	${WRKDIR}/.compiler/bin/ada-fail-wrapper

${_FAIL_WRAPPER.CC}: fail-wrapper
${_FAIL_WRAPPER.CXX}: fail-wrapper
${_FAIL_WRAPPER.FC}: fail-wrapper
${_FAIL_WRAPPER.ADA}: fail-wrapper

.PHONY: fail-wrapper
fail-wrapper: .USE
	${RUN}${MKDIR} ${.TARGET:H}
	${RUN}					\
	exec 1>${.TARGET};						\
	${ECHO} '#!'${TOOLS_SHELL:Q};					\
	${ECHO} 'wrapperlog="$${TOOLS_WRAPPER_LOG-'${_TOOLS_WRAP_LOG:Q}'}"'; \
	${ECHO} 'lang="${.TARGET:T:S/-fail-wrapper//}"'; \
	${ECHO} 'msg="*** Please consider adding $$lang to USE_LANGUAGES in the package Makefile."'; \
	${ECHO} '${ECHO} "$$msg" >> $$wrapperlog'; \
	${ECHO} '${ECHO} "$$msg" > ${WARNING_DIR}/${.TARGET:T}'; \
	${ECHO} '${ECHO} "PKGSRC-WARNING: Something is trying to run the $$lang compiler," 1>&2'; \
	${ECHO} '${ECHO} "PKGSRC-WARNING: but it is not added to USE_LANGUAGES in the package Makefile." 1>&2'; \
	${ECHO} 'exit 1'
	${RUN}${CHMOD} +x ${.TARGET}

.if empty(USE_LANGUAGES:Mc) && empty(USE_LANGUAGES:Mobjc) && empty(USE_LANGUAGES:Mobjc-c++)
PKG_CC:=		${_FAIL_WRAPPER.CC}
ALL_ENV+=		CPP=${CPP:Q}
override-tools: ${_FAIL_WRAPPER.CC}
.endif
.if empty(USE_LANGUAGES:Mc++)
PKG_CXX:=		${_FAIL_WRAPPER.CXX}
ALL_ENV+=		CXXCPP=${CPP:Q} # to make some Autoconf scripts happy
override-tools: ${_FAIL_WRAPPER.CXX}
.endif
.if empty(USE_LANGUAGES:Mfortran) && empty(USE_LANGUAGES:Mfortran77)
PKG_FC:=		${_FAIL_WRAPPER.FC}
override-tools: ${_FAIL_WRAPPER.FC}
.endif
.if empty(USE_LANGUAGES:Mada)
PKG_ADA:=		${_FAIL_WRAPPER.ADA}
override-tools: ${_FAIL_WRAPPER.ADA}
.endif

.if !empty(DRAGONFLY_CCVER) && ${OPSYS} == "DragonFly"
ALL_ENV+=		CCVER=${DRAGONFLY_CCVER}
.endif

.endif	# BSD_COMPILER_MK