-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
51 lines (48 loc) · 1.22 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
#directories
IDIR = inc
ODIR = obj
SDIR = src
#compiler settings
CC=clang
CFLAGS=-I $(IDIR)
CCFLAGS = -std=c11 -Wall -Wextra -Werror -Wpedantic -I $(IDIR)
#dependencies
NAME = libmx.a
TEST = test
#headers
_DEPS = libmx.h
DEPS = $(patsubst %,$(IDIR)/%,$(_DEPS))
#sources
SRCS := $(wildcard $(SDIR)/mx_*.c)
#objects
_OBJS = $(SRCS:.c=.o)
OBJS = $(subst $(SDIR),$(ODIR),$(_OBJS))
all: $(NAME)
#make objects
$(ODIR)/%.o: $(SDIR)/%.c $(DEPS)
@mkdir -p obj
@printf "\33[2KCompiling \33[0;32m$<\33[m\r"
@$(CC) -c -o $@ $< $(CCFLAGS)
#make library
$(NAME): $(OBJS)
@printf "\r\33[2KLinking library... \33[0;33m$@\33[m"
@ar -rc $@ $^
@printf "\r\33[2KSuccesfully linked \33[0;32m$@\33[m. Enjoy!\n"
#executable for tests
$(TEST): $(NAME)
@printf "\r\33[2KCompiling test cases... \33[0;33m$@\33[m"
@$(CC) $(CCFLAGS) -Wno-nonnull $(SDIR)/$(TEST).c $< -o $@
@printf "\r\33[2K\33[0;32mTests compiled succesfully!\33[m\n"
@./test
.PHONY: clean uninstall reinstall
#delete all files
uninstall: clean
@printf "\r\33[2K\33[0;33mUninstalling library...\33[m\n"
@rm -f $(NAME) $(TEST)
#remove all temporary files
clean:
@printf "\r\33[2K\33[0;33mRemoving temporary files...\33[m\n"
@rm -rf $(ODIR)
@rm -f *.a
#rebuild project
reinstall: uninstall all