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