通过ocaml和cpp扩展生成文件

时间:2020-05-26 09:21:42

标签: c++ makefile

我在同一目录中有大量.ml.cpp文件,它们彼此完全独立。我有什么方法可以使用Makefile编译它们而无需使用外部bash / shell脚本?

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 $@ $< 

仅识别我的Makefile文件的.cpp有什么问题:

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

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

谢谢。

1 个答案:

答案 0 :(得分:2)

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

.SUFFIXES: .cpp .ml

但是,更好的方法是使用模式规则,以便完全放弃使用.SUFFIXES

%: %.ml
    $(CCML) -o $@ $<
相关问题