# -*- shell-script -*-
# mknetrel.libtool -- libtool fixups

fix_libtool_dltool () {
    sed -i~ \
	-e "s/^DLLTOOL=.*/DLLTOOL='$target-dlltool'/" \
        -e "s/^DLLTOOL=/HOST_CC=gcc\nDLLTOOL=/" \
        -e "s/^HOST_CC=/SED=sed\nHOST_CC=/" \
        -e "s/^allow_undefined_flag=.*/allow_undefined_flag=/" \
	$1
##	-e "s@^sys_lib_dlsearch_path_spec=.*@sys_lib_dlsearch_path_spec='$cygwin_prefix/lib'@"
}

fix_libtool_dlopen_undefined () {
    for i in $(find $build -name libtool); do
	sed -i~ -e 's/\(allow_undefined_flag=.*\)unsupported/\1/' $i
    done
}
    
fix_libtool_script () {
    [ $base != "libtool" ] || return 0
    for i in $mknetrel_root/bin/$target-libtool \
	$cygwin_prefix/bin/$target-libtool; do
	[ -x "$i" ] && fixtool=$i
    done
    for i in $(find $build -name libtool); do
	[ -n "$fixtool" ] || exit 1
	cp --backup $fixtool $i
    done
}

fix_libtool_la () {
    # fix libtool's .la dependency_libs output for dlopen
    for i in $inst/lib $inst/$prefix/lib; do
	if [ -d "$i" ]; then
	    cd $i || exit 1
	    for j in $(ls -1 *.la); do
		sed -i~ \
		    -e 's/ *-L *[^"'"'"' ][^"'"'"' ]*//g'\
		    -e "s@\( \|=\)\(/usr/lib/lib\)@\1$cygwin_root\2@g"\
		    $j
	    done
	fi
    done

    # fix some libtool's .dll name
    mv $inst/$prefix/lib/$dll_prefix$base-$sover $inst/$prefix/bin/$dll_prefix$base-$sover.dll

    # more libtool fixups.  I love libtool.
    sed -i~ \
	-e "s@^dlname=.*@dlname='../bin/$dll_prefix$base-$sover.dll'@" \
	-e "s@^library_names=.*@library_names='$dll_prefix$base.dll.a'@" \
	-e "s@^old_library=.*@old_library='$dll_prefix$base.a'@" \
	$inst/$prefix/lib/lib$base.la
}
