Browse code

build: handle library dependencies in configure

Instead of setting FFLIBS in each library Makefile configure
exports FFLIBS-$library in config.mak.

Janne Grunau authored on 2014/05/01 20:18:57
Showing 8 changed files
... ...
@@ -8,7 +8,7 @@ all: all-yes
8 8
 include $(SRC_PATH)/arch.mak
9 9
 
10 10
 OBJS      += $(OBJS-yes)
11
-FFLIBS    := $(FFLIBS-yes) $(FFLIBS)
11
+FFLIBS    := $(FFLIBS-$(NAME)) $(FFLIBS-yes) $(FFLIBS)
12 12
 TESTPROGS += $(TESTPROGS-yes)
13 13
 
14 14
 LDLIBS       = $(FFLIBS:%=%$(BUILDSUF))
... ...
@@ -655,6 +655,15 @@ prepend(){
655 655
     eval "$var=\"$* \$$var\""
656 656
 }
657 657
 
658
+unique(){
659
+    var=$1
660
+    uniq_list=""
661
+    for tok in $(eval echo \$$var); do
662
+        uniq_list="$(filter_out $tok $uniq_list) $tok"
663
+    done
664
+    eval "$var=\"${uniq_list}\""
665
+}
666
+
658 667
 add_cppflags(){
659 668
     append CPPFLAGS "$@"
660 669
 }
... ...
@@ -2110,11 +2119,11 @@ metadata_example_deps="avformat avutil"
2110 2110
 output_example_deps="avcodec avformat avutil swscale"
2111 2111
 transcode_aac_example_deps="avcodec avformat avresample"
2112 2112
 
2113
-# libraries
2113
+# libraries, in linking order
2114 2114
 avcodec_deps="avutil"
2115
-avdevice_deps="avutil avcodec avformat"
2115
+avdevice_deps="avformat avcodec avutil"
2116 2116
 avfilter_deps="avutil"
2117
-avformat_deps="avutil avcodec"
2117
+avformat_deps="avcodec avutil"
2118 2118
 avresample_deps="avutil"
2119 2119
 swscale_deps="avutil"
2120 2120
 
... ...
@@ -4373,6 +4382,20 @@ for thread in $THREADS_LIST; do
4373 4373
     fi
4374 4374
 done
4375 4375
 
4376
+# conditional library dependencies, in linking order
4377
+enabled movie_filter    && prepend avfilter_deps "avformat avcodec"
4378
+enabled resample_filter && prepend avfilter_deps "avresample"
4379
+enabled scale_filter    && prepend avfilter_deps "swscale"
4380
+
4381
+expand_deps(){
4382
+    lib_deps=${1}_deps
4383
+    eval "deps=\$$lib_deps"
4384
+    append $lib_deps $(map 'eval echo \$${v}_deps' $deps)
4385
+    unique $lib_deps
4386
+}
4387
+
4388
+map 'expand_deps $v' $LIBRARY_LIST
4389
+
4376 4390
 echo "install prefix            $prefix"
4377 4391
 echo "source path               $source_path"
4378 4392
 echo "C compiler                $cc"
