-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
63 lines (47 loc) · 2.15 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
55
56
57
58
59
60
61
62
CFLAGS=-Wall -O2 -Wno-unused
INCLUDES=-I include
LIB=libDivaS.a
# -----------------------------------------------
# Detect available system libraries
# -----------------------------------------------
LIBGPP := $(shell echo "int main(int argc,char** argv) {return 0;}" > tmp.c 2>/dev/null && gcc tmp.c -o tmp -lg++ > /dev/null 2>&1 && echo -lg++)
LIBSTDCPP:= $(shell echo "int main(int argc, char** argv) {return 0;}" > tmp.c 2>/dev/null && gcc tmp.c -o tmp -lstdc++ > /dev/null 2>&1 && echo -lstdc++)
$(shell rm tmp.c tmp)
# -----------------------------------------------
# Detect location of DivaS library
# -----------------------------------------------
LIBDIVA=$(shell test -f ../$(LIB) && echo ../$(LIB))
ifeq (,${LIBDIVA})
LIBDIVA=$(shell test -f ../../lib/$(LIB) && echo ../../lib/$(LIB))
endif
ifeq (,${LIBDIVA})
LIBDIVA=-lDivaS
endif
# -----------------------------------------------
# Libraries to be used
# -----------------------------------------------
LIBS=$(LIBDIVA) -lpthread $(LIBGPP) $(LIBSTDCPP)
# -----------------------------------------------
# Extra includes to be used
# -----------------------------------------------
EXTRA_INCLUDES=$(shell test -f /usr/include/string.h && echo -include /usr/include/string.h)
EXTRA_INCLUDES+=$(shell test -f /usr/include/strings.h && echo -include /usr/include/strings.h)
EXTRA_INCLUDES+=$(shell test -f /usr/include/memory.h && echo -include /usr/include/memory.h)
# -------------------------------------------------------------------------
TARGET=divaconf
SRC=divaconf.c
# -------------------------------------------------------------------------
$(TARGET): $(patsubst ./%.c,./%.o,$(SRC))
$(CC) $(CFLAGS) $(INCLUDES) $^ $(LIBS) -o $(TARGET)
./%.o:./%.c
$(CC) $(EXTRA_INCLUDES) -c $(CFLAGS) $(INCLUDES) $< -o $@
./%.o:./%.cpp
$(CC) $(EXTRA_INCLUDES) -c $(CFLAGS) $(INCLUDES) $< -o $@
# -------------------------------------------------------------------------
clean:
@rm -f ./*.o $(TARGET) ./.depend ./tmp.o ./tmp
# -------------------------------------------------------------------------
depend:
@$(CC) $(INCLUDES) $(CFLAGS) -M $(SRC) | \
sed -e "s/^.*:/.\/&/" - > ./.depend
-include ./.depend