Blame build/win32/lt-compile-resource

Packit a7402c
#!/bin/sh
Packit a7402c
Packit a7402c
# Script to compile a resource file for a DLL in the same way that
Packit a7402c
# libtool would, if it knew about .rc files.
Packit a7402c
Packit a7402c
# This kinda sucks, but the alternative would be to teach autoconf,
Packit a7402c
# automake, and libtool about compiling .rc files.  That would be
Packit a7402c
# doable, but waiting for those changes to propagate to official
Packit a7402c
# versions of those tools would take some time.
Packit a7402c
Packit a7402c
# The command line arguments are:
Packit a7402c
# $1: the name of the .rc file to compile if it exists
Packit a7402c
# $2: the name of the resource libtool object file to produce
Packit a7402c
Packit a7402c
rcfile=$1
Packit a7402c
lo=$2
Packit a7402c
case "$lo" in
Packit a7402c
*.lo) 
Packit a7402c
    resfile=.libs/`basename $lo .lo`.o
Packit a7402c
    ;;
Packit a7402c
*)
Packit a7402c
    echo libtool object name should end with .lo
Packit a7402c
    exit 1
Packit a7402c
    ;;
Packit a7402c
esac
Packit a7402c
d=`dirname $0`
Packit a7402c
Packit a7402c
# Create .libs if not there already
Packit a7402c
[ ! -d .libs ] && mkdir .libs
Packit a7402c
Packit a7402c
# Super-ugly hack: libtool can work in two ways on Win32: Either it
Packit a7402c
# uses .lo files which are the real object files in "this" directory,
Packit a7402c
# or it creates .o files in the .libs subdirectory, and the .lo file
Packit a7402c
# is a small text file. We try to deduce which case this is by
Packit a7402c
# checking if there are any .o files in .libs. This requires that the
Packit a7402c
# resource file gets built last in the Makefile.
Packit a7402c
Packit a7402c
o_files_in_dotlibs=`echo .libs/*.o`
Packit a7402c
case "$o_files_in_dotlibs" in
Packit a7402c
    .libs/\*.o)
Packit a7402c
	use_script=false
Packit a7402c
	;;
Packit a7402c
    *)  use_script=true
Packit a7402c
	;;
Packit a7402c
esac
Packit a7402c
Packit a7402c
# Another way of working of libtool: When compiling with --enable-static and
Packit a7402c
# --disable-shared options, the .lo file can be still a small text file, and
Packit a7402c
# the .o files are created in the same directory as the .lo files.
Packit a7402c
Packit a7402c
o_files_in_dot=`echo ./*.o`
Packit a7402c
case "$o_files_in_dot" in
Packit a7402c
    ./\*.o)
Packit a7402c
    	use_script=$use_script
Packit a7402c
    	;;
Packit a7402c
    *)	use_script=true
Packit a7402c
    	;;
Packit a7402c
esac    	
Packit a7402c
Packit a7402c
# Try to compile resource file
Packit a7402c
$d/compile-resource $rcfile $resfile && {
Packit a7402c
    if [ $use_script = true ]; then
Packit a7402c
	# Handcraft a libtool object
Packit a7402c
	# libtool checks for a second line matching "Generated by .* libtool"!
Packit a7402c
	(echo "# $lo"
Packit a7402c
	echo "# Generated by lt-compile-resource, compatible with libtool"
Packit a7402c
	echo "pic_object=$resfile"
Packit a7402c
	echo "non_pic_object=none") >$lo
Packit a7402c
    else
Packit a7402c
	mv $resfile $lo
Packit a7402c
    fi
Packit a7402c
    # Success
Packit a7402c
    exit 0
Packit a7402c
}
Packit a7402c
Packit a7402c
# If unsuccessful (no .rc file, or some error in it) return failure
Packit a7402c
Packit a7402c
exit 1