sercmd: fix LIBS when installing from a module
[sip-router] / utils / sercmd / Makefile
1 # $Id$
2 COREPATH=../..
3 include $(COREPATH)/Makefile.defs
4 include $(COREPATH)/Makefile.targets
5
6 auto_gen=
7 NAME=sercmd
8 RELEASE=0.2
9
10 readline_locations= /usr/include/readline/readline.h \
11                                         $(LOCALBASE)/include/readline/readline.h
12
13 use_readline ?=
14 ifneq (,$(MAKECMDGOALS))
15 ifeq (,$(filter-out $(nodep_targets),$(MAKECMDGOALS)))
16 #set it to empty, we don't need to detect/use it for clean, doc a.s.o
17 override use_readline:=
18 quiet=1
19 endif
20 endif #ifneq (,$(MAKECMDGOALS))
21
22
23 # erase common DEFS (not needed)
24 C_DEFS:=
25 DEFS:= -DNAME='"$(NAME)"' -DVERSION='"$(RELEASE)"' \
26                 $(filter -D%HAVE -DARCH% -DOS% -D__CPU% -D__OS%, $(DEFS))
27
28 # use proper libs (we can't rely on LIBS value since we might be called
29 # from a module Makefile)
30 #LIBS:=$(filter-out -lfl  -ldl -lpthread -lssl -lcrypto, $(LIBS))
31
32 LIBS:= -lresolv
33 ifeq  ($(OS), solaris)
34         LIBS+= -L$(LOCALBASE)/lib -lxnet -lnsl
35 endif
36
37 ifeq ($(use_readline),)
38 readline_path := $(shell  \
39                                                 for r in $(readline_locations) ""; do \
40                                                         if [ -r "$$r" ] ; then echo $$r; exit; fi;  \
41                                                 done;\
42                                         )
43 ifneq ($(readline_path),)
44 use_readline := 1
45 endif
46 endif
47
48 ifeq ($(use_readline),1)
49         DEFS+=-DUSE_READLINE
50         LIBS+=-lreadline -lncurses
51 endif
52
53
54 include $(COREPATH)/Makefile.utils
55
56 ifeq (,$(quiet))
57 ifeq ($(use_readline),1)
58 $(info readline detected ($(readline_path)) )
59 $(info command completion enabled)
60 else
61 $(info "no readline include files detected, disabling readline support")
62 $(info "command completion disabled" )
63 $(info "to force readline support try 'make use_readline=1'")
64 endif
65 endif # ifeq (,$(quiet))
66
67 $(NAME).o: 
68
69 .PHONY: msg
70 msg:
71         @if [ "$(use_readline)" = "1" ]; then \
72                 echo; echo "readline detected ($(readline_path)):"; \
73                 echo "command completion enabled"; echo ; \
74         else \
75                 echo ; \
76                 echo "no readline include files detected, disabling readline support";\
77                 echo "command completion disabled"; \
78                 echo "(to force readline support try 'make use_readline=1')";\
79                 echo ; \
80         fi
81
82 modules: