-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
85 lines (60 loc) · 2.4 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#------------------------------------------------------------------------------
# Target
#------------------------------------------------------------------------------
EXEC = test
CFLAGS = -g -O0 -Wall -Werror -Iinc
LDFLAGS = -Wl,-rpath,$(shell pwd)/lib -Llib -lhs
CC = gcc
#------------------------------------------------------------------------------
# Directories
#------------------------------------------------------------------------------
DIR_SRC = ./src/
DIR_BUILD = ./build/
DIR_BUILD_OBJ = $(DIR_BUILD)/
DIR_BUILD_BIN = $(DIR_BUILD)/
#------------------------------------------------------------------------------
# File suffixes
#------------------------------------------------------------------------------
EXT_CODE = .c
EXT_HEADERS = .h
EXT_OBJECT = .o
.SUFFIXES:
.SUFFIXES: $(EXT_CODE) $(EXT_HEADERS) $(EXT_OBJECT)
#------------------------------------------------------------------------------
# Search Paths
#------------------------------------------------------------------------------
VPATH =
vpath
vpath %$(EXT_CODE) $(DIR_SRC)
vpath %$(EXT_HEADERS) $(DIR_SRC)
vpath %$(EXT_OBJECT) $(DIR_BUILD_OBJ)
#------------------------------------------------------------------------------
# Macros
#------------------------------------------------------------------------------
# Get every code file in the source directory
FILES_SRC = $(foreach dir,$(DIR_SRC),$(wildcard $(DIR_SRC)*$(EXT_CODE)))
# Get only the file name of the source files
FILES_SRC_REL = $(notdir $(FILES_SRC))
# Replaces the code extension by the object extension
FILES_SRC_O = $(subst $(EXT_CODE),$(EXT_OBJECT),$(FILES_SRC_REL))
# Prefix all code files with the object directory
FILES_SRC_BUILD = $(addprefix $(DIR_BUILD_OBJ),$(FILES_SRC_O))
# Prefix all executables with the build directory
FILES_EXEC_BUILD = $(addprefix $(DIR_BUILD_BIN),$(EXEC))
#------------------------------------------------------------------------------
# Other targets
#------------------------------------------------------------------------------
default: $(FILES_EXEC_BUILD)
cp $(FILES_EXEC_BUILD) .
-include .depend
$(DIR_BUILD_OBJ)%$(EXT_OBJECT): %$(EXT_CODE)
$(CC) -c -o $@ $< $(CFLAGS)
$(FILES_EXEC_BUILD): $(FILES_SRC_BUILD)
$(CC) -o $@ $^ $(LDFLAGS)
dep depend:
@$(CC) $(CFLAGS) -M -MM $(FILES_SRC) > .depend
@sed -i "s@\(^\w\)@$(DIR_BUILD_OBJ)\1@" .depend
clean:
rm -fr $(FILES_EXEC_BUILD) $(FILES_SRC_BUILD) $(EXEC)
distclean: clean
rm -fr .depend