aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: 30c0c8f930f35d443508d084f632c2379581b78c (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
CC  = $(PREFIX)-gcc
CXX = $(PREFIX)-g++
LD = $(CXX)

INCLUDE = -Iinclude/
LIB = -lusb-1.0 -lpthread
#LIB = -lhidapi-libusb
BUILD = build

CXXFLAGS = -std=c++14 -fPIC -fpermissive
SOFLAGS = -shared

CXXSOURCES = $(wildcard *.cc)
OBJ = $(CXXSOURCES:%.cc=$(BUILD)/%.o)
DEPENDS = $(CXXSOURCES:%.cc=$(BUILD)/%.d)

all: $(OBJ) $(BUILD)/libnitrokey.so unittest

$(BUILD)/libnitrokey.so: $(OBJ) $(DEPENDS)
	$(CXX) $(SOFLAGS) $(OBJ) $(LIB) -o $@

$(BUILD)/%.d: %.cc
	$(CXX) -M $< -o $@ $(INCLUDE) $(CXXFLAGS)

$(BUILD)/%.o: %.cc $(DEPENDS)
	$(CXX) -c $< -o $@ $(INCLUDE) $(CXXFLAGS)

clean:
	rm -f $(OBJ)
	rm -f $(BUILD)/libnitrokey.so
	make -C unittest clean

mrproper: clean
	rm -f $(BUILD)/*.d
	make -C unittest mrproper

unittest: $(BUILD)/libnitrokey.so
	make -C unittest
	cd unittest/build && ln -fs ../../build/libnitrokey.so .

.PHONY: all clean mrproper unittest

include $(wildcard build/*.d)