-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
47 lines (33 loc) · 974 Bytes
/
Makefile
File metadata and controls
47 lines (33 loc) · 974 Bytes
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
# General purpose C/C++ Makefile
# Created by Pooya Merat on 2018-04-10.
CXX = g++
CC = gcc
# Set the executable name
PROG_NAME := exec_name # name of the executable
SRC_DIRS = .
OBJDIR = obj
SRCS := $(shell find $(SRC_DIRS) -maxdepth 1 -type f -regex ".*\.cpp" -o -regex ".*\.c")
_OBJS := $(addsuffix .o,$(basename $(SRCS)))
OBJS := $(patsubst ./%,$(OBJDIR)/%,$(_OBJS))
# Add Libraries (-L and -l have to be in order for ubuntu)
# Example: LDFLAGS += -L/usr/local/lib -lpthread
# Compiler flags
CXXFLAGS += -Wall -std=c++11
CCFLAGS += -Wall -Wextra
CCFLAGS += -std=gnu99 # Disable if not needed
CCFLAGS += -O3
# Commands
.PHONY: clean
$(PROG_NAME): directories $(OBJS)
$(CXX) $(OBJS) -o $@ $(LDFLAGS)
directories:
@mkdir -p $(OBJDIR)
$(OBJDIR)/%.o: %.cpp
$(CXX) $(CXXFLAGS) -c -o $@ $<
$(OBJDIR)/%.o: %.c
$(CC) $(CCFLAGS) -c -o $@ $<
clean:
@- $(RM) $(PROG_NAME)
@- $(RM) -rf $(OBJDIR)
# Print for debugging
print-% : ; @echo $* = $($*)