-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
129 lines (109 loc) · 4.12 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
###############################################################################
# Makefile
#
# AUTHOR : Felipe Belem
# DATE : 2021-02-24
# LICENSE : MIT License
# EMAIL : [email protected]
###############################################################################
#==============================================================================
# COMPILING SETTINGS
#==============================================================================
CC = gcc #mingw-64 for Windows, or clang for MacOS
CFLAGS= -std=gnu11 -fPIC
# Directories -----------------------------------------------------------------
HOME_DIR = .
INC_DIR = $(HOME_DIR)/include
SRC_DIR = $(HOME_DIR)/src
OBJ_DIR = $(HOME_DIR)/obj
LIB_DIR = $(HOME_DIR)/lib
BIN_DIR = $(HOME_DIR)/bin
DEMO_DIR = $(HOME_DIR)/demo
INCS = -I$(INC_DIR)
LIBS_LD = -L$(LIB_DIR)
LIB_NAME = phd
LIBS_LINK = -l$(LIB_NAME)
LIB_SFIX = .a#.lib for Windows
# Compiler --------------------------------------------------------------------
# Enabling debugging GNU GCC flags
IFT_DEBUG = NO
# Enabling external libraries
# OpenMP: Requires version 4.5
# LibPNG: Requires version 1.6.29
# LibJPEG: Requires version 9.0
IFT_OMP = NO
IFT_LIBPNG = NO
IFT_LIBJPEG = NO
# It is expecting a GNU GCC compiler. For other compilers, modifications
# might be necessary
ifeq ($(IFT_DEBUG),YES)
CFLAGS += -Og -g -pedantic -ggdb -pg -Wfatal-errors -Wall -Wextra \
-Wno-unused-parameter -DIFT_DEBUG
else
CFLAGS += -O3
ifeq ($(IFT_OMP), YES)
CFLAGS += -fopenmp -DIFT_OMP
LIBS_LINK += -lgomp
endif
endif
ifeq ($(IFT_LIBJPEG),YES)
# If you desire to indicate another library version to be used (whether it
# is a shared or static one), update the following 2 variables accordingly
INCS += -I$(HOME_DIR)/externals/libjpeg/include# /path/to/libjpeg/headers
LIBS_LD += -L$(HOME_DIR)/externals/libjpeg/lib# /path/to/libjpeg/library
LIBS_LINK += -ljpeg
CFLAGS += -DIFT_LIBJPEG
endif
ifeq ($(IFT_LIBPNG),YES)
# If you desire to indicate another library version to be used (whether it
# is a shared or static one), update the following 2 variables accordingly
INCS += -I$(HOME_DIR)/externals/libpng/include# /path/to/libpng/headers
LIBS_LD += -L$(HOME_DIR)/externals/libpng/lib# /path/to/libpng/library
LIBS_LINK += -lpng
CFLAGS += -DIFT_LIBPNG
# ZLib: Requires version 1.2.11
# If you desire to indicate another library version to be used (whether it
# is a shared or static one), update the following 2 variables accordingly
INCS += -I$(HOME_DIR)/externals/libpng/zlib/include# /path/to/zlib/headers
LIBS_LD += -L$(HOME_DIR)/externals/libpng/zlib/lib# /path/to/zlib/library
LIBS_LINK += -lz
endif
LIBS_LINK += -lm
# Files -----------------------------------------------------------------------
SRC_FILES = $(wildcard $(SRC_DIR)/*.c)
DEMO_FILES = $(wildcard $(DEMO_DIR)/*.c)
OBJ_FILES = $(patsubst $(SRC_DIR)/%.c, $(OBJ_DIR)/%.o, $(SRC_FILES))
#==============================================================================
# RULES
#==============================================================================
.PHONY: all clean demo lib obj refresh tidy
all: lib demo
# Compiling -------------------------------------------------------------------
status:
@echo "\nCompilation Flags ------------------------------------------"
@echo "- IFT_DEBUG: $(IFT_DEBUG)"
@echo "- IFT_OMP: $(IFT_OMP)"
@echo "- IFT_LIBPNG: $(IFT_LIBPNG)"
@echo "- IFT_LIBJPEG: $(IFT_LIBJPEG)"
@echo "------------------------------------------------------------\n"
lib: status obj
@mkdir -p $(LIB_DIR)
ar csr $(LIB_DIR)/lib$(LIB_NAME)$(LIB_SFIX) $(OBJ_FILES)
@echo "\n----- Library was successfully built\n"
obj:
@make -j $(OBJ_FILES)
@echo "\n----- All sources were compiled\n"
demo:
@make -j $(patsubst %.c, %, $(DEMO_FILES))
@echo "\n----- All demos were compiled\n"
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
@mkdir -p $(OBJ_DIR)
$(CC) $(CFLAGS) $(INCS) -c $< -o $@ $(LIBS_LD) $(LIBS_LINK)
$(DEMO_DIR)/%:
@mkdir -p $(BIN_DIR)
$(CC) $(CFLAGS) $(INCS) [email protected] -o $(BIN_DIR)/$(@F) $(LIBS_LD) $(LIBS_LINK)
# Cleaning --------------------------------------------------------------------
clean: tidy
$(RM) -r $(BIN_DIR)
$(RM) -r $(OBJ_DIR)
$(RM) -r $(LIB_DIR)