Skip to content

Commit d1bdd59

Browse files
ntocmassiot
authored andcommitted
Improve config.h header generation
Automatically generate config.h header with all pkg-config and optional configuration items to make sure nothing is missing.
1 parent 8f42e26 commit d1bdd59

30 files changed

+122
-122
lines changed

Build.mk

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ version = 0.5
66

77
cflags = -O2 -g $(warn) $(warn_c)
88
cxxflags = -O2 -g $(warn) $(warn_cxx)
9-
cppflags = -Iinclude -I$(top_srcdir)/include
9+
cppflags = -I$(top_builddir) -Iinclude -I$(top_srcdir)/include
1010
ldflags = $(if $(or $(have_apple),$(have_san)),,-Wl,--no-undefined)
1111

1212
warn = -Wall \
@@ -49,9 +49,6 @@ SED ?= sed
4949
configs += atomic
5050
atomic-assert = __ATOMIC_SEQ_CST
5151

52-
configs += bigendian
53-
bigendian-assert = __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
54-
5552
configs += eventfd
5653
eventfd-includes = sys/eventfd.h
5754
eventfd-functions = eventfd
@@ -94,25 +91,7 @@ includesubdir = $(notdir $(patsubst %/,%,$(dir $1)))
9491
genfiles = config.h include/upipe/config.h
9592

9693
config.h:
97-
$(call cmd,gen){ \
98-
$(if $(have_alsa),echo "#define HAVE_ALSA_ASOUNDLIB_H 1";) \
99-
$(if $(have_atomic),echo "#define HAVE_ATOMIC_OPS 1";) \
100-
$(if $(have_audiotoolbox),echo "#define HAVE_AUDIOTOOLBOX_AUDIOTOOLBOX_H 1";) \
101-
$(if $(have_bearssl),echo "#define HAVE_BEARSSL_H 1";) \
102-
$(if $(have_bigendian),echo "#define WORDS_BIGENDIAN 1";) \
103-
$(if $(have_bitstream),echo "#define HAVE_BITSTREAM_COMMON_H 1";) \
104-
$(if $(have_eventfd),echo "#define HAVE_EVENTFD 1";) \
105-
$(if $(have_features.h),echo "#define HAVE_FEATURES_H 1";) \
106-
$(if $(have_libgcrypt),echo "#define HAVE_GCRYPT_H 1";) \
107-
$(if $(have_libtasn1),echo "#define HAVE_LIBTASN1_H 1";) \
108-
$(if $(have_net/if.h),echo "#define HAVE_NET_IF_H 1";) \
109-
$(if $(have_openssl),echo "#define HAVE_OPENSSL_SSL_H 1";) \
110-
$(if $(have_pipe),echo "#define HAVE_PIPE 1";) \
111-
$(if $(have_semaphore),echo "#define HAVE_SEMAPHORE_H 1";) \
112-
$(if $(have_unistd.h),echo "#define HAVE_UNISTD_H 1";) \
113-
$(if $(have_x86asm),echo "#define HAVE_X86ASM 1";) \
114-
$(if $(have_zvbi-0.2),echo "#define HAVE_LIBZVBI_H 1";) \
115-
} > $@
94+
$(call cmd,config.h)
11695

11796
# --- coding-style checks ------------------------------------------------------
11897

Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,19 @@ config-deps:
714714
config-env:
715715
@$(foreach v,$(_config_env_vars),printf "%-15s: %s\n" $v '$($v)';)
716716

717+
[a-z] = a b c d e f g h i j k l m n o p q r s t u v w x y z
718+
[A-Z] = A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
719+
720+
_tr = $(strip $(if $1,$(subst $(firstword $1),$(firstword $2),\
721+
$(call _tr,$(wordlist 2,26,$1),$(wordlist 2,26,$2),$3)),$3))
722+
_toupper = $(call _tr,$([a-z]),$([A-Z]),$1)
723+
_toid = $(call _tr,- . /,_ _ _,$1)
724+
_have = $(sort $(foreach c,$(configs) $(_pkgs),\
725+
$(if $(have_$c),$(call _toid,$(call _toupper,$c)))))
726+
727+
print-config.h = CONFIG $@
728+
cmd-config.h = for i in $(_have); do echo "\#define HAVE_$$i 1"; done > $@
729+
717730
_distcleanfiles = config.mk config.log $(if $(_oot),Makefile) $(_makefiles)
718731

