帮我写一个makefile文件。我有一个程序叫parser,对test文件夹下所有xxx.cmm都运行./parser xxx.cmm
时间: 2023-05-19 10:06:02 浏览: 121
跟我写makefile
Sure, here's a sample makefile that should work for your needs:
```
CC=gcc
CFLAGS=-Wall
SRC_DIR=test
OBJ_DIR=obj
BIN_DIR=bin
SRCS=$(wildcard $(SRC_DIR)/*.cmm)
OBJS=$(patsubst $(SRC_DIR)/%.cmm,$(OBJ_DIR)/%.o,$(SRCS))
BINS=$(patsubst $(SRC_DIR)/%.cmm,$(BIN_DIR)/%,$(SRCS))
.PHONY: all clean
all: $(BINS)
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cmm
$(CC) $(CFLAGS) -c $< -o $@
$(BIN_DIR)/%: $(OBJ_DIR)/%.o
$(CC) $(CFLAGS) $< -o $@
clean:
rm -f $(OBJ_DIR)/*.o $(BIN_DIR)/*
```
To use this makefile, simply place it in the same directory as your `test` folder and run `make`. This will compile all of the `.cmm` files in the `test` folder using the `parser` program and output the resulting executables in the `bin` folder. You can then run each executable as desired.
阅读全文