-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
49 lines (38 loc) · 1.03 KB
/
makefile
File metadata and controls
49 lines (38 loc) · 1.03 KB
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
main:
# Comprehensive Makefile
# This will automatically compile any .c files in the current directory.
# Some of the syntax was adapted from:
# https://gist.github.com/Wenchy/64db1636845a3da0c4c7
# http://nuclear.mutantstargoat.com/articles/make/
CC = gcc
CFLAGS = --std=gnu99
SRCEXT = c
LDFLAGS += -pthread
BINDIR = .
# exe_file = $(BINDIR)/$(shell basename "${PWD}")
exe_file = line_processor
# Handle debug case
DEBUG ?= 1
ifeq ($(DEBUG), 1)
CFLAGS += -g -Wall
else
CFLAGS += -DNDEBUG -O3
endif
SRCDIR = .
BUILDDIR = build
SOURCES = $(shell find $(SRCDIR) -type f -name "*.$(SRCEXT)")
OBJECTS = $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.o))
DEP = $(OBJECTS:.o=.d)
all: $(exe_file)
$(exe_file): $(OBJECTS)
@mkdir -p $(BINDIR)
$(CC) -o $(exe_file) $^ $(LIB) $(LDFLAGS)
$(BUILDDIR)/%.d: $(SRCDIR)/%.$(SRCEXT)
@mkdir -p $(BUILDDIR)
@$(CC) $(INC) $< -MM -MT $(@:.d=.o) >$@
$(BUILDDIR)/%.o: $(SRCDIR)/%.$(SRCEXT)
$(CC) $(CFLAGS) $(INC) -c -o $@ $<
.PHONY: clean
clean:
rm -rf $(BUILDDIR) $(exe_file)
-include $(DEP)