719732
# --- dependencies -------------------------------------------------------------

examples/hls2rtp.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#include <ctype.h>
3131
#include <syslog.h>
3232

33-
#include "upipe/config.h"
33+
#include "config.h"
3434
#include "upipe/upipe_dump.h"
3535
#include "upipe/uprobe.h"
3636
#include "upipe/uprobe_helper_uprobe.h"
@@ -81,10 +81,10 @@
8181
#include "upipe-pthread/uprobe_pthread_upump_mgr.h"
8282
#include "upipe-pthread/upipe_pthread_transfer.h"
8383
#include "upipe-pthread/umutex_pthread.h"
84-
#ifdef UPIPE_HAVE_OPENSSL_SSL_H
84+
#ifdef HAVE_OPENSSL
8585
#include "upipe-openssl/uprobe_https_openssl.h"
8686
#endif
87-
#ifdef UPIPE_HAVE_BEARSSL_H
87+
#ifdef HAVE_BEARSSL
8888
#include "upipe-bearssl/uprobe_https_bearssl.h"
8989
#endif
9090

@@ -1287,10 +1287,10 @@ enum opt {
12871287
OPT_DELAY,
12881288
OPT_QUIT_TIMEOUT,
12891289
OPT_USER_AGENT,
1290-
#ifdef UPIPE_HAVE_BEARSSL_H
1290+
#ifdef HAVE_BEARSSL
12911291
OPT_USE_BEARSSL,
12921292
#endif
1293-
#ifdef UPIPE_HAVE_OPENSSL_SSL_H
1293+
#ifdef HAVE_OPENSSL
12941294
OPT_USE_OPENSSL,
12951295
#endif
12961296
};
@@ -1323,10 +1323,10 @@ static struct option options[] = {
13231323
{ "delay", required_argument, NULL, OPT_DELAY },
13241324
{ "quit-timeout", required_argument, NULL, OPT_QUIT_TIMEOUT },
13251325
{ "user-agent", required_argument, NULL, OPT_USER_AGENT },
1326-
#ifdef UPIPE_HAVE_BEARSSL_H
1326+
#ifdef HAVE_BEARSSL
13271327
{ "use-bearssl", no_argument, NULL, OPT_USE_BEARSSL },
13281328
#endif
1329-
#ifdef UPIPE_HAVE_OPENSSL_SSL_H
1329+
#ifdef HAVE_OPENSSL
13301330
{ "use-openssl", no_argument, NULL, OPT_USE_OPENSSL },
13311331
#endif
13321332
{ 0, 0, 0, 0 },
@@ -1369,11 +1369,11 @@ int main(int argc, char **argv)
13691369
enum upipe_ts_conformance conformance = UPIPE_TS_CONFORMANCE_AUTO;
13701370
bool no_stdin = false;
13711371

1372-
#ifdef UPIPE_HAVE_BEARSSL_H
1372+
#ifdef HAVE_BEARSSL
13731373
bool use_bearssl = true;
13741374
#endif
13751375

1376-
#ifdef UPIPE_HAVE_OPENSSL_SSL_H
1376+
#ifdef HAVE_OPENSSL
13771377
bool use_openssl = true;
13781378
#endif
13791379

@@ -1482,19 +1482,19 @@ int main(int argc, char **argv)
14821482
case OPT_MISSING_ARG:
14831483
return usage(argv[0], "missing argument");
14841484

1485-
#ifdef UPIPE_HAVE_BEARSSL_H
1485+
#ifdef HAVE_BEARSSL
14861486
case OPT_USE_BEARSSL:
14871487
use_bearssl = true;
1488-
#ifdef UPIPE_HAVE_OPENSSL_SSL_H
1488+
#ifdef HAVE_OPENSSL
14891489
use_openssl = false;
14901490
#endif
14911491
break;
14921492
#endif
14931493

1494-
#ifdef UPIPE_HAVE_OPENSSL_SSL_H
1494+
#ifdef HAVE_OPENSSL
14951495
case OPT_USE_OPENSSL:
14961496
use_openssl = true;
1497-
#ifdef UPIPE_HAVE_BEARSSL_H
1497+
#ifdef HAVE_BEARSSL
14981498
use_bearssl = false;
14991499
#endif
15001500
break;
@@ -1793,12 +1793,12 @@ int main(int argc, char **argv)
17931793
uprobe_release(main_probe);
17941794
main_probe = &probe_src;
17951795

1796-
#ifdef UPIPE_HAVE_OPENSSL_SSL_H
1796+
#ifdef HAVE_OPENSSL
17971797
if (use_openssl)
17981798
main_probe = uprobe_https_openssl_alloc(main_probe);
17991799
#endif
18001800

1801-
#ifdef UPIPE_HAVE_BEARSSL_H
1801+
#ifdef HAVE_BEARSSL
18021802
if (use_bearssl)
18031803
main_probe = uprobe_https_bearssl_alloc(main_probe);
18041804
#endif

examples/ts_encrypt.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2424
*/
2525

26-
#include "upipe/config.h"
26+
#include "config.h"
2727

2828
#include "upump-ev/upump_ev.h"
2929

@@ -73,7 +73,7 @@
7373
#include <unistd.h>
7474
#include <syslog.h>
7575

76-
#ifdef UPIPE_HAVE_GCRYPT_H
76+
#ifdef HAVE_LIBGCRYPT
7777
#include <gcrypt.h>
7878
#endif
7979

@@ -269,7 +269,7 @@ int main(int argc, char *argv[])
269269
exit(-1);
270270
}
271271

272-
#ifdef UPIPE_HAVE_GCRYPT_H
272+
#ifdef HAVE_LIBGCRYPT
273273
gcry_check_version(NULL);
274274
gcry_control(GCRYCTL_INITIALIZATION_FINISHED, 0);
275275
#endif

examples/uplay.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <stdlib.h>
3232
#include <stdio.h>
3333

34+
#include "config.h"
3435
#include "upipe/uprobe.h"
3536
#include "upipe/uprobe_stdio.h"
3637
#include "upipe/uprobe_prefix.h"
@@ -81,9 +82,9 @@
8182
#include "upipe-gl/upipe_glx_sink.h"
8283
#include "upipe-gl/uprobe_gl_sink.h"
8384
#include "upipe-gl/uprobe_gl_sink_cube.h"
84-
#ifdef UPIPE_HAVE_ALSA_ASOUNDLIB_H
85+
#ifdef HAVE_ALSA
8586
#include "upipe-alsa/upipe_alsa_sink.h"
86-
#elif defined(UPIPE_HAVE_AUDIOTOOLBOX_AUDIOTOOLBOX_H)
87+
#elif defined(HAVE_AUDIOTOOLBOX)
8788
#include "upipe-osx/upipe_osx_audioqueue_sink.h"
8889
#endif
8990

