帮我写一个makefile文件。我有一个程序叫parser,遍历test文件夹下所有xxx.cmm都运行./parser xxx.cmm
时间: 2023-05-19 15:06:05 浏览: 119
跟我写makefile
Sure, here's a sample makefile that should work for you:
```
CC=gcc
CFLAGS=-Wall -Wextra -pedantic -std=c99
SRCDIR=./test
OBJDIR=./obj
BINDIR=./bin
SRCS=$(wildcard $(SRCDIR)/*.cmm)
OBJS=$(patsubst $(SRCDIR)/%.cmm,$(OBJDIR)/%.o,$(SRCS))
BINS=$(patsubst $(SRCDIR)/%.cmm,$(BINDIR)/%,$(SRCS))
.PHONY: all clean
all: $(BINS)
$(BINDIR)/%: $(OBJDIR)/%.o
$(CC) $(CFLAGS) $< -o $@
$(OBJDIR)/%.o: $(SRCDIR)/%.cmm
$(CC) $(CFLAGS) -c $< -o $@
clean:
rm -f $(OBJS) $(BINS)
```
You can save this as a file named `Makefile` in the same directory as your `parser` program and the `test` folder. Then, simply run `make` in the terminal to compile all the `xxx.cmm` files in the `test` folder and generate corresponding executables in the `bin` folder.
阅读全文