+# Order the libraries passed to us correctly for static linking.
+#
+# While the libraries order doesn't matter when linking dynamically, we must
+# put the libraries depending on other libraries in front of their dependencies
+# when linking statically or the dependencies wouldn't be resolved by the
+# standard UNIX linkers.
+order_libs()
+{
+ if is_static; then
+ for lib do
+ # Distinguish between the libraries that may need to be moved to
+ # the end of the list (because other ones may depend on them) and
+ # those that can be output immediately because no other libraries
+ # depend on them.
+ case "$lib" in
+ base|core|html|xml|adv) eval "use_$lib=1" ;;
+ *) libs="$libs $lib" ;;
+ esac
+ done
+
+ # Add the libraries that we postponed adding above.
+ # Order of the checks here is important.
+ [ -z "$use_html" ] || libs="$libs html"
+ [ -z "$use_adv" ] || libs="$libs adv"
+ [ -z "$use_core" ] || libs="$libs core"
+ [ -z "$use_xml" ] || libs="$libs xml"
+ [ -z "$use_base" ] || libs="$libs base"
+ else
+ # No need to order them.
+ libs="$@"
+ fi
+
+ echo $libs
+}
+