kamcmd: use pkg-config to get compile flags for lib readline
[sip-router] / utils / kamcmd / Makefile
1 #
2 #
3
4 COREPATH=../../src/
5 include $(COREPATH)/Makefile.defs
6 include $(COREPATH)/Makefile.targets
7
8 auto_gen=
9 RELEASE=1.5
10 UTIL_SRC_NAME=kamcmd
11 ifeq ($(FLAVOUR),ser)
12         NAME?=sercmd
13 else
14         NAME?=kamcmd
15 endif
16
17 readline_localpath=$(LOCALBASE)/include/readline/readline.h
18 readline_locations= /usr/include/readline/readline.h \
19                                         $(readline_localpath)
20
21 ifeq ($(CROSS_COMPILE),)
22         BUILDER = $(shell which pkg-config)
23 ifneq ($(BUILDER),)
24         PKGREADLINE = $(shell $(BUILDER) --exists readline > /dev/null 2>&1 ; echo $$? )
25 ifneq ($(PKGREADLINE),0)
26         BUILDER =
27 endif
28 endif
29 endif
30
31
32 use_readline ?=
33 ifneq (,$(MAKECMDGOALS))
34 ifeq (,$(filter-out $(nodep_targets),$(MAKECMDGOALS)))
35 #set it to empty, we don't need to detect/use it for clean, doc a.s.o
36 override use_readline:=
37 quiet=1
38 endif
39 endif #ifneq (,$(MAKECMDGOALS))
40
41
42 # erase common DEFS (not needed)
43 C_DEFS:=
44 DEFS:= -DNAME='"$(NAME)"' -DSRNAME='"$(MAIN_NAME)"' -DVERSION='"$(RELEASE)"' -D__OS_$(OS) \
45                 -DRUN_DIR='"$(run_target)"' \
46                 $(filter -D%HAVE -DARCH% -DOS% -D__CPU% -D__OS%, $(DEFS))
47
48 # use proper libs (we can't rely on LIBS value since we might be called
49 # from a module Makefile)
50 #LIBS:=$(filter-out -lfl  -ldl -lpthread -lssl -lcrypto, $(LIBS))
51
52 ifeq ($(OS), linux)
53         LIBS:= -lresolv
54 endif
55 ifeq ($(OS), solaris)
56         LIBS:= -lresolv -L$(LOCALBASE)/lib -lxnet -lnsl
57 endif
58 ifeq ($(OS), freebsd)
59         LIBS:=
60 endif
61 ifeq  ($(OS), dragonfly)
62         LIBS:= -L$(LOCALBASE)/lib
63 endif
64 ifeq ($(OS), openbsd)
65         LIBS:=
66 endif
67 ifeq ($(OS), netbsd)
68         LIBS:=
69 endif
70 ifeq ($(OS), darwin)
71 readline_locations= /opt/local/include/readline/readline.h \
72                                         /usr/include/readline/readline.h \
73                                         $(readline_localpath)
74         LIBS:= -lresolv
75 endif
76 ifneq (,$(findstring cygwin, $(OS)))
77         LIBS:= -lresolv
78 endif
79
80 # detect libreadline
81 ifneq ($(BUILDER),)
82         DEFS += $(shell $(BUILDER) --cflags readline)
83         LIBS += $(shell $(BUILDER) --libs readline)
84         use_readline := 1
85 else
86 ifeq ($(use_readline),)
87 readline_path := $(shell  \
88                                                 for r in $(readline_locations) ""; do \
89                                                         if [ -r "$$r" ] ; then echo $$r; exit; fi;  \
90                                                 done;\
91                                         )
92 ifneq ($(readline_path),)
93 use_readline := 1
94 endif
95 endif
96
97 ifeq ($(use_readline),1)
98
99 ifneq (,$(findstring opt, $(readline_path)))
100         DEFS+=-DUSE_READLINE -I /opt/local/include
101         LIBS+=-L/opt/local/lib -lreadline -lncurses
102 else
103
104 ifeq ($(readline_path),$(readline_localpath))
105         DEFS+=-I$(LOCALBASE)/include
106         LIBS+=-L$(LOCALBASE)/lib
107 endif
108
109         DEFS+=-DUSE_READLINE
110         LIBS+=-lreadline -lncurses
111 endif
112
113 endif  # ifeq ($(use_readline),1)
114
115 endif  # ifneq ($(BUILDER),)
116
117
118 include $(COREPATH)/Makefile.utils
119
120 ifeq (,$(quiet))
121 ifeq ($(use_readline),1)
122 ifneq ($(BUILDER),)
123 $(info readline detected via pkg-config)
124 else
125 $(info readline detected ($(readline_path)) )
126 endif
127 $(info command completion enabled)
128 else
129 $(info "no readline include files detected, disabling readline support")
130 $(info "command completion disabled" )
131 $(info "to force readline support try 'make use_readline=1'")
132 endif
133 endif # ifeq (,$(quiet))
134
135 $(NAME).o:
136
137 .PHONY: msg
138 msg:
139         @if [ "$(use_readline)" = "1" ]; then \
140                 echo; echo "readline detected ($(readline_path)):"; \
141                 echo "command completion enabled"; echo ; \
142         else \
143                 echo ; \
144                 echo "no readline include files detected, disabling readline support";\
145                 echo "command completion disabled"; \
146                 echo "(to force readline support try 'make use_readline=1')";\
147                 echo ; \
148         fi
149
150 modules: