-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
65 lines (50 loc) · 2.34 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
63
64
65
CFLAGS=-Wall -O2 -Wno-unused
INCLUDES=-I include
OBJ_DIR=obj
BIN_DIR=bin
SRC_DIR=src
LIB=libDivaS.a
# -----------------------------------------------
# Detect available system libraries
# -----------------------------------------------
LIBGPP := $(shell echo "int main(int argc,char** argv) {return 0;}" > obj/tmp.c 2>/dev/null && gcc obj/tmp.c -o obj/tmp -lg++ > /dev/null 2>&1 && echo -lg++)
LIBSTDCPP:= $(shell echo "int main(int argc, char** argv) {return 0;}" > obj/tmp.c 2>/dev/null && gcc obj/tmp.c -o obj/tmp -lstdc++ > /dev/null 2>&1 && echo -lstdc++)
$(shell rm obj/tmp.c obj/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=$(BIN_DIR)/bluebox
SRC=$(SRC_DIR)/main.c
# -------------------------------------------------------------------------
$(TARGET): $(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/%.o,$(SRC))
$(CC) $(CFLAGS) $(INCLUDES) $^ $(LIBS) -o $(TARGET)
$(OBJ_DIR)/%.o:$(SRC_DIR)/%.c
$(CC) $(EXTRA_INCLUDES) -c $(CFLAGS) $(INCLUDES) $< -o $@
$(OBJ_DIR)/%.o:$(SRC_DIR)/%.cpp
$(CC) $(EXTRA_INCLUDES) -c $(CFLAGS) $(INCLUDES) $< -o $@
# -------------------------------------------------------------------------
clean:
@rm -f $(OBJ_DIR)/*.o $(TARGET) $(OBJ_DIR)/.depend $(OBJ_DIR)/tmp.o $(OBJ_DIR)/tmp
# -------------------------------------------------------------------------
depend:
@$(CC) $(INCLUDES) $(CFLAGS) -M $(SRC) | \
sed -e "s/^.*:/$(OBJ_DIR)\/&/" - > $(OBJ_DIR)/.depend
-include $(OBJ_DIR)/.depend