#!/bin/bash
args=("$@")
for ((arg=0; arg<${#args[@]}; arg++)) ; do
    if test x"${args[$arg]}" = x-o ; then
        objarg=$((arg+1))
        break
    fi
done
if test x$objarg = x ; then
    echo 'Error: no -o on compiler command line' 1>&2
    exit 1
fi
lo="${args[$objarg]}"
obj="${lo%.lo}"
if test x"$lo" = x"$obj" ; then
    echo "Error: libtool object file name \"$lo\" does not end in .lo" 1>&2
    exit 1
fi
objbase="${obj##*/}"
libobjdir="${obj%$objbase}.libs"
if test ! -d "$libobjdir" ; then
    mkdir_out="$(mkdir "$libobjdir" 2>&1)"
    mkdir_ret=$?
    if test "$mkdir_ret" -ne 0 && test ! -d "$libobjdir" ; then
	echo "$mkdir_out" 1>&2
        exit $mkdir_ret
    fi
fi
pic_object="$libobjdir/$objbase.o"
args[$objarg]="$pic_object"
"${args[@]}" -fPIC -DPIC || exit $?
{
echo "# $lo - a libtool object file"
echo "# Generated by doltcompile, not libtool"
echo "pic_object='.libs/${objbase}.o'"
echo non_pic_object=none
} > "$lo"
