-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathMakefile
73 lines (54 loc) · 1.7 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
CC?=gcc
CFLAGS=-Wall -std=c99
LFLAGS=
TARGET=libtar.a
AR=ar
.PHONY: clean-test
all: $(TARGET) exec
tar.o: tar.h tar.c
$(CC) $(CFLAGS) -c tar.c
$(TARGET): tar.o
$(AR) -r $(TARGET) tar.o
exec: $(TARGET) main.c
$(CC) $(CFLAGS) main.c -o exec -ltar -L.
test: exec clean-test
@echo "create fake directory entries"
@touch file
@mkdir folder
@touch folder/a
@mkfifo pipe
@ln -s file sym
@mknod block b 1 2
@mknod char c 3 4
@echo "archive the files with GNU tar"
@tar -cf test.tar file folder pipe sym block char char block sym pipe folder file
@echo "remove original directory entries"
@rm -r file folder pipe sym block char
@echo "test extraction with tarball created by GNU tar"
@./exec x test.tar || (echo "fail" && exit 1)
@echo "test archive"
@./exec c test.tar file folder pipe sym block char char block sym pipe folder file || (echo "fail" && exit 1)
@echo "remove nonexistent entry from tarball"
@./exec r test.tar nonexistent && (echo "fail" && exit 1) || true
@echo "remove entries from tarball"
@./exec r test.tar folder/ block || (echo "fail" && exit 1)
@echo "diff tar -t and exec -t"
@tar -vtf test.tar > real
@./exec tv test.tar > out
@diff -bu real out || (echo "fail" && exit 1)
@rm -f real out
@echo "restore removed entries"
@./exec a test.tar block folder/ || (echo "fail" && exit 1)
@echo "diff tar -t and exec -t"
@tar -vtf test.tar > real
@./exec tv test.tar > out
@diff -bu real out || (echo "fail" && exit 1)
@rm real out
@echo "extract the files with GNU tar"
@tar -xf test.tar || (echo "fail" && exit 1)
@echo "clean up"
@$(MAKE) clean-test
clean-test:
rm -rf test.tar char block sym pipe folder file real out
clean: clean-test
rm -f tar.o $(TARGET) ./exec