pud: statically link nmealib if PUD_NMEALIB_STATICALLY_LINKED is defined
[olsrd.git] / lib / pud / Makefile
1 NMEALIB_PATH = nmealib
2 LIBRARY_PATH = wireformat
3 JAVA_PATH = wireformat-java
4 include $(LIBRARY_PATH)/Makefile.inc
5 NMEALIB_NAME := nmea
6 LIBRARY_NAME := $(PROJECT)
7
8
9 include Makefile.inc
10
11 TOPDIR = ../..
12 include $(TOPDIR)/Makefile.inc
13
14
15 PUD_NMEALIB_STATICALLY_LINKED ?=
16 CFLAGS += -D_GNU_SOURCE
17
18
19 RESOURCESDIR = ./resources
20 NMEALIB_INC = $(NMEALIB_PATH)/include
21 NMEALIB_LIB = $(NMEALIB_PATH)/lib
22 LIBRARY_INC = $(LIBRARY_PATH)/include
23 LIBRARY_LIB = $(LIBRARY_PATH)/lib
24 NMEALIB_LIB_STATIC = $(NMEALIB_LIB)/lib$(NMEALIB_NAME).a
25
26 CFLAGS += -I $(NMEALIB_INC) -I $(LIBRARY_INC)
27 ifeq ($(PUD_NMEALIB_STATICALLY_LINKED),)
28 LIBS += -L $(NMEALIB_LIB) -L $(LIBRARY_LIB) -l$(NMEALIB_NAME) -lm -l$(LIBRARY_NAME)
29 else
30 # libnmea is statically linked
31 LIBS += -L $(LIBRARY_LIB) -lm -l$(LIBRARY_NAME)
32 endif
33
34
35 SUPPORTED = 0
36 ifeq ($(OS),linux)
37 SUPPORTED = 1
38 endif
39 ifeq ($(OS),android)
40 SUPPORTED = 1
41 endif
42
43
44 ifeq ($(SUPPORTED),0)
45
46 .PHONY: all default_target install clean
47
48 all: default_target
49
50 default_target install clean:
51         @echo "*** $(PLUGIN_NAME) plugin not supported on $(OS), sorry!"
52
53 else
54
55 GIT_SHA = $(shell git describe 2> /dev/null || echo "Unknown")
56 CFLAGS += -DGIT_SHA=\"$(GIT_SHA)\" -DPLUGIN_VER=\"$(PLUGIN_VER)\"
57
58 .PHONY: all default_target install uninstall clean doc doc-clean nmealib library java java-instal java-uninstall
59
60 all: default_target
61
62 default_target: nmealib library $(PLUGIN_FULLNAME)
63
64 # repeat from toplevel Makefile.inc, and adjust: we need the library includes
65 %.d: %.c
66         @$(filter-out $(CCACHE),$(CC)) -M $(strip $(CPPFLAGS)) -I $(NMEALIB_INC) -I $(LIBRARY_INC) "$<" | sed -e '1s/\($(call quote,$(*F))\.o\)[ :]*/$(call quote,$(*D)/\1 $@: Makefile $(TOPDIR)$(if $(TOPDIR),/)Makefile.inc) /g' >"$@"
67
68 $(PLUGIN_FULLNAME): $(OBJS) version-script.txt
69 ifeq ($(PUD_NMEALIB_STATICALLY_LINKED),)
70         @echo "[LD] $@ (nmealib dynamically linked)"
71         @$(CC) $(LDFLAGS) -o $(PLUGIN_FULLNAME) $(OBJS) $(LIBS)
72 else
73         @echo "[LD] $@ (nmealib statically linked)"
74         @$(CC) $(LDFLAGS) -o $(PLUGIN_FULLNAME) $(OBJS) $(NMEALIB_LIB_STATIC) $(LIBS)
75 endif
76
77 install: all
78         @$(MAKE) -C "$(NMEALIB_PATH)" DESTDIR="$(DESTDIR)" install
79         @$(MAKE) -C "$(LIBRARY_PATH)" DESTDIR="$(DESTDIR)" install
80         $(INSTALL_LIB)
81         mkdir -p "$(DOCDIR_OLSRD)"
82         cp "$(RESOURCESDIR)/olsrd.pud.position.conf" "$(DOCDIR_OLSRD)"
83         $(STRIP) "$(LIBDIR)/$(PLUGIN_FULLNAME)"
84
85 uninstall:
86         @$(MAKE) -C "$(NMEALIB_PATH)" DESTDIR="$(DESTDIR)" uninstall
87         @$(MAKE) -C "$(LIBRARY_PATH)" DESTDIR="$(DESTDIR)" uninstall
88         rm -f "$(LIBDIR)/lib$(PLUGIN_NAME).so" "$(LIBDIR)/$(PLUGIN_NAME)" "$(DOCDIR_OLSRD)/olsrd.pud.position.conf"
89         $(UNINSTALL_LIB)
90         rmdir -v -p --ignore-fail-on-non-empty "$(LIBDIR)" "$(DOCDIR_OLSRD)"
91
92 clean:
93         @echo "[$@]"
94         @rm -f $(OBJS) $(SRCS:%.c=%.d) "$(PLUGIN_FULLNAME)"
95         @$(MAKE) -C doc clean
96         @$(MAKE) -C "$(NMEALIB_PATH)" clean
97         @$(MAKE) -C "$(LIBRARY_PATH)" clean
98         @$(MAKE) -C "$(JAVA_PATH)" clean
99
100 doc:
101         @$(MAKE) -C doc all
102         @$(MAKE) -C "$(NMEALIB_PATH)" doc
103         @$(MAKE) -C "$(LIBRARY_PATH)" doc
104         @$(MAKE) -C "$(JAVA_PATH)" doc
105
106 doc-clean:
107         @$(MAKE) -C doc clean
108         @$(MAKE) -C "$(NMEALIB_PATH)" doc clean
109         @$(MAKE) -C "$(LIBRARY_PATH)" doc clean
110         @$(MAKE) -C "$(JAVA_PATH)" doc clean
111
112 nmealib:
113         @$(MAKE) -C "$(NMEALIB_PATH)" all
114
115 library:
116         @$(MAKE) -C "$(LIBRARY_PATH)" all
117
118 java:
119         @$(MAKE) -C "$(JAVA_PATH)" all
120
121 java-install: java
122         @$(MAKE) -C "$(JAVA_PATH)" DESTDIR="$(DESTDIR)" install
123
124 java-uninstall:
125         @$(MAKE) -C "$(JAVA_PATH)" DESTDIR="$(DESTDIR)" uninstall
126
127 endif