[FFmpeg-devel] [PATCH 2/2] configure: libbsd support for arc4random()
Ganesh Ajjanagadde
gajjanag at mit.edu
Mon Dec 7 12:25:27 CET 2015
On Mon, Dec 7, 2015 at 5:37 AM, Ganesh Ajjanagadde <gajjanag at mit.edu> wrote:
> On Mon, Dec 7, 2015 at 2:57 AM, Hendrik Leppkes <h.leppkes at gmail.com> wrote:
>> On Mon, Dec 7, 2015 at 4:56 AM, Ganesh Ajjanagadde
>> <gajjanagadde at gmail.com> wrote:
>>> On non-BSD machines, there exists a package libbsd for providing BSD
>>> functionality. This can be used to get support for arc4random.
>>>
>>> Thus, an opt-in --enable-libbsd is added to configure for this
>>> functionality.
>>>
>>> Tested on GNU/Linux.
>>>
>>> Signed-off-by: Ganesh Ajjanagadde <gajjanagadde at gmail.com>
>>> ---
>>> configure | 23 +++++++++++++++++++++++
>>> libavutil/random_seed.c | 7 ++++++-
>>> 2 files changed, 29 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/configure b/configure
>>> index e676269..bf18198 100755
>>> --- a/configure
>>> +++ b/configure
>>> @@ -211,6 +211,7 @@ External library support:
>>> --enable-libass enable libass subtitles rendering,
>>> needed for subtitles and ass filter [no]
>>> --enable-libbluray enable BluRay reading using libbluray [no]
>>> + --enable-libbsd enable random seeding via arc4random [no]
>>> --enable-libbs2b enable bs2b DSP library [no]
>>> --enable-libcaca enable textual display using libcaca [no]
>>> --enable-libcelt enable CELT decoding via libcelt [no]
>>> @@ -1295,6 +1296,26 @@ require_pkg_config(){
>>> use_pkg_config "$@" || die "ERROR: $pkg not found using pkg-config$pkg_config_fail_message"
>>> }
>>>
>>> +require_libbsd(){
>>> + log require_libbsd "$@"
>>> + pkg="libbsd"
>>> + check_cmd $pkg_config --exists --print-errors $pkg \
>>> + || die "ERROR: $pkg not found"
>>> + pkg_cflags=$($pkg_config --cflags $pkg_config_flags $pkg)
>>> + pkg_libs=$($pkg_config --libs $pkg_config_flags $pkg)
>>> + {
>>> + echo "#define _DEFAULT_SOURCE"
>>> + echo "#include <bsd/stdlib.h>"
>>> + echo "long check_func(void) { return (long) arc4random; }"
>>> + echo "int main(void) { return 0; }"
>>> + } | check_ld "cc" $pkg_cflags $pkg_libs \
>>> + && set_safe "${pkg}_cflags" $pkg_cflags \
>>> + && set_safe "${pkg}_libs" $pkg_libs \
>>> + || die "ERROR: $pkg not found"
>>> + add_cflags $(get_safe "${pkg}_cflags")
>>> + add_extralibs $(get_safe "${pkg}_libs")
>>> +}
>>> +
>>
>> We don't usually define such functions for a dep, it would be better
>> if you can implement the check using the normal "require" function, or
>> even better if libbsd provides a pkgconfig file, use that.
>> Or is there any particular reason why this would need a much more
>> complex handling than default pkg config could offer?
>
> This was the most annoying thing for me, and I could not get the
> default pkgconfig file on Arch Linux to work. There seems to be only
> one reason for it, so I would love to see ideas: it is to define
> -D_DEFAULT_SOURCE or equivalently #define _DEFAULT_SOURCE while
> testing for it. And the only reason for that is BSD's silly insistence
> on non-portable, non-POSIX u_char data type.
Oops, forgot that it should be BSD_SOURCE, DEFAULT_SOURCE is something
only in recent libc, with BSD_SOURCE getting deprecated by a warning.
Thus, technically, it should be both of them defined, but even just
BSD_SOURCE should suffice since we don't care about warnings in
configure. Fixed locally.
>
>>
>>> require_libfreetype(){
>>> log require_libfreetype "$@"
>>> pkg="freetype2"
>>> @@ -1441,6 +1462,7 @@ EXTERNAL_LIBRARY_LIST="
>>> libaacplus
>>> libass
>>> libbluray
>>> + libbsd
>>> libbs2b
>>> libcaca
>>> libcdio
>>> @@ -5386,6 +5408,7 @@ enabled libiec61883 && require libiec61883 libiec61883/iec61883.h iec61883
>>> enabled libaacplus && require "libaacplus >= 2.0.0" aacplus.h aacplusEncOpen -laacplus
>>> enabled libass && require_pkg_config libass ass/ass.h ass_library_init
>>> enabled libbluray && require_pkg_config libbluray libbluray/bluray.h bd_open
>>> +enabled libbsd && require_libbsd
>>> enabled libbs2b && require_pkg_config libbs2b bs2b.h bs2b_open
>>> enabled libcelt && require libcelt celt/celt.h celt_decode -lcelt0 &&
>>> { check_lib celt/celt.h celt_decoder_create_custom -lcelt0 ||
>>> diff --git a/libavutil/random_seed.c b/libavutil/random_seed.c
>>> index 205a636..464b406 100644
>>> --- a/libavutil/random_seed.c
>>> +++ b/libavutil/random_seed.c
>>> @@ -20,6 +20,8 @@
>>>
>>> #include "config.h"
>>>
>>> +#define _DEFAULT_SOURCE
>>> +#define _BSD_SOURCE
>>> #if HAVE_UNISTD_H
>>> #include <unistd.h>
>>> #endif
>>> @@ -30,6 +32,9 @@
>>> #include <windows.h>
>>> #include <wincrypt.h>
>>> #endif
>>> +#if CONFIG_LIBBSD
>>> +#include <bsd/stdlib.h>
>>> +#endif
>>> #include <fcntl.h>
>>> #include <math.h>
>>> #include <time.h>
>>> @@ -121,7 +126,7 @@ uint32_t av_get_random_seed(void)
>>> }
>>> #endif
>>>
>>> -#if HAVE_ARC4RANDOM
>>> +#if HAVE_ARC4RANDOM || CONFIG_LIBBSD
>>> return arc4random();
>>> #endif
>>>
>>> --
>>> 2.6.3
>>>
>>> _______________________________________________
>>> ffmpeg-devel mailing list
>>> ffmpeg-devel at ffmpeg.org
>>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>> _______________________________________________
>> ffmpeg-devel mailing list
>> ffmpeg-devel at ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
More information about the ffmpeg-devel
mailing list