逐个执行命令

时间:2016-11-22 18:36:17

标签: makefile

我有以下Makefile

CC := clang++
CFLAGS := -std=c++1z
BINARY := -g -Wall -Wextra -Wformat -Werror -pedantic
OPTIMIZE := -Ofast -march=native -ffast-math
CPPCOREGUIDELINES := clang-tidy

SRC := $(wildcard *.cpp)
BIN := $(patsubst %.cpp,bin/%,$(SRC))

all: clean cpp

clean:
  mkdir -p ./bin
  rm -f bin/*

cpp: $(BIN)
$(BIN): bin/%: %.cpp
  $(CC) $(CFLAGS) $(BINARY) $(OPTIMIZE) $^ -o $@

checks: $(SRC)
  $(CPPCOREGUIDELINES) $^ -- $(CFLAGS) $(BINARY) $(OPTIMIZE)

这样执行checks

$ make checks
clang-tidy 007-pointer.cpp 008-arrays-introduction-smarter.cpp -- -std=c++1z -g -Wall -Wextra -Wformat -Werror -pedantic -Ofast -march=native -ffast-math
81 warnings generated.
393 warnings generated.
C:\www\cpp\hackerrank\007-pointer.cpp:16:3: warning: do not call c-style vararg functions [cppcoreguidelines-pro-type-vararg]
  scanf("%d %d", &a, &b);
  ^
C:\www\cpp\hackerrank\007-pointer.cpp:18:3: warning: do not call c-style vararg functions [cppcoreguidelines-pro-type-vararg]
  printf("%d\n%d", a, b);
  ^
C:\www\cpp\hackerrank\008-arrays-introduction-smarter.cpp:19:12: warning: do not use pointer arithmetic [cppcoreguidelines-pro-bounds-pointer-arithmetic]
    cin >> t[i];
           ^
C:\www\cpp\hackerrank\008-arrays-introduction-smarter.cpp:22:13: warning: do not use pointer arithmetic [cppcoreguidelines-pro-bounds-pointer-arithmetic]
    cout << t[i] << " ";
            ^
...

我希望在每个文件之后逐个执行checks

$ make checks
clang-tidy 007-pointer.cpp -- -std=c++1z -g -Wall -Wextra -Wformat -Werror -pedantic -Ofast -march=native -ffast-math
81 warnings generated.
C:\www\cpp\hackerrank\007-pointer.cpp:16:3: warning: do not call c-style vararg functions [cppcoreguidelines-pro-type-vararg]
  scanf("%d %d", &a, &b);
  ^
C:\www\cpp\hackerrank\007-pointer.cpp:18:3: warning: do not call c-style vararg functions [cppcoreguidelines-pro-type-vararg]
  printf("%d\n%d", a, b);
  ^
clang-tidy 008-arrays-introduction-smarter.cpp -- -std=c++1z -g -Wall -Wextra -Wformat -Werror -pedantic -Ofast -march=native -ffast-math
312 warnings generated.
C:\www\cpp\hackerrank\008-arrays-introduction-smarter.cpp:19:12: warning: do not use pointer arithmetic [cppcoreguidelines-pro-bounds-pointer-arithmetic]
    cin >> t[i];
           ^
C:\www\cpp\hackerrank\008-arrays-introduction-smarter.cpp:22:13: warning: do not use pointer arithmetic [cppcoreguidelines-pro-bounds-pointer-arithmetic]
    cout << t[i] << " ";
            ^
...

我该怎么做?

1 个答案:

答案 0 :(得分:1)

然后一个接一个地做:

checks: $(patsubst %.cpp,%.check,${SRC})
%.check : %.cpp
    $(CPPCOREGUIDELINES) $< -- $(CFLAGS) $(BINARY) $(OPTIMIZE)
.PHONY: %.check checks