Makefile:make运行命令

Joe*_*Joe 0 c makefile

这是我的 makefile。我知道有一种更短的方法可以写出来,但我有一个关于如何运行它的问题。我的硬件说我必须使用命令: make run --- 该命令应该导致可执行文件使用文件重定向来运行以读取输入文件数据。

我该如何设置呢?

我也知道 gcc 应该是选项卡式的。

test:  main.o sum.o stack.o bSearch.o database.o db.o set.o parse.o bubble.o
    gcc -o object main.o sum.o stack.o bSearch.o db.o set.o parse.o bubble.o

main.o: main.c sum.h
gcc -c main.c

sum.o: sum.c sum.h
    gcc -c sum.c

stack.o: stack.c stack.h
    gcc -c stack.c

bSearch.o: bSearch.c defs.h sortAndsearch.h
    gcc -c bSearch.c

database.o: database.c defs.h parse.h
    gcc -c database.c

db.o: db.c defs.h
    gcc -c db.c

set.o: set.c set.h db.h
    gcc -c set.c

parse.o: parse.c parse.h
    gcc -c parse.c

bubble.o: bubble.c defs.h
    gcc -c bubble.c

sortAndsearch.h: db.h

defs.h: set.h sortAndsearch.h

stack.h: set.h

clean:
    rm *.o object
Run Code Online (Sandbox Code Playgroud)

Chr*_*ner 5

“run”就像 Makefile 中的任何其他目标一样,例如“test”或“set.o” - 但您必须将规则添加到 Makefile 中,以便 make 知道如何处理它。

run:
  ./test < input.txt
Run Code Online (Sandbox Code Playgroud)