forked from Industrial-Shields/librpiplc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
54 lines (40 loc) · 1.2 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
LIBNAME:=rpiplc
override CXXFLAGS+=-Wall -Werror -std=c++14
override LDFLAGS+=-shared
CC=g++
CXX=g++
PREFIX=/usr/local
LIBRARY:=lib$(LIBNAME).so
HEADERS:=$(wildcard src/*.h)
SRCS:=$(wildcard src/*.cpp)
OBJS:=$(patsubst %.cpp,%.o,$(SRCS))
TEST_SRCS=$(wildcard test/*.cpp)
TEST_BINS=$(patsubst %.cpp,%,$(TEST_SRCS))
define test-targets
.PHONY: $(1)
$(1): $(1).cpp $(LIBRARY)
$(CXX) $(CXXFLAGS) -Isrc -L. -o $(1) $(1).cpp -l$(LIBNAME)
endef
.PHONY: first all world clean tests install pack pre-pack
first all world: $(LIBRARY)
$(LIBRARY): $(OBJS)
$(CC) $(LDFLAGS) $^ -o $@
$(OBJS): CXXFLAGS+=-fpic
$(OBJS): $(SRCS) $(HEADERS)
$(foreach TEST_BIN,$(TEST_BINS),$(eval $(call test-targets,$(TEST_BIN))))
tests: $(TEST_BINS)
install:
if [ -n "$(DESTDIR)" ]; then mkdir -p $(DESTDIR); fi
mkdir -p $(DESTDIR)$(PREFIX)/lib/
cp $(LIBRARY) $(DESTDIR)$(PREFIX)/lib/
if [ -z "$(DESTDIR)" ]; then ldconfig; fi
mkdir -p $(DESTDIR)$(PREFIX)/include/$(LIBNAME)
cp $(HEADERS) $(DESTDIR)$(PREFIX)/include/$(LIBNAME)/
pack: DESTDIR=/tmp/$(LIBNAME)
pack: PREFIX=
pack: pre-pack $(LIBRARY) install
tar -C $(DESTDIR) -cjvf lib$(LIBNAME).tar.bz2 .
pre-pack:
rm -rf $(DESTDIR)
clean:
rm -f $(OBJS) $(LIBRARY) $(TEST_BINS) src/*.o