-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
46 lines (34 loc) · 943 Bytes
/
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
CC = gcc
CXX = g++
SHELL := /bin/bash
# performance evaluation
PERF_ITER ?= 10
PERF = perf stat -r $(PERF_ITER)
# Common flags, with user-selected debugging
OPTLVL ?= 2
COMMON_FLAGS = -O$(OPTLVL) -march=native -Wall -Wextra -Wpedantic
ifdef DEBUG
COMMON_FLAGS += -g
endif
# Special flags for either C or C++
CFLAGS ?= $(COMMON_FLAGS) -std=c99
CXXFLAGS ?= $(COMMON_FLAGS) -std=c++11
LDFLAGS := -lm
INCLUDES := -I.
DEFINES += -DDEBUG
# Source and binaries
CFILES := $(wildcard *.c)
CXXFILES := $(wildcard *.cpp)
BINS = $(CFILES:.c=.cbin) $(CXXFILES:.cpp=.cxxbin)
PERFDAT = $(CFILES:.c=.perfdat)
.PHONY: all clean
all: $(BINS)
perfdiff: all $(PERFDAT)
%.cbin: %.c
$(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) $^ -o $@ $(LDFLAGS)
%.cxxbin: %.cpp
$(CXX) $(CXXFLAGS) $(DEFINES) $(INCLUDES) $^ -o $@ $(LDFLAGS)
%.perfdat: %.cbin %.cxxbin
@diff <($(PERF) ./$*.cbin 2>&1) <($(PERF) ./$*.cxxbin 2>&1) > $@ ||:
clean:
@rm -f $(BINS) $(PERFDAT)