-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
45 lines (32 loc) · 805 Bytes
/
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
.PHONY: clean all run
.DEFAULT_GOAL := all
BIN_NAME=minesweeper
CC=gcc
ODIR=obj
BDIR=bin
CFLAGS=-Werror -Wall -pedantic
INCS=
LIBS=
SRCS=$(wildcard *.c)
OBJS=$(patsubst %.c,$(ODIR)/%.o,$(filter-out $(patsubst %,%.c,$(BIN_NAME)), $(SRCS)))
BINS=$(patsubst %,$(BDIR)/%,$(BIN_NAME))
.depend: $(SRCS)
$(CC) $(CFLAGS) -MM $^ > ./.depend
sed -i.bak -e 's/^/${ODIR}\//' ./.depend && rm ./.depend.bak
-include .depend
$(BDIR) $(ODIR):
@echo "MKDIR $@"
@mkdir -p $@
$(ODIR)/%.o: $(ODIR)
@echo "GCC $^ -> $@"
@$(CC) -c -o $@ $< $(CFLAGS) $(INCS)
$(BINS): $(BDIR)/%: $(ODIR)/%.o $(OBJS) | $(BDIR)
@echo "GCC $@"
@gcc -o $@ $^ $(CFLAGS) $(LIBS)
all: $(BINS)
clean:
@echo "CLEAN $(ODIR) $(BDIR) .depend"
@rm -rf $(ODIR) $(BDIR) .depend
run: $(BINS)
@echo "RUN $@"
@./$(BDIR)/$(BIN_NAME)