-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
48 lines (39 loc) · 933 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
46
47
48
CC = gcc
BINDIR = bin
BUILDDIR = build
INCDIR = include
LIBDIR = lib
SRCDIR = src
TESTDIR = test
SRCEXT = c
EXE = tinysh
LIB = -L$(LIBDIR)
SRC = $(wildcard $(SRCDIR)/*.$(SRCEXT))
OBJ = $(patsubst $(SRCDIR)/%, $(BUILDDIR)/%, $(SRC:.$(SRCEXT)=.o))
INC = -I$(INCDIR)
CDEBUG = -g -DDEBUG
CFDEBUG = -o -g -DDEBUG
STD = -std=gnu11
OPT = -O2
FLAGS = -Wall $(STD) $(CDEBUG)
CFLAGS = -c $(FLAGS) $(OPT)
LDFLAGS = $(FLAGS) $(OPT)
CFDEBUG = -pedantic -Wextra $(FLAGS)
MKFLAGS = -p
RM = rm
RMFLAGS = -rf
RMTARGETS = *~ $(BUILDDIR) $(BINDIR)/$(EXE)
all: $(BINDIR)/$(EXE)
$(BINDIR)/$(EXE): $(OBJ)
@echo "Linking objects..."
$(CC) $(LDFLAGS) $(LIB) $^ -o $@
$(OBJ): $(BUILDDIR)/%.o : $(SRCDIR)/%.c
@echo "Building objects..."
@mkdir $(MKFLAGS) $(BUILDDIR)
$(CC) $(CFLAGS) $(INC) $^ -o $@
debug:
$(CC) $(CFDEBUG) $(LIB) $(INC) $(SRC) -o $(BINDIR)/$(EXE)
clean:
@echo "Cleaning up..."
$(RM) $(RMFLAGS) $(RMTARGETS)
.PHONY: clean