pthreads/{hello → hello_w}/Makefile RENAMED
@@ -1,37 +1,41 @@
1
  # target: prerequisites
2
  # command to build target
3
 
4
- hello: hello.c
5
- cc -g -Wall -Wextra hello.c -o hello -pthread
 
 
 
 
6
 
7
  .PHONY: lint
8
  lint:
9
- cpplint hello.c
10
 
11
  .PHONY: memcheck
12
- memcheck: hello
13
- valgrind --tool=memcheck --leak-check=full ./hello
14
 
15
  .PHONY: helgrind
16
- helgrind: hello
17
- valgrind --tool=helgrind ./hello
18
 
19
  .PHONY: asan # invalid access & memory leaks
20
- asan: hello.c
21
- cc -g -Wall -Wextra -fsanitize=address hello.c -o hello -pthread
22
 
23
  .PHONY: msan # uninitialized memory
24
- msan: hello.c
25
- clang -g -Wall -Wextra -fsanitize=memory hello.c -o hello -pthread
26
 
27
  .PHONY: tsan # thread sanitizer
28
- tsan: hello.c
29
- cc -g -Wall -Wextra -fsanitize=thread hello.c -o hello -pthread
30
 
31
  .PHONY: ubsan # undefined behavior
32
- ubsan: hello.c
33
- cc -g -Wall -Wextra -fsanitize=undefined hello.c -o hello -pthread
34
 
35
  .PHONY: clean
36
  clean:
37
- rm -f hello
1
  # target: prerequisites
2
  # command to build target
3
 
4
+ APPNAME=$(shell basename $(shell pwd))
5
+ APPARGS=10
6
+ CFLAGS=-g -Wall -Wextra
7
+
8
+ $(APPNAME): $(APPNAME).c
9
+ cc $(CFLAGS) $< -o $@ -pthread
10
 
11
  .PHONY: lint
12
  lint:
13
+ cpplint --filter=-readability/casting $(APPNAME).c
14
 
15
  .PHONY: memcheck
16
+ memcheck: $(APPNAME)
17
+ valgrind --tool=memcheck --leak-check=full ./$(APPNAME) $(APPARGS)
18
 
19
  .PHONY: helgrind
20
+ helgrind: $(APPNAME)
21
+ valgrind --tool=helgrind ./$(APPNAME) $(APPARGS)
22
 
23
  .PHONY: asan # invalid access & memory leaks
24
+ asan: $(APPNAME).c
25
+ cc $(CFLAGS) -fsanitize=address $(APPNAME).c -o $(APPNAME) -pthread
26
 
27
  .PHONY: msan # uninitialized memory
28
+ msan: $(APPNAME).c
29
+ clang $(CFLAGS) -fsanitize=memory $(APPNAME).c -o $(APPNAME) -pthread
30
 
31
  .PHONY: tsan # thread sanitizer
32
+ tsan: $(APPNAME).c
33
+ cc $(CFLAGS) -fsanitize=thread $(APPNAME).c -o $(APPNAME) -pthread
34
 
35
  .PHONY: ubsan # undefined behavior
36
+ ubsan: $(APPNAME).c
37
+ cc $(CFLAGS) -fsanitize=undefined $(APPNAME).c -o $(APPNAME) -pthread
38
 
39
  .PHONY: clean
40
  clean:
41
+ rm -f $(APPNAME)