@@ -482,15 +483,15 @@ static int catch_audio(struct uprobe *uprobe, struct upipe *upipe,
482483
uprobe_throw(uprobe_main, NULL, UPROBE_FREEZE_UPUMP_MGR);
483484

484485
struct upipe *sink;
485-
#ifdef UPIPE_HAVE_ALSA_ASOUNDLIB_H
486+
#ifdef HAVE_ALSA
486487
struct upipe_mgr *upipe_alsink_mgr = upipe_alsink_mgr_alloc();
487488
sink = upipe_void_alloc(upipe_alsink_mgr,
488489
uprobe_pfx_alloc(uprobe_use(uprobe_main), UPROBE_LOG_VERBOSE,
489490
"alsink"));
490491
assert(sink != NULL);
491492
upipe_mgr_release(upipe_alsink_mgr);
492493
upipe_attach_uclock(sink);
493-
#elif defined(UPIPE_HAVE_AUDIOTOOLBOX_AUDIOTOOLBOX_H)
494+
#elif defined(HAVE_AUDIOTOOLBOX)
494495
struct upipe_mgr *upipe_osx_audioqueue_sink_mgr =
495496
upipe_osx_audioqueue_sink_mgr_alloc();
496497
sink = upipe_void_alloc(upipe_osx_audioqueue_sink_mgr,

include/upipe-av/upipe_av_samplefmt.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
extern "C" {
3636
#endif
3737

38+
#include "upipe/ubase.h"
3839
#include "upipe/uref_sound_flow.h"
3940
#include "upipe/uref_sound_flow_formats.h"
4041
#include <libavutil/samplefmt.h>
@@ -50,7 +51,7 @@ static const struct {
5051
{ AV_SAMPLE_FMT_S32, "sound.s32." },
5152
{ AV_SAMPLE_FMT_FLT, "sound.f32." },
5253
{ AV_SAMPLE_FMT_DBL, "sound.f64." },
53-
#ifdef UPIPE_WORDS_BIGENDIAN
54+
#ifdef UBASE_BIGENDIAN
5455
{ AV_SAMPLE_FMT_S16, "sound.s16be." },
5556
{ AV_SAMPLE_FMT_S32, "sound.s32be." },
5657
{ AV_SAMPLE_FMT_FLT, "sound.f32be." },
@@ -91,7 +92,7 @@ upipe_av_samplefmt_to_flow_format(enum AVSampleFormat fmt)
9192
{ AV_SAMPLE_FMT_S64, &uref_sound_flow_format_s64 },
9293
{ AV_SAMPLE_FMT_S64P, &uref_sound_flow_format_s64_planar },
9394

94-
#ifdef UPIPE_WORDS_BIGENDIAN
95+
#ifdef UBASE_BIGENDIAN
9596
{ AV_SAMPLE_FMT_S16, &uref_sound_flow_format_s16be },
9697
{ AV_SAMPLE_FMT_S32, &uref_sound_flow_format_s32be },
9798
{ AV_SAMPLE_FMT_FLT, &uref_sound_flow_format_f32be },

include/upipe/uatomic.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ typedef void * _Atomic uatomic_ptr_t;
6565
#define uatomic_fetch_add atomic_fetch_add
6666
#define uatomic_fetch_sub atomic_fetch_sub
6767

68-
#elif defined(UPIPE_HAVE_ATOMIC_OPS)
68+
#elif defined(UPIPE_HAVE_ATOMIC)
6969

7070
/*
7171
* Preferred method: gcc atomic operations
@@ -161,7 +161,7 @@ static inline uint32_t uatomic_fetch_sub(uatomic_uint32_t *obj,
161161
}
162162

163163

164-
#elif defined(UPIPE_HAVE_SEMAPHORE_H) /* mkdoc:skip */
164+
#elif defined(UPIPE_HAVE_SEMAPHORE) /* mkdoc:skip */
165165

166166
/*
167167
* On POSIX platforms use semaphores (slower)

include/upipe/ubase.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,11 @@ static inline void uchain_init(struct uchain *uchain)
174174
uchain->next = uchain->prev = NULL;
175175
}
176176

177-
#ifdef UPIPE_WORDS_BIGENDIAN
177+
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
178+
#define UBASE_BIGENDIAN
179+
#endif
180+
181+
#ifdef UBASE_BIGENDIAN
178182
/** @This allows to define a 32-bit unsigned integer with 4 letters. */ \
179183
# define UBASE_FOURCC(a, b, c, d) \
180184
(((uint32_t)d) | (((uint32_t)c) << 8) | (((uint32_t)b) << 16) | \

lib/upipe-alsa/upipe_alsa_sink.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ static snd_pcm_format_t upipe_alsink_format_from_flow_def(struct uref *flow_def)
162162
else if (!ubase_ncmp(def, "s16be."))
163163
format = SND_PCM_FORMAT_S16_BE;
164164
else if (!ubase_ncmp(def, "s16."))
165-
#ifdef UPIPE_WORDS_BIGENDIAN
165+
#ifdef UBASE_BIGENDIAN
166166
format = SND_PCM_FORMAT_S16_BE;
167167
#else
168168
format = SND_PCM_FORMAT_S16_LE;
@@ -172,7 +172,7 @@ static snd_pcm_format_t upipe_alsink_format_from_flow_def(struct uref *flow_def)
172172
else if (!ubase_ncmp(def, "u16be."))
173173
format = SND_PCM_FORMAT_U16_BE;
174174
else if (!ubase_ncmp(def, "u16."))
175-
#ifdef UPIPE_WORDS_BIGENDIAN
175+
#ifdef UBASE_BIGENDIAN
176176
format = SND_PCM_FORMAT_U16_BE;
177177
#else
178178
format = SND_PCM_FORMAT_U16_LE;
@@ -190,7 +190,7 @@ static snd_pcm_format_t upipe_alsink_format_from_flow_def(struct uref *flow_def)
190190
else if (!ubase_ncmp(def, "s32be."))
191191
format = SND_PCM_FORMAT_S32_BE;
192192
else if (!ubase_ncmp(def, "s32."))
193-
#ifdef UPIPE_WORDS_BIGENDIAN
193+
#ifdef UBASE_BIGENDIAN
194194
format = SND_PCM_FORMAT_S32_BE;
195195
#else
196196
format = SND_PCM_FORMAT_S32_LE;
@@ -200,7 +200,7 @@ static snd_pcm_format_t upipe_alsink_format_from_flow_def(struct uref *flow_def)
200200
else if (!ubase_ncmp(def, "u32be."))
201201
format = SND_PCM_FORMAT_U32_BE;
202202
else if (!ubase_ncmp(def, "u32."))
203-
#ifdef UPIPE_WORDS_BIGENDIAN
203+
#ifdef UBASE_BIGENDIAN
204204
format = SND_PCM_FORMAT_U32_BE;
205205
#else
206206
format = SND_PCM_FORMAT_U32_LE;
@@ -210,7 +210,7 @@ static snd_pcm_format_t upipe_alsink_format_from_flow_def(struct uref *flow_def)
210210
else if (!ubase_ncmp(def, "s24be."))
211211
format = SND_PCM_FORMAT_S24_BE;
212212
else if (!ubase_ncmp(def, "s24."))
213-
#ifdef UPIPE_WORDS_BIGENDIAN
213+
#ifdef UBASE_BIGENDIAN
214214
format = SND_PCM_FORMAT_S24_BE;
215215
#else
216216
format = SND_PCM_FORMAT_S24_LE;
@@ -220,7 +220,7 @@ static snd_pcm_format_t upipe_alsink_format_from_flow_def(struct uref *flow_def)
220220
else if (!ubase_ncmp(def, "u24be."))
221221
format = SND_PCM_FORMAT_U24_BE;
222222
else if (!ubase_ncmp(def, "u24."))
223-
#ifdef UPIPE_WORDS_BIGENDIAN
223+
#ifdef UBASE_BIGENDIAN
224224
format = SND_PCM_FORMAT_U24_BE;
225225
#else
226226
format = SND_PCM_FORMAT_U24_LE;
@@ -230,7 +230,7 @@ static snd_pcm_format_t upipe_alsink_format_from_flow_def(struct uref *flow_def)
230230
else if (!ubase_ncmp(def, "f32be."))
231231
format = SND_PCM_FORMAT_FLOAT_BE;
232232
else if (!ubase_ncmp(def, "f32."))
233-
#ifdef UPIPE_WORDS_BIGENDIAN
233+
#ifdef UBASE_BIGENDIAN
234234
format = SND_PCM_FORMAT_FLOAT_BE;
235235
#else
236236
format = SND_PCM_FORMAT_FLOAT_LE;
@@ -240,7 +240,7 @@ static snd_pcm_format_t upipe_alsink_format_from_flow_def(struct uref *flow_def)
240240
else if (!ubase_ncmp(def, "f64be."))
241241
format = SND_PCM_FORMAT_FLOAT64_BE;
242242
else if (!ubase_ncmp(def, "f64."))
243-
#ifdef UPIPE_WORDS_BIGENDIAN
243+
#ifdef UBASE_BIGENDIAN
244244
format = SND_PCM_FORMAT_FLOAT64_BE;
245245
#else
246246
format = SND_PCM_FORMAT_FLOAT64_LE;

lib/upipe-av/upipe_avcodec_decode.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
* @short Upipe avcodec decode module
3030
*/
3131

32+
#include "upipe/ubase.h"
3233
#include "upipe/uclock.h"
3334
#include "upipe/ubuf.h"
3435
#include "upipe/uref.h"
@@ -1120,7 +1121,7 @@ static void upipe_avcdec_output_sub(struct upipe *upipe, AVSubtitle *sub,
11201121
}
11211122

11221123
if (unlikely(
1123-
#ifdef UPIPE_WORDS_BIGENDIAN
1124+
#ifdef UBASE_BIGENDIAN
11241125
!ubase_check(uref_pic_flow_set_argb(flow_def_attr)) ||
11251126
#else
11261127
!ubase_check(uref_pic_flow_set_bgra(flow_def_attr)) ||

0 commit comments

Comments
 (0)