gpt4 book ai didi

makefile - 我的 Makefile 中有硬编码路径 - 如何使用 ocamlfind 消除这些路径? (或如何改用 ocamlbuild 或 omake)

转载 作者:行者123 更新时间:2023-12-01 11:54:08 25 4
gpt4 key购买 nike

我正在尝试构建一个需要 camlp4 扩展(在本例中为 pa_deriving)的 ocaml 项目。这是我的 Makefile:

include ./Makefile.config

OCAMLC := ${OCAMLFIND} ocamlc
OCAMLOPT := ${OCAMLFIND} ocamlopt
OCAMLDEP := ${OCAMLFIND} ocamldep
PP := -package camlp4 -ppopt /home/p/godi-3.12.1.0/lib/ocaml/site-lib/deriving-ocsigen/pa_deriving.cma -syntax camlp4o
LIBS := -I /home/p/godi-3.12.1.0/lib/ocaml/site-lib/deriving-ocsigen -package unix -package oUnit

OCAMLFLAGS = -w Aef

SOURCES = logic.ml \
fsm.ml \
test_logic.ml


test_logic: ${SOURCES:.ml=.cmo}
${OCAMLC} -o $@ ${LIBS} -linkpkg deriving.cma $^

# Common rules

%.cmi: %.mli
${OCAMLC} ${OCAMLFLAGS} ${PP} ${LIBS} -c $<
%.cmo: %.ml
${OCAMLC} ${OCAMLFLAGS} ${PP} ${LIBS} -c $<
%.cmx: %.ml
${OCAMLOPT} ${OCAMLFLAGS} ${PP} ${LIBS} -c $<

# Clean up
clean:
-rm -f *.cm[ioax] *.cmxa *.cmxs *${OBJEXT} *${LIBEXT} *.annot
-rm -f tests${EXEEXT}
distclean: clean
-rm -f *~ \#* .\#*

# Dependencies
depend:
${OCAMLDEP} ${PP} *.ml *.mli > .depend

-include .depend

这个 Makefile 有效;它完成了工作,但问题是我上面有硬编码路径,例如:/home/p/godi-3.12.1.0/lib/ocaml/site-lib/deriving-ocsigen/pa_deriving.cma 指的是我的 OCaml 安装。我想摆脱这些,以便我可以分发代码和 Makefile,这样任何人都可以使用它进行构建。

我应该为此使用 omake 还是 ocamlbuild?我想使用 omake 并且我已经为此使用了 OMakefile,但无法使任何工作正常进行 - 任何建议将不胜感激。

更新:我尝试将 ocamlbuild 与以下 _tags 文件一起使用:

<*.ml>: package(unix), package(oUnit), package(deriving-ocsigen.syntax), syntax(camlp4o)

使用以下 ocamlbuild 命令: ocamlbuild -use-ocamlfind test_logic.native -经典显示

然后我得到:

/home/phil/godi-3.12.1.0/bin/ocamlfind ocamldep -package deriving-ocsigen.syntax -package oUnit -package unix -syntax camlp4o -modules fsm.ml > fsm.ml.depends  
/home/phil/godi-3.12.1.0/bin/ocamlfind ocamldep -package deriving-ocsigen.syntax -package oUnit -package unix -syntax camlp4o -modules logic.ml > logic.ml.depends
/home/phil/godi-3.12.1.0/bin/ocamlfind ocamlc -c -package deriving-ocsigen.syntax -package oUnit -package unix -syntax camlp4o -o logic.cmo logic.ml
/home/phil/godi-3.12.1.0/bin/ocamlfind ocamlc -c -package deriving-ocsigen.syntax -package oUnit -package unix -syntax camlp4o -o fsm.cmo fsm.ml
/home/phil/godi-3.12.1.0/bin/ocamlfind ocamlopt -c -package deriving-ocsigen.syntax -package oUnit -package unix -syntax camlp4o -o logic.cmx logic.ml
/home/phil/godi-3.12.1.0/bin/ocamlfind ocamlopt -c -package deriving-ocsigen.syntax -package oUnit -package unix -syntax camlp4o -o fsm.cmx fsm.ml
/home/phil/godi-3.12.1.0/bin/ocamlfind ocamlopt -linkpkg -linkpkg logic.cmx fsm.cmx test_logic.cmx -o test_logic.native
+ /home/phil/godi-3.12.1.0/bin/ocamlfind ocamlopt -linkpkg -linkpkg logic.cmx fsm.cmx test_logic.cmx -o test_logic.native
File "_none_", line 1, characters 0-1:
Error: No implementations provided for the following modules:
Deriving_Show referenced from test_logic.cmx
Deriving_Enum referenced from test_logic.cmx
OUnit referenced from test_logic.cmx

我需要在 _tags 文件中添加什么来纠正这个问题?

最佳答案

我看到您使用 ocamlbuild 解决了您的解决方案,它是美好的。在一般情况下,您可以使用 ocamlfind 查询scripts/Makefile作为查询信息的命令行界面关于 findlib 包,特别是避免硬编码路径。

$ ocamlfind query deriving-ocsigen 
/usr/lib/ocaml/deriving-ocsigen
$ ocamlfind query deriving-ocsigen -i-format
-I /usr/lib/ocaml/deriving-ocsigen
$ ocamlfind query deriving-ocsigen -predicates byte -a-format
deriving_num.cma
$ ocamlfind query deriving-ocsigen.syntax -predicates syntax,preprocessor -a-format
pa_deriving.cma
$ ocamlfind query deriving-ocsigen.syntax -predicates syntax,preprocessor -format "-I %d %a"
-I /usr/lib/ocaml/deriving-ocsigen pa_deriving.cma

关于makefile - 我的 Makefile 中有硬编码路径 - 如何使用 ocamlfind 消除这些路径? (或如何改用 ocamlbuild 或 omake),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8696016/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com