-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
61 lines (46 loc) · 1.1 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
# Reference: https://www.cs.colby.edu/maxwell/courses/tutorials/maketutor/
# Set compiler & flags
# Set `-I src` since header files are in src/ directory
CC=gcc
CFLAGS=-std=c11 -I src
# Executables
EXEC=sha512
EXEC_TEST=test.o
# Directories
SDIR=src
ODIR=obj
TEST_DIR=tests
INS_DIR=/usr/local/bin
# Object files for running the main program
OBJS=$(patsubst %,$(ODIR)/%,$(_OBJS))
_OBJS=main.o sha512.o utils.o
# Object files for running the tests
OBJS_TEST=$(patsubst %,$(ODIR)/%,$(_OBJS_TEST))
_OBJS_TEST=test_sha512.o sha512.o utils.o
# Builds SHA-512 executable
all: init $(EXEC)
@echo "Build complete."
# Creates output directory
init:
@mkdir -p $(ODIR)/
# Compiles src files
$(ODIR)/%.o: $(SDIR)/%.c
$(CC) $(CFLAGS) -c $< -o $@
$(EXEC): $(OBJS)
$(CC) $(CFLAGS) -o $@ $^
# Compiles test files
$(ODIR)/%.o: $(TEST_DIR)/%.c
$(CC) $(CFLAGS) -c $< -o $@
$(EXEC_TEST): $(OBJS_TEST)
$(CC) $(CFLAGS) -o $@ $^
# Compiles and runs the test executable
test: init $(EXEC_TEST)
./$(EXEC_TEST)
rm $(EXEC_TEST)
install:
cp $(EXEC) $(INS_DIR)/
uninstall:
rm $(INS_DIR)/$(EXEC)
clean:
rm -rf $(ODIR)/
rm -f $(EXEC)