How can I check if a function exists in waf?

Vijay Kumar Banerjee vijaykumar9597 at gmail.com
Fri Feb 1 10:44:02 UTC 2019


On Fri, 1 Feb 2019 at 14:49, Sebastian Huber <
sebastian.huber at embedded-brains.de> wrote:

> On 01/02/2019 10:06, Vijay Kumar Banerjee wrote:
> >
> > On Fri, 1 Feb 2019 at 12:13, Sebastian Huber
> > <sebastian.huber at embedded-brains.de
> > <mailto:sebastian.huber at embedded-brains.de>> wrote:
> >
> >     Hello,
> >
> >     how can I check if a function exists in waf (similar to
> >     AC_CHECK_FUNC)?
> >     Currently, we get this output from the RTEMS tools waf configure
> >     (please
> >     note the "Invalid argument 'function_name' in test"):
> >
> > Hi,
> >
> > The support for 'function_name' has been removed since waf 2 as it
> > was broken ( see
> > https://gitlab.com/ita1024/waf/blob/master/waflib/Tools/c_config.py#L420
> )
>
> Nice.
>
> >
> > I guess the best option is to just use 'header_name' or to use the
> > 'fragment' parameter to write a fragment that calls the desired function.
>
> So, there is no standard compile and link test for functions? If I use this
>
>      conf.check_cc(fragment = 'int main(void) { strnlen("", 0); return
> 0; }',
>                    header_name="string.h", features = 'c', mandatory =
> False)
>
> waf outputs
>
> Checking for header string.h                  : yes
>
> I don't want to test for string.h, I want to test for strnlen(). In
> config.log we have:
>
>
You can use the msg param like this ...
============
diff --git a/rtemstoolkit/wscript b/rtemstoolkit/wscript
index 2c126c8..105869f 100644
--- a/rtemstoolkit/wscript
+++ b/rtemstoolkit/wscript
@@ -374,6 +374,12 @@ def conf_libiberty(conf):
     conf.check(header_name='process.h',   features = 'c', mandatory =
False)
     conf.check(header_name='stdlib.h',    features = 'c')
     conf.check(header_name='string.h',    features = 'c')
+    conf.check_cc( fragment = '''
+                              #include <string.h>
+                              int main(void) { strnlen("", 0); return 0; }
+                                 ''',
+                    features = 'c',
+                    msg = 'Checking for function strnlen')
     conf.check(header_name='strings.h',   features = 'c', mandatory =
False)
     conf.check(header_name='sys/file.h',  features = 'c', mandatory =
False)
     conf.check(header_name='sys/stat.h',  features = 'c', mandatory =
False)

============

This gives an output

Checking for function strnlen            : yes

---------------------------------------------
> Checking for header string.h
> ==>
> int main(void) { strnlen("", 0); return 0; }
> <==
> [1/1] Compiling
>  [32mbuild/.conf_check_6da1e91772980301eb2528a1d150a7ab/test.c [0m
>
> ['/usr/bin/gcc', '../test.c', '-c',
>
> '-o/scratch/git-rtems-tools/build/.conf_check_6da1e91772980301eb2528a1d150a7ab/testbuild/test.c.1.o']
> err: ../test.c: In function ‘main’:
> ../test.c:1:18: warning: implicit declaration of function ‘strnlen’
> [-Wimplicit-function-declaration]
>   int main(void) { strnlen("", 0); return 0; }
>                    ^~~~~~~
>
> yes
> ---------------------------------------------
>
> So, this test uses already quite some code and still is basically useless.
>
> --
> Sebastian Huber, embedded brains GmbH
>
> Address : Dornierstr. 4, D-82178 Puchheim, Germany
> Phone   : +49 89 189 47 41-16
> Fax     : +49 89 189 47 41-09
> E-Mail  : sebastian.huber at embedded-brains.de
> PGP     : Public key available on request.
>
> Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/devel/attachments/20190201/62dddaa3/attachment.html>


More information about the devel mailing list