... ...
@@ -4578,6 +4601,8 @@ get_version(){
4578 4578
 
4579 4579
 map 'get_version $v' $LIBRARY_LIST
4580 4580
 
4581
+map 'eval echo "FFLIBS-${v}=\$${v}_deps" >> config.mak' $LIBRARY_LIST
4582
+
4581 4583
 print_program_libs(){
4582 4584
     eval "program_libs=\$${1}_libs"
4583 4585
     eval echo "LIBS-${1}=${program_libs}" >> config.mak
... ...
@@ -4639,13 +4664,18 @@ test -n "$WARNINGS" && printf "\n$WARNINGS"
4639 4639
 
4640 4640
 # build pkg-config files
4641 4641
 
4642
+lib_version(){
4643
+    eval printf "\"lib${1} >= \$LIB$(toupper ${1})_VERSION, \""
4644
+}
4645
+
4642 4646
 pkgconfig_generate(){
4643 4647
     name=$1
4644 4648
     shortname=${name#lib}${build_suffix}
4645 4649
     comment=$2
4646 4650
     version=$3
4647 4651
     libs=$4
4648
-    requires=$5
4652
+    requires=$(map 'lib_version $v' $(eval echo \$${name#lib}_deps))
4653
+    requires=${requires%, }
4649 4654
     enabled ${name#lib} || return 0
4650 4655
     mkdir -p $name
4651 4656
     cat <<EOF > $name/$name.pc
... ...
@@ -4680,15 +4710,10 @@ Cflags: -I\${includedir}
4680 4680
 EOF
4681 4681
 }
4682 4682
 
4683
-lavfi_libs="libavutil = $LIBAVUTIL_VERSION"
4684
-enabled movie_filter    && prepend lavfi_libs "libavformat >= $LIBAVFORMAT_VERSION, libavcodec >= $LIBAVCODEC_VERSION,"
4685
-enabled resample_filter && prepend lavfi_libs "libavresample >= $LIBAVRESAMPLE_VERSION,"
4686
-enabled scale_filter    && prepend lavfi_libs "libswscale >= $LIBSWSCALE_VERSION,"
4687
-
4688 4683
 pkgconfig_generate libavutil     "Libav utility library"          "$LIBAVUTIL_VERSION"     "$LIBM"
4689
-pkgconfig_generate libavcodec    "Libav codec library"            "$LIBAVCODEC_VERSION"    "$extralibs" "libavutil = $LIBAVUTIL_VERSION"
4690
-pkgconfig_generate libavformat   "Libav container format library" "$LIBAVFORMAT_VERSION"   "$extralibs" "libavcodec = $LIBAVCODEC_VERSION"
4691
-pkgconfig_generate libavdevice   "Libav device handling library"  "$LIBAVDEVICE_VERSION"   "$extralibs" "libavformat = $LIBAVFORMAT_VERSION"
4692
-pkgconfig_generate libavfilter   "Libav video filtering library"  "$LIBAVFILTER_VERSION"   "$extralibs" "$lavfi_libs"
4693
-pkgconfig_generate libavresample "Libav audio resampling library" "$LIBAVRESAMPLE_VERSION" "$extralibs" "libavutil = $LIBAVUTIL_VERSION"
4694
-pkgconfig_generate libswscale    "Libav image rescaling library"  "$LIBSWSCALE_VERSION"    "$LIBM"      "libavutil = $LIBAVUTIL_VERSION"
4684
+pkgconfig_generate libavcodec    "Libav codec library"            "$LIBAVCODEC_VERSION"    "$extralibs"
4685
+pkgconfig_generate libavformat   "Libav container format library" "$LIBAVFORMAT_VERSION"   "$extralibs"
4686
+pkgconfig_generate libavdevice   "Libav device handling library"  "$LIBAVDEVICE_VERSION"   "$extralibs"
4687
+pkgconfig_generate libavfilter   "Libav video filtering library"  "$LIBAVFILTER_VERSION"   "$extralibs"
4688
+pkgconfig_generate libavresample "Libav audio resampling library" "$LIBAVRESAMPLE_VERSION" "$extralibs"
4689
+pkgconfig_generate libswscale    "Libav image rescaling library"  "$LIBSWSCALE_VERSION"    "$LIBM"
... ...
@@ -1,5 +1,4 @@
1 1
 NAME = avcodec
2
-FFLIBS = avutil
3 2
 
4 3
 HEADERS = avcodec.h                                                     \
5 4
           avfft.h                                                       \
... ...
@@ -1,5 +1,4 @@
1 1
 NAME    = avdevice
2
-FFLIBS  = avformat avcodec avutil
3 2
 
4 3
 HEADERS = avdevice.h                                                    \
5 4
           version.h                                                     \
... ...
@@ -1,9 +1,4 @@
1 1
 NAME = avfilter
2
-FFLIBS = avutil
3
-FFLIBS-$(CONFIG_ASYNCTS_FILTER) += avresample
4
-FFLIBS-$(CONFIG_MOVIE_FILTER) += avformat avcodec
5
-FFLIBS-$(CONFIG_RESAMPLE_FILTER) += avresample
6
-FFLIBS-$(CONFIG_SCALE_FILTER)   += swscale
7 2
 
8 3
 HEADERS = avfilter.h                                                    \
9 4
           avfiltergraph.h                                               \
... ...
@@ -1,5 +1,4 @@
1 1
 NAME = avformat
2
-FFLIBS = avcodec avutil
3 2
 
4 3
 HEADERS = avformat.h                                                    \
5 4
           avio.h                                                        \
... ...
@@ -1,5 +1,4 @@
1 1
 NAME = avresample
2
-FFLIBS = avutil
3 2
 
4 3
 HEADERS = avresample.h                                                  \
5 4
           version.h                                                     \
... ...
@@ -1,5 +1,4 @@
1 1
 NAME = swscale
2
-FFLIBS = avutil
3 2
 
4 3
 HEADERS = swscale.h                                                     \
5 4
           version.h                                                     \