more fixes: add host_alias suffix when cross-compiling; add builtin 2rd party libs...
[wxWidgets.git] / wx-config.in
1 #!/bin/sh
2
3 # Generic configuration variables:
4 prefix=@prefix@
5 exec_prefix=@exec_prefix@
6 exec_prefix_set=no
7 CC="@CC@"
8 GCC="@GCC@"
9 CXX="@CXX@"
10 LD="@SHARED_LD@"
11 srcdir=@top_srcdir@
12 builddir=@top_builddir_wxconfig@
13 cross_compiling=@cross_compiling@
14 target=@host_alias@
15 static_flag=@STATIC_FLAG@
16 basename_nogui=@WX_LIBRARY_BASENAME_NOGUI@
17 basename_gui=@WX_LIBRARY_BASENAME_GUI@
18 release=@WX_MAJOR_VERSION_NUMBER@.@WX_MINOR_VERSION_NUMBER@
19 is_monolithic=@MONOLITHIC@
20
21
22 # Linker flags for sublibraries:
23 CORE_BASE_LIBS="xml net base"
24 CORE_GUI_LIBS="html core"
25
26 ldlibs_base="@WXCONFIG_EXTRALIBS@"
27 ldlibs_core="@EXTRALIBS_GUI@"
28 ldlibs_xml="@EXTRALIBS_XML@"
29
30 ldflags_gl="@LDFLAGS_GL@"
31 ldlibs_gl="@OPENGL_LIBS@"
32
33
34 # is $1 among the rest of arguments?
35 isinlist()
36 {
37     value=$1
38     shift
39     isin=no
40     for iii in $* ; do
41         if test $iii = $value ; then isin=yes ; fi
42     done
43     test $isin = yes
44 }
45
46 # output linker commands needed to link against libraries passed as arguments
47 # (does not handle monolithic/multilib):
48 output_libs()
49 {
50     if test "$cross_compiling" = "yes" ; then
51         target_tag="-${target}"
52     fi
53
54     all_libs=""
55     all_ldflags=""
56     wxlibs=""
57
58     for lib in $* ; do
59         eval xlibs=\$ldlibs_$lib
60         eval xflags=\$ldflags_$lib
61         if isinlist $lib $CORE_BASE_LIBS ; then
62             basename=$basename_nogui
63         else
64             basename=$basename_gui
65         fi
66         if test $lib = "base" ; then
67             libname="$basename"
68         else
69             libname="${basename}_${lib}"
70         fi
71
72         all_ldflags="$all_ldflags $xflags"
73         if test $static_flag = yes ; then
74             wxlibs="$wxlibs @libdir@/lib${libname}-${release}${target_tag}.a"
75             all_libs="$all_libs $xlibs"
76         else
77             wxlibs="$wxlibs -l${libname}-${release}${target_tag}"
78         fi
79     done
80
81     echo $all_ldflags $wxlibs $all_libs
82 }
83
84 # return the absolute path prepending builddir to it if needed
85 makeabs()
86 {
87     path=$1
88     # TODO: this only works under Unix and even there it could be
89     #       enhanced to remove ".." and "."
90     if [ `echo $path | sed 's/^\(.\).*/\1/'` != "/" ]; then
91         if [ $path = "." ]; then
92             path=$builddir
93         else
94             path="$builddir/$path"
95         fi
96     fi
97
98     echo $path
99 }
100
101 usage()
102 {
103     cat <<EOF
104 Usage: wx-config [--prefix[=DIR]] [--exec-prefix[=DIR]] [--version] [--release]
105                  [--basename] [--static] [--libs[=LIBS]] [--gl-libs]
106                  [--cppflags] [--cflags] [--cxxflags] [--ldflags] [--rezflags]
107                  [--cc] [--cxx] [--ld]
108
109 wx-config returns configuration information about the installed
110 version of wxWindows. It may be used to query its version and
111 installation directories and also retrieve the C and C++ compilers
112 and linker which were used for its building and the corresponding
113 flags.
114
115 Ordinarily it should be installed to the appropriate system location
116 along with the headers and library files, but it is also possible to
117 use it to enable builds with an uninstalled wxWindows version for
118 package building and bleeding edge developers.  To do so, use it like
119 this:
120
121 \${wx_builddir}/wx-config --prefix=\${wx_srcdir} --exec-prefix=\${wx_builddir}
122
123 Note that any other options supplied must come *after* the prefix
124 specification for it to take effect.
125
126 --static must come before --libs and --gl-libs.
127
128 --libs can take optional argument that contains comma-separated list of
129 wxWindows libraries to link against. This list can include both core
130 and contrib libraries.
131
132 --gl-libs option is deprecated, used --libs=gl instead.
133
134 EOF
135
136     exit $1
137 }
138
139 cppflags()
140 {
141     # we should never specify -I/usr/include on the compiler command line: this
142     # is at best useless and at worst breaks compilation on the systems where
143     # the system headers are non-ANSI because gcc works around this by storing
144     # the ANSI-fied versions of them in its private directory which is searched
145     # after all the directories on the cmd line.
146     #
147     # the situation is a bit more complicated with -I/usr/local/include: again,
148     # it shouldn't be specified with gcc which looks there by default anyhow
149     # and gives warnings (at least 3.1 does) if it is specified explicitly --
150     # but this -I switch *is* needed for the other compilers
151     #
152     # note that we assume that if we use GNU cc we also use GNU c++ and vice
153     # versa, i.e. this won't work (either for --cflags or --cxxflags) if GNU C
154     # compiler and non-GNU C++ compiler are used or vice versa -- we'll fix
155     # this when/if anybody complains about it
156     if test "@includedir@" != "/usr/include" \
157             -a "@includedir@" != "/usr/include/c++" \
158             -a \( "${GCC}" != "yes" \
159                   -o "@includedir@" != "/usr/local/include" \) \
160             -a \( "${cross_compiling}" != "yes" \
161                   -o "@includedir@" != "/usr/${target}/include" \) ;
162     then
163         includes=" -I@includedir@"
164     fi
165
166     includes="-I@libdir@/wx/include/@TOOLCHAIN_NAME@$includes"
167
168     if test $static_flag = yes ; then
169         echo $includes @WXDEBUG_DEFINE@ @TOOLCHAIN_DEFS@ @WXCONFIG_INCLUDE@ @WX_LARGEFILE_FLAGS@
170     else
171         echo $includes @WXDEBUG_DEFINE@ @TOOLCHAIN_DEFS@ @TOOLCHAIN_DLL_DEFS@ @WXCONFIG_INCLUDE@ @WX_LARGEFILE_FLAGS@
172     fi
173 }
174
175 if test $# -eq 0; then
176     usage 1 1>&2
177 fi
178
179 while test $# -gt 0; do
180   case "$1" in
181   -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
182   *) optarg= ;;
183   esac
184
185   case $1 in
186     --inplace)
187       prefix=`makeabs $srcdir`
188       exec_prefix=`makeabs $builddir`
189       exec_prefix_set=yes
190       ;;
191     --prefix=*)
192       prefix=$optarg
193       if test $exec_prefix_set = no ; then
194         exec_prefix=$optarg
195       fi
196       ;;
197     --prefix)
198       echo $prefix
199       ;;
200     --exec-prefix=*)
201       exec_prefix=$optarg
202       exec_prefix_set=yes
203       ;;
204     --exec-prefix)
205       echo $exec_prefix
206       ;;
207     --version)
208       echo @WX_MAJOR_VERSION_NUMBER@.@WX_MINOR_VERSION_NUMBER@.@WX_RELEASE_NUMBER@
209       ;;
210     --release)
211       echo $release
212       ;;
213     --basename)
214       echo $basename
215       ;;
216     --static)
217       static_flag=yes
218       ;;
219     --cppflags)
220       cppflags
221       ;;
222     --cflags)
223       echo `cppflags` @CODE_GEN_FLAGS@
224       ;;
225     --cxxflags)
226       echo `cppflags` @CODE_GEN_FLAGS@ @CODE_GEN_FLAGS_CXX@
227       ;;
228     --ldflags)
229       echo @LDFLAGS_EXE@
230       ;;
231     --rezflags)
232       echo @MACRESWXCONFIG@
233       ;;
234
235     --libs*)
236       # find if the argument was --libs=list,of,libs or --libs:
237       if test "x$optarg" = "x" ; then
238           if test "$is_monolithic" = "0" ; then
239               # link against all libs if none given explicitly:
240               libs_list="$CORE_GUI_LIBS $CORE_BASE_LIBS"
241           fi
242       else
243           libs_list=`echo "$optarg" | tr ',' ' '`
244           # always add wxBase, any wxApp needs it:
245           libs_list="$libs_list base"
246       fi
247
248       # include install directory only if it is not default:
249       if test "@libdir@" != "/usr/lib" \
250               -a \( "${cross_compiling}" != "yes" \
251                     -o "@libdir@" != "/usr/${target}/lib" \) ;
252       then
253           libs="-L@libdir@"
254       fi
255
256       # in monolithic build, link against the main library:
257       if test "$is_monolithic" = "1" ; then
258           # filter out core libs, leave only contrib in libs_list:
259           newlist=
260           for i in $libs_list ; do
261               if isinlist $i $CORE_BASE_LIBS $CORE_GUI_LIBS ; then
262                   libs_list="" # do nothing
263               else
264                   newlist="$newlist $i"
265               fi
266           done
267           libs_list="$newlist"
268           
269           # output link flags:
270           contrib_libs=`output_libs $libs_list`
271           if test $static_flag = yes ; then
272               echo "$libs @LDFLAGS@ @WXCONFIG_RPATH@ $contrib_libs @libdir@/@WXCONFIG_LIBS_STATIC@ @EXTRALIBS_GUI@ @LIBS@ @DMALLOC_LIBS@"
273           else
274               echo $libs @LDFLAGS@ @WXCONFIG_RPATH@ $contrib_libs @WXCONFIG_LIBS@ @DMALLOC_LIBS@
275           fi
276       else
277           # in multilib mode, link against all sublibraries:
278           wxlibs=`output_libs $libs_list`
279           echo $libs @LDFLAGS@ @WXCONFIG_RPATH@ $wxlibs @DMALLOC_LIBS@
280       fi
281
282       ;;
283     --gl-libs)
284       output_libs gl
285       ;;
286     --cc)
287       echo $CC
288       ;;
289     --cxx)
290       echo $CXX
291       ;;
292     --ld)
293       echo $LD
294       ;;
295     *)
296       usage 1 1>&2
297       ;;
298   esac
299   shift
300 done
301