summaryrefslogtreecommitdiff
path: root/configure.mk.in
blob: 300d1becbe88562b6cfa5101b549522df3d50dd6 (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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
# Copyright (c) 2009-2010, Aleksey Cheusov <vle@gmx.net>
# All rights reserved.
# 
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
# 
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

######################################################################
# See  mk-configure(7) for documentation
#

# user defined variables
MKC_SHOW_CACHED?=0       # set it to `1' to show "...(cached)..." lines
MKC_DELETE_TMPFILES?=0   # set it to `1' to delete temporary files
MKC_CACHEDIR?=${.OBJDIR} # directory for cache and intermediate files
MKC_COMMON_HEADERS?=     # list of headers always #included
MKC_NOCACHE?=            # 1 or yes for disabling cache
MKC_CUSTOM_DIR?=${.CURDIR} # directory with custom tests.c

# .endif for the next .if is in the end of file
.if ${MKCHECKS:Uno:tl} == "yes"

HAVE_FUNCLIB.main ?=	1

#
.undef MKC_SRCS
.undef MKC_LDADD
.undef MKC_CFLAGS

#
.ifndef OPSYS
OPSYS!=	uname -s
.endif

TARGET_OPSYS?=	${OPSYS}
.if defined(MKC_COMMON_DEFINES.${TARGET_OPSYS})
CPPFLAGS+=		${MKC_COMMON_DEFINES.${TARGET_OPSYS}}
.endif
.if defined(MKC_COMMON_DEFINES)
CPPFLAGS+=		${MKC_COMMON_DEFINES}
.endif

#
_MKC_CPPFLAGS:=		${CPPFLAGS}
_MKC_CFLAGS:=		${CFLAGS}
_MKC_CXXFLAGS:=		${CXXFLAGS}
_MKC_FFLAGS:=		${FFLAGS}
_MKC_LDFLAGS:=		${LDFLAGS}
_MKC_LDADD:=		${LDADD}

mkc.environ=CC='${CC}' CXX='${CXX}' FC='${FC}' CPPFLAGS='${_MKC_CPPFLAGS}' CFLAGS='${_MKC_CFLAGS}' CXXFLAGS='${_MKC_CXXFLAGS}' FFLAGS='${_MKC_FFLAGS}' LDFLAGS='${_MKC_LDFLAGS}' LDADD='${_MKC_LDADD}' LEX='${LEX}' YACC='${YACC}' MKC_CACHEDIR='${MKC_CACHEDIR}' MKC_COMMON_HEADERS='${MKC_COMMON_HEADERS}' MKC_DELETE_TMPFILES='${MKC_DELETE_TMPFILES}' MKC_SHOW_CACHED='${MKC_SHOW_CACHED}' MKC_NOCACHE='${MKC_NOCACHE}' MKC_VERBOSE=1

#
MKC_SOURCE_FUNCLIBS   ?=
_MKC_SOURCE_FUNCS=	${MKC_SOURCE_FUNCLIBS:C/:.*//}

# checking for builtin checks
.for i in ${MKC_CHECK_BUILTINS} ${MKC_REQUIRE_BUILTINS}
MKC_CUSTOM_FN.${i}?=	${BUILTINSDIR}/${i}
MKC_CHECK_CUSTOM+=	${i}
MKC_REQUIRE_CUSTOM+=	${MKC_REQUIRE_BUILTINS:M${i}}
.endfor

# checking for headers
.for h in ${MKC_CHECK_HEADERS} ${MKC_REQUIRE_HEADERS}
.if !defined(HAVE_HEADER.${h:S|.|_|g:S|/|_|g})
HAVE_HEADER.${h:S|.|_|g:S|/|_|g}   !=   env ${mkc.environ} mkc_check_header ${h}
.endif
.if ${HAVE_HEADER.${h:S|.|_|g:S|/|_|g}}
.if empty(MKC_REQUIRE_HEADERS:U:M${h})
MKC_CFLAGS  +=  -DHAVE_HEADER_${h:tu:S|.|_|g:S|/|_|g}=${HAVE_HEADER.${h:S|.|_|g:S|/|_|g}}
.endif
.elif !empty(MKC_REQUIRE_HEADERS:U:M${h})
MKC_ERR_MSG+=		"ERROR: cannot find header ${h}"
.endif
.endfor

.undef MKC_CHECK_HEADERS
.undef MKC_REQUIRE_HEADERS

# checking for functions in libraries
.for f in ${MKC_CHECK_FUNCLIBS:U} ${MKC_SOURCE_FUNCLIBS:U} ${MKC_REQUIRE_FUNCLIBS:U}
.if !defined(HAVE_FUNCLIB.${f:S/:/./g})
HAVE_FUNCLIB.${f:S/:/./g}!=	env ${mkc.environ} mkc_check_funclib ${f:S/:/ /g}
.endif
.if !defined(HAVE_FUNCLIB.${f:C/:.*//})
HAVE_FUNCLIB.${f:C/:.*//}!=	env ${mkc.environ} mkc_check_funclib ${f:C/:.*//}
.endif
.if ${HAVE_FUNCLIB.${f:C/:.*//}} != ${HAVE_FUNCLIB.${f:S/:/./g}}
.if empty(MKC_NOAUTO_FUNCLIBS:U:S/:/./g:M${f:S/:/./g}) && empty(MKC_NOAUTO_FUNCLIBS:U:M1) && ${HAVE_FUNCLIB.${f:S/:/./g}} && !${HAVE_FUNCLIB.${f:C/:.*//}}
MKC_LDADD+=-l${f:C/^.*://}
.endif
.endif
.if !${HAVE_FUNCLIB.${f:S/:/./g}} && !${HAVE_FUNCLIB.${f:C/:.*//}} && !empty(_MKC_SOURCE_FUNCS:M${f:C/:.*//})
MKC_SRCS+=${f:C/:.*//}.c
.endif
.endfor # f

.for f in ${MKC_REQUIRE_FUNCLIBS:U}
.if !${HAVE_FUNCLIB.${f:S/:/./g}} && !${HAVE_FUNCLIB.${f:C/:.*//}}
MKC_ERR_MSG+=		"ERROR: cannot find function ${f}"
.endif
.endfor # f

.undef MKC_CHECK_FUNCLIBS
.undef MKC_SOURCE_FUNCLIBS
.undef MKC_REQUIRE_FUNCLIBS

# checking for sizeof(xxx)
.for t in ${MKC_CHECK_SIZEOF:U}
.if !defined(SIZEOF.${t:S|.|_|g:S|-|_|g:S|*|P|g:S|/|_|g:S|:|.|g})
SIZEOF.${t:S|.|_|g:S|-|_|g:S|*|P|g:S|/|_|g:S|:|.|g}   !=   env ${mkc.environ} mkc_check_sizeof ${t:S/:/ /g}
.endif
.if ${SIZEOF.${t:S|.|_|g:S|-|_|g:S|*|P|g:S|/|_|g:S|:|.|g}} != failed
MKC_CFLAGS  +=  -DSIZEOF_${t:S/-/_/g:S| |_|g:S|*|P|g:S|:|_|g:S|.|_|g:tu}=${SIZEOF.${t:S|.|_|g:S|-|_|g:S|*|P|g:S|/|_|g:S|:|.|g}}
.endif
.endfor

.undef MKC_CHECK_SIZEOF

# checking for declared #define
.for d in ${MKC_CHECK_DEFINES:U} ${MKC_REQUIRE_DEFINES:U}
.if !defined(HAVE_DEFINE.${d:S/./_/g:S/:/./g:S|/|_|g})
HAVE_DEFINE.${d:S/./_/g:S/:/./g:S|/|_|g}   !=   env ${mkc.environ} mkc_check_decl define ${d:S/:/ /g}
.endif
.if ${HAVE_DEFINE.${d:S/./_/g:S/:/./g:S|/|_|g}}
.if empty(MKC_REQUIRE_DEFINES:U:M${d})
MKC_CFLAGS  +=  -DHAVE_DEFINE_${d:tu:S/:/_/g:S/./_/g:S|/|_|g}=1
.endif
.endif
.endfor

.for d in ${MKC_REQUIRE_DEFINES:U}
.if !${HAVE_DEFINE.${d:S/./_/g:S/:/./g:S|/|_|g}}
MKC_ERR_MSG+=		"ERROR: cannot find declaration of define ${d}"
.endif
.endfor

.undef MKC_CHECK_DEFINES
.undef MKC_REQUIRE_DEFINES

# checking for declared type
.for t in ${MKC_CHECK_TYPES:U} ${MKC_REQUIRE_TYPES:U}
.if !defined(HAVE_TYPE.${t:S/./_/g:S/:/./g:S|/|_|g})
HAVE_TYPE.${t:S/./_/g:S/:/./g:S|/|_|g}   !=   env ${mkc.environ} mkc_check_decl type ${t:S/:/ /g}
.endif
.if ${HAVE_TYPE.${t:S/./_/g:S/:/./g:S|/|_|g}}
.if empty(MKC_REQUIRE_TYPES:U:M${t})
MKC_CFLAGS  +=  -DHAVE_TYPE_${t:tu:S/:/_/g:S/./_/g:S|/|_|g}=1
.endif
.endif
.endfor

.for t in ${MKC_REQUIRE_TYPES:U}
.if !${HAVE_TYPE.${t:S/./_/g:S/:/./g:S|/|_|g}}
MKC_ERR_MSG+=		"ERROR: cannot find declaration of type ${t}"
.endif
.endfor

.undef MKC_CHECK_TYPES
.undef MKC_REQUIRE_TYPES

# checking for declared variables
.for d in ${MKC_CHECK_VARS:U} ${MKC_REQUIRE_VARS:U}
.if !defined(HAVE_VAR.${d:S/./_/g:S/:/./g:S|/|_|g})
HAVE_VAR.${d:S/./_/g:S/:/./g:S|/|_|g}   !=   env ${mkc.environ} mkc_check_decl variable ${d:S/:/ /g}
.endif
.if ${HAVE_VAR.${d:S/./_/g:S/:/./g:S|/|_|g}}
.if empty(MKC_REQUIRE_VARS:U:M${d})
MKC_CFLAGS  +=  -DHAVE_VAR_${d:tu:S/:/_/g:S/./_/g:S|/|_|g}=1
.endif
.endif
.endfor

.for d in ${MKC_REQUIRE_VARS:U}
.if !${HAVE_VAR.${d:S/./_/g:S/:/./g:S|/|_|g}}
MKC_ERR_MSG+=		"ERROR: cannot find declaration of variable ${d}"
.endif
.endfor

.undef MKC_REQUIRE_VARS

# checking for struct members
.for m in ${MKC_CHECK_MEMBERS:U} ${MKC_REQUIRE_MEMBERS:U}
.if !defined(HAVE_MEMBER.${m:S/./_/g:S/:/./g:S|/|_|g:S/-/_/g})
HAVE_MEMBER.${m:S/./_/g:S/:/./g:S|/|_|g:S/-/_/g}   !=   env ${mkc.environ} mkc_check_decl member ${m:S/:/ /g}
.endif
.if ${HAVE_MEMBER.${m:S/./_/g:S/:/./g:S|/|_|g:S/-/_/g}}
.if empty(MKC_REQUIRE_MEMBERS:U:M${m})
MKC_CFLAGS  +=  -DHAVE_MEMBER_${m:tu:S/:/_/g:S/./_/g:S|/|_|g:S/-/_/g}=1
.endif
.endif
.endfor

.for m in ${MKC_REQUIRE_MEMBERS:U}
.if !${HAVE_MEMBER.${m:S/./_/g:S/:/./g:S|/|_|g:S/-/_/g}}
MKC_ERR_MSG+=		"ERROR: cannot find member ${m}"
.endif
.endfor

.undef MKC_CHECK_MEMBERS
.undef MKC_REQUIRE_MEMBERS

# checking for declared functions
.for n in 0 1 2 3 4 5 6 7 8 9

.for d in ${MKC_CHECK_FUNCS${n}:U} ${MKC_REQUIRE_FUNCS${n}:U}
.if !defined(HAVE_FUNC${n}.${d:S/./_/g:S/:/./g:S|/|_|g})
HAVE_FUNC${n}.${d:S/./_/g:S/:/./g:S|/|_|g}   !=   env ${mkc.environ} mkc_check_decl func${n} ${d:S/:/ /g}
.endif
.if ${HAVE_FUNC${n}.${d:S/./_/g:S/:/./g:S|/|_|g}}
.if empty(MKC_REQUIRE_FUNCS${n}:U:M${d})
MKC_CFLAGS  +=  -DHAVE_FUNC${n}_${d:tu:S/:/_/g:S/./_/g:S|/|_|g}=1
.endif
.endif
.endfor # d

.for d in ${MKC_REQUIRE_FUNCS${n}:U}
.if !${HAVE_FUNC${n}.${d:S/./_/g:S/:/./g:S|/|_|g}}
MKC_ERR_MSG+=		"ERROR: cannot find declaration of function ${d}"
.endif
.endfor # d

.undef MKC_CHECK_FUNCS${n}
.undef MKC_REQUIRE_FUNCS${n}

.endfor # n

# custom checks
.for c in ${MKC_CHECK_CUSTOM} ${MKC_REQUIRE_CUSTOM}
.if !defined(CUSTOM.${c})
.if !defined(MKC_CUSTOM_FN.${c})
MKC_CUSTOM_FN.${c}=${c}.c
.endif
CUSTOM.${c}   !=   env ${mkc.environ} mkc_check_custom \
	${MKC_CUSTOM_FN.${c}:H:S|^.$|${MKC_CUSTOM_DIR}|}/${MKC_CUSTOM_FN.${c}:T}
.endif
.if !empty(CUSTOM.${c}) && ${CUSTOM.${c}} != 0
.if empty(MKC_REQUIRE_CUSTOM:U:M${c})
MKC_CFLAGS  +=  -DCUSTOM_${c:tu}=${CUSTOM.${c}}
.endif
.endif
.endfor

.for c in ${MKC_REQUIRE_CUSTOM}
.if empty(CUSTOM.${c}) || ${CUSTOM.${c}} == 0
MKC_ERR_MSG+=		"ERROR: custom test ${c} failed"
.endif
.endfor

.for c in ${MKC_CHECK_BUILTINS} 
BUILTIN.${c}=	${CUSTOM.${c}}
.endfor

# checking for declared #define
.for p in ${MKC_CHECK_PROGS} ${MKC_REQUIRE_PROGS}
prog_id:=	${MKC_PROG.id.${p:S|+|x|g}:U${p}:S|/|_|g}
.if !defined(PROG.${prog_id})
p_=${p:M/*}
.if !empty(p_)
.  if exists(${p})
PROG.${prog_id}=${p}
.  else
PROG.${prog_id}=
.  endif # exists(${p})
.else
.undef p_
PROG.${prog_id} != env ${mkc.environ} mkc_check_prog -i '${prog_id}' '${p}'
.endif # p matches /*
.endif # !defined(PROG.${prog_id})
.if !empty(PROG.${prog_id})
HAVE_PROG.${prog_id}=		1
.else
HAVE_PROG.${prog_id}=		0
.endif

.if !${HAVE_PROG.${prog_id}} && !empty(MKC_REQUIRE_PROGS:U1:M${p})
MKC_ERR_MSG+=		"ERROR: cannot find program ${p}"
.endif
.endfor # p

.undef MKC_CHECK_PROGS
.undef MKC_REQUIRE_PROGS

.undef MKC_CHECK_CUSTOM
.undef MKC_REQUIRE_CUSTOM

# final assignment
.if !${MKC_NOAUTO:U0}
.for i in ${MKC_CFLAGS}
CFLAGS+=	${i}
.endfor
.for i in ${MKC_LDADD}
LDADD+=		${i}
.endfor
.for i in ${MKC_SRCS}
SRCS+=		${i}
.endfor

.endif # .if MKC_AUTO

.endif # !make(clean) && !make(cleandir) && !make(distclean)