-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathMakefile
79 lines (60 loc) · 1.59 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
#-------------------------------------------
DEBUG_EN=1
APP=test_app
TOP_DIR=$(shell pwd)
ARCH=
CC=gcc
CFLAGS= -Wall -Wfatal-errors -std=c99
LDFLAGS=
SRC_TOP=./src
OBJ_DIR=./obj/
INC_DIRS=./inc
LIB_DIRS=
ifeq ($(DEBUG_EN), 1)
CFLAGS+=-O0 -g -DDEBUG_EN
endif
# Dependencies if any
LIBS= m openblas
DEPS=$(wildcard ./inc/*.h)
CFLAGS+= $(foreach D,$(INC_DIRS),-I$D)
LDFLAGS+= $(foreach D,$(LIB_DIRS),-L$D) $(foreach L,$(LIBS), -l$(L))
#-------------------------------------------
# Source files for compilation
#-------------------------------------------
SRCS=$(wildcard $(SRC_TOP)/*.c)
# List of all objects that are to be built
OBJS= $(addprefix $(OBJ_DIR), $(patsubst %.c, %.o, $(notdir $(SRCS))))
vpath %.c $(dir $(SRCS))
#-------------------------------------------
# Build targets
all : obj $(APP) $(DEPS)
$(APP): Makefile $(OBJ_DIR) $(OBJS)
@echo "Linking..."
$(CC) -o $@ $(OBJS) $(LDFLAGS)
$(OBJ_DIR):
mkdir -p $(OBJ_DIR)
$(OBJS):$(OBJ_DIR)%.o:%.c
@echo "Building $@ from $<..."
$(CC) -c $(CFLAGS) $< -o $@
#-------------------------------------------
#-------------------------------------------
# Phony targets
#-------------------------------------------
.phony: clean clean_all
obj :
mkdir -p obj
# Clean the common object files
clean:
@echo "Removing all objects..."
rm -rf $(OBJS)
rm -f $(APP)
# Clean all libraries if at all
clean_all:
@echo "Cleaning everything..."
# Print important variables and values
print:
@echo "Compiler flags = $(CFLAGS)"
@echo "Linker flags = $(LDFLAGS)"
@echo "Source files = $(SRCS)"
@echo "Object files = $(OBJS)"
@echo "Dependencies = $(DEPS)"