]>
Commit | Line | Data |
---|---|---|
1 | # | |
2 | # simple autoconf system for GNU make | |
3 | # | |
4 | # (c) 2002-2006 Gerd Hoffmann <kraxel@suse.de> | |
5 | # | |
6 | # credits for creating this one go to the autotools people because | |
7 | # they managed it to annoy lots of developers and users (including | |
8 | # me) with version incompatibilities. | |
9 | # | |
10 | # This file is public domain. No warranty. If it breaks you keep | |
11 | # both pieces. | |
12 | # | |
13 | ######################################################################## | |
14 | ||
15 | # verbose yes/no | |
16 | verbose ?= no | |
17 | ||
18 | # some stuff used by the tests | |
19 | ifneq ($(verbose),no) | |
20 | # verbose (for debug) | |
21 | ac_init = echo "checking $(1) ... " >&2; rc=no | |
22 | ac_b_cmd = echo "run: $(1)" >&2; $(1) >/dev/null && rc=yes | |
23 | ac_s_cmd = echo "run: $(1)" >&2; rc=`$(1)` | |
24 | ac_fini = echo "... result is $${rc}" >&2; echo >&2; echo "$${rc}" | |
25 | else | |
26 | # normal | |
27 | ac_init = echo -n "checking $(1) ... " >&2; rc=no | |
28 | ac_b_cmd = $(1) >/dev/null 2>&1 && rc=yes | |
29 | ac_s_cmd = rc=`$(1) 2>/dev/null` | |
30 | ac_fini = echo "$${rc}" >&2; echo "$${rc}" | |
31 | endif | |
32 | ||
33 | # some helpers to build cflags and related variables | |
34 | ac_def_cflags_1 = $(if $(filter yes,$($(1))),-D$(1)) | |
35 | ac_lib_cflags = $(foreach lib,$(1),$(call ac_def_cflags_1,HAVE_LIB$(lib))) | |
36 | ac_inc_cflags = $(foreach inc,$(1),$(call ac_def_cflags_1,HAVE_$(inc))) | |
37 | ac_lib_mkvar_1 = $(if $(filter yes,$(HAVE_LIB$(1))),$($(1)_$(2))) | |
38 | ac_lib_mkvar = $(foreach lib,$(1),$(call ac_lib_mkvar_1,$(lib),$(2))) | |
39 | ||
40 | ||
41 | ######################################################################## | |
42 | # the tests ... | |
43 | ||
44 | # get uname | |
45 | ac_uname = $(shell \ | |
46 | $(call ac_init,for system);\ | |
47 | $(call ac_s_cmd,uname -s | tr 'A-Z' 'a-z');\ | |
48 | $(call ac_fini)) | |
49 | ||
50 | # check for some header file | |
51 | # args: header file | |
52 | ac_header = $(shell \ | |
53 | $(call ac_init,for $(1));\ | |
54 | $(call ac_b_cmd,echo '\#include <$(1)>' |\ | |
55 | $(CC) $(CFLAGS) -E -);\ | |
56 | $(call ac_fini)) | |
57 | ||
58 | # check for some function | |
59 | # args: function [, additional libs ] | |
60 | ac_func = $(shell \ | |
61 | $(call ac_init,for $(1));\ | |
62 | echo 'void $(1)(void); int main(void) {$(1)();return 0;}' \ | |
63 | > __actest.c;\ | |
64 | $(call ac_b_cmd,$(CC) $(CFLAGS) $(LDFLAGS) -o \ | |
65 | __actest __actest.c $(2));\ | |
66 | rm -f __actest __actest.c;\ | |
67 | $(call ac_fini)) | |
68 | ||
69 | # check for some library | |
70 | # args: function, library [, additional libs ] | |
71 | ac_lib = $(shell \ | |
72 | $(call ac_init,for $(1) in $(2));\ | |
73 | echo 'void $(1)(void); int main(void) {$(1)();return 0;}' \ | |
74 | > __actest.c;\ | |
75 | $(call ac_b_cmd,$(CC) $(CFLAGS) $(LDFLAGS) -o \ | |
76 | __actest __actest.c -l$(2) $(3));\ | |
77 | rm -f __actest __actest.c;\ | |
78 | $(call ac_fini)) | |
79 | ||
80 | # check if some compiler flag works | |
81 | # args: compiler flag | |
82 | ac_cflag = $(shell \ | |
83 | $(call ac_init,if $(CC) supports $(1));\ | |
84 | echo 'int main() {return 0;}' > __actest.c;\ | |
85 | $(call ac_b_cmd,$(CC) $(CFLAGS) $(1) $(LDFLAGS) -o \ | |
86 | __actest __actest.c);\ | |
87 | rm -f __actest __actest.c;\ | |
88 | $(call ac_fini)) | |
89 | ||
90 | # check for some binary | |
91 | # args: binary name | |
92 | ac_binary = $(shell \ | |
93 | $(call ac_init,for $(1));\ | |
94 | $(call ac_s_cmd,which $(1));\ | |
95 | bin="$$rc";rc="no";\ | |
96 | $(call ac_b_cmd,test -x "$$$$bin");\ | |
97 | $(call ac_fini)) | |
98 | ||
99 | # check if lib64 is used | |
100 | ac_lib64 = $(shell \ | |
101 | $(call ac_init,for libdir name);\ | |
102 | $(call ac_s_cmd,$(CC) -print-search-dirs | grep -q lib64 &&\ | |
103 | echo "lib64" || echo "lib");\ | |
104 | $(call ac_fini)) | |
105 | ||
106 | # check for x11 ressource dir prefix | |
107 | ac_resdir = $(shell \ | |
108 | $(call ac_init,for X11 app-defaults prefix);\ | |
109 | $(call ac_s_cmd, for dir in \ | |
110 | /etc/X11/app-defaults \ | |
111 | /usr/X11R6/lib/X11/app-defaults \ | |
112 | /usr/share/X11/app-defaults \ | |
113 | /usr/lib/X11/app-defaults \ | |
114 | ; do test -d "$$dir" || continue;\ | |
115 | dirname "$$dir"; break; done);\ | |
116 | $(call ac_fini)) | |
117 | ||
118 | # check if package is installed, via pkg-config | |
119 | # args: pkg name | |
120 | ac_pkg_config = $(shell \ | |
121 | $(call ac_init,for $(1) (using pkg-config));\ | |
122 | $(call ac_b_cmd, pkg-config $(1));\ | |
123 | $(call ac_fini)) | |
124 | ||
125 | ||
126 | ######################################################################## | |
127 | # build Make.config | |
128 | ||
129 | define newline | |
130 | ||
131 | ||
132 | endef | |
133 | make-config-q = $(subst $(newline),\n,$(make-config)) | |
134 | ||
135 | ifeq ($(filter config,$(MAKECMDGOALS)),config) | |
136 | .PHONY: Make.config | |
137 | LIB := $(call ac_lib64) | |
138 | else | |
139 | LIB ?= $(call ac_lib64) | |
140 | LIB := $(LIB) | |
141 | endif | |
142 | .PHONY: config | |
143 | config: Make.config | |
144 | @true | |
145 | ||
146 | Make.config: $(srcdir)/GNUmakefile | |
147 | @echo -e "$(make-config-q)" > $@ | |
148 | @echo | |
149 | @echo "Make.config written, edit if needed" | |
150 | @echo |