繁体   English   中英

Makefile 通过 ocaml 和 cpp 扩展

[英]Makefile by ocaml and cpp extension

我在同一个目录中有大量.ml.cpp文件,它们完全相互独立。 有什么方法可以在不使用外部 bash / shell 脚本的情况下使用Makefile编译它们?

CC=g++
CFLAGS=-Wall -std=c++14 -Wno-unused-variable
CCML=ocamlc
SHELL := '/bin/bash'
.SUFFIXES = .cpp .ml

cpp_objs:=$(wildcard *.cpp)
ml_objs:=$(wildcard *.ml)
cpp_targets:=$(cpp_objs:.cpp= )
ml_targets:=$(ml_objs:.ml= )

targets:=$(cpp_targets) $(ml_targets)

.PHONY:all
all: $(targets) 
# all: $(cpp_targets) 
.ml: 
    $(CCML) -o $@ $<
.cpp:
    $(CC) $(CFLAGS) -o $@ $< 

这个只识别我的.cpp文件的Makefile有什么问题:

make: *** No rule to make target `[ML-FILES]', needed by `all'.  Stop.

更新:所有*.ml*.cpp文件在目录中都有唯一的名称。

谢谢。

根据手册,您应该将.SUFFIXES配置为目标,而不是变量:

.SUFFIXES: .cpp .ml

但是,更好的方法是使用模式规则,这样您就可以完全放弃使用.SUFFIXES

%: %.ml
    $(CCML) -o $@ $<

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM