我在试着让libtool和yasm合作。
yasm从我的.asm源代码创建了正确的.o files,但是我不知道如何让libtool构建相关的.lo和.dep文件。它希望通过合并.o文件来构建共享库。
发布于 2016-09-14 10:41:43
libtool生成的文件通常使用以下布局:包含位置元数据的build目录中的.lo文件;build目录中的静态对象.o文件;以及build/.libs目录中的PIC / shared .o对象。
您可以使用libtool编译模式。我不熟悉yasm,所以你必须填写开关。它将运行两次yasm构建,一次使用-DPIC (可能还有其他共享对象选项)。
libtool --tag=CC --mode=compile yasm <options> src.asm
如果使用automake,这可能需要对.asm文件使用明确的规则:
.asm.lo:
$(LIBTOOL) --tag=CC --mode=compile \
yasm <options> $<请记住,这些是Makefiles中的制表符,而不是(8)空格字符!您可能还需要在此之前添加:.SUFFIXES: .asm .lo。我使用变量$(LIBTOOL),因为有些平台(例如OSX)需要将其安装为glibtool,而Makefile.in就是这么做的。
例如,生成的src.lo、src.o、.libs/src.o应该由make clean遵守。
对于你的库libfoo,你需要用:EXTRA_libfoo_la_SOURCES = src.asm让automake知道这些源代码,用libfoo_la_LIBADD = src.lo让automake知道这些源代码。甚至有必要将其添加到依赖项:libfoo_la_DEPENDENCIES = src.lo。
尽管我不明白为什么仅仅将src.asm放在libfoo_la_SOURCES中是不够的。
发布于 2016-09-16 04:34:45
这是可行的(尽管我从未想过如何让libtool在目标目录中创建.lo文件,或者创建目标目录的.libs目录)。
Makefile规则:
# Rule to build object files from asm files.
#
# XXX
# Libtool creates the .lo file in the directory where make is run. Move the file
# into place explicitly; I'm sure this is wrong, but have no idea how to fix it.
# Additionally, in a parallel make, the .libs file may not yet be created, check
# as necessary, but ignore errors.
.asm.lo:
-d=`dirname $@`; test $d/.libs || mkdir $d/.libs
$(LIBTOOL) --tag=CC --mode=compile sh $(srcdir)/dist/yasm.sh $< $@
rm -f $@
mv `basename $@` $@执行yasm调用的支持shell脚本:
#! /bin/sh
# Libtool support for yasm files, expect the first argument to be a path to
# the source file and the second argument to be a path to libtool's .lo file.
# Use the second argument plus libtool's -o argument to set the real target
# file name.
source=$1
target=`dirname $2`
while test $# -gt 0
do
case $1 in
-o)
target="$target/$2"
shift; shift;;
*)
shift;;
esac
done
yasm -f x64 -f elf64 -X gnu -g dwarf2 -D LINUX -o $target $sourcehttps://stackoverflow.com/questions/39413673
复制相似问题