summaryrefslogtreecommitdiff
path: root/Makefile
blob: 8a2f6668173ea63a977fa37bf76260d6e6bb6d2f (plain)
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
awkbin     :=$(shell which awk)
cpbin      :=$(shell which cp)
echobin    :=$(shell which echo)
findbin    :=$(shell which find)
grepbin    :=$(shell which grep)
installbin :=$(shell which install)
rmbin      :=$(shell which rm)
sedbin     :=$(shell which sed)
sortbin    :=$(shell which sort)
truebin    :=$(shell which true)

CXX = g++

# to get full debug symbols, add -g to both FLAGS
CXXFLAGS = -g -std=c++11 -Wall -Weffc++ -Wextra -Wsign-conversion -Werror

# adding -s will make the linker strip the file
LDFLAGS = -g

src = $(wildcard *.cpp)
obj = $(src:.cpp=.o)

OUTEXE = helloworld

all: $(OUTEXE)

# compile
$(obj): $(src)
	$(CXX) -c $(CXXFLAGS) $<

# link
$(OUTEXE): $(obj)
	$(CXX) -o $@ $^ $(LDFLAGS)

.PHONY: clean cleanall list

list:
	@$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | ${awkbin} -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | ${sortbin} | ${grepbin} -E -v -e '^[^[:alnum:]]' -e '^$@$$' -e '\.(cp*|o)'

clean:
	rm -f $(obj)

cleanall:
	rm -f $(obj) $(OUTEXE)
bgstack15