aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: b6d3c294f322c0cf094af5e88caeb0269184cb43 (plain)
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
# ############################################################################ #
#                                                                              #
#                                                             .                #
#    Makefile                                                / \               #
#                                                           /   \              #
#    By: charles <charles.cabergs@gmail.com>               /o  o \             #
#                                                         /  v    \            #
#    Created: 2020/06/27 13:12:43 by charles             /    _    \           #
#    Updated: 2020/06/28 07:50:23 by charles            '-----------'          #
#                                                                              #
# ############################################################################ #

RM = rm -f

INCDIR = inc
SRCDIR = src
OBJDIR = obj
OBJDIRS = $(shell find $(SRCDIR) -type d | sed 's/src/$(OBJDIR)/')

INC = $(shell find $(INCDIR) -name "*.h")
SRC = $(shell find $(SRCDIR) -name "*.c")
OBJ = $(SRC:$(SRCDIR)/%.c=$(OBJDIR)/%.o)

CC = gcc
CCFLAGS = -I$(INCDIR) -Wall -Wextra -Wpedantic #-Werror
LDFLAGS = -lncurses

NAME = hanoi

all: prebuild $(NAME)

prebuild:
	@for subdir in $(OBJDIRS); do mkdir -vp $$subdir; done

$(NAME): $(OBJ)
	@echo "Linking: $@"
	$(CC) -o $@ $(OBJ) $(LDFLAGS)

$(OBJDIR)/%.o: $(SRCDIR)/%.c $(INC)
	@echo "Compiling: $@"
	@$(CC) $(CCFLAGS) -c -o $@ $<

clean:
	@echo "Removing objects"
	@$(RM) -r $(OBJDIR)

fclean:
	@echo "Removing objects"
	@$(RM) -r $(OBJDIR)
	@echo "Removing exectable"
	@$(RM) $(NAME)

re: fclean all

.PHONY: all prebuild clean fclean re