-BUILDDIR = $(PWD)/build
-SRCDIR = $(PWD)/src
+MAKEFLAGS += --no-print-directory
+
+TOPDIR = $(shell pwd)
+BUILDDIR = $(TOPDIR)/build
+SRCDIR = $(TOPDIR)/src
+PREFIX = /usr/local
+
+include $(TOPDIR)/libcmdline.vars.mk
+
+export TOPDIR
+export BUILDDIR
+export SRCDIR
+export PREFIX
SUBDIRS = lib
+SUBDIRS += calculator_server
SUBDIRS += trivial_rdline
SUBDIRS += extension_example
SUBDIRS += calculator_standalone
-SUBDIRS += calculator_server
SUBDIRS += client
-SUBDIRS += event_server
SUBDIRS += genconf
+ifeq ($(HAVE_EVENT_LIB),y)
+SUBDIRS += event_server
+endif
-# configuration for lib, not adviced to modify it except for
-# really small devices, because it changes the API.
-# CFLAGS += -DNO_RDLINE_HISTORY
-# CFLAGS += -DNO_RDLINE_KILL_BUF
-CFLAGS += -DCMDLINE_HAVE_FLOAT
-CFLAGS += -DCMDLINE_HAVE_SOCKET
-
-CFLAGS += -Wall -Werror
-CFLAGS += -O0 -g
-
-CFLAGS += -I$(SRCDIR)/lib
-
-# needed if you want to parse float
-LDFLAGS += -lm
-
-
-export CFLAGS LDFLAGS
-
-_all: all
-
-all clean:
- for i in $(SUBDIRS) ; do \
- make -C ${BUILDDIR}/$$i \
- VPATH=${SRCDIR}/$$i $@ || exit $$? ; \
- done
+include $(TOPDIR)/libcmdline.subdir.mk
--- /dev/null
+This library provides an interface to implement command line
+interfaces. It has no dependency except libc, and it contains its own
+(lightweight) alternative to readline. The libcmdline library was
+initially designed for very small devices like microcontrollers or
+embedded devices running outside an OS, but it also fully works under
+linux.
+
+To compile:
+ make
+
+Then install it:
+ make install PREFIX=/usr/local
+
+If you don't have libevent on your system, edit the libcmdline.vars.mk
+file and comment the related line.
+
+To cross-compile the library (example for powerpc):
+ make CROSS=powerpc-linux-gnu-
+++ /dev/null
-SRC = main.c commands.c
-
-OBJS = $(SRC:%.c=%.o)
-
-PROG = server
-LDLIB = ../lib/libcmdline.a
-
-all: $(PROG)
-
-clean:
- rm -f $(PROG) $(OBJS)
-
-$(PROG): $(OBJS) $(LDLIB)
- $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LDLIB)
-
-%.o: %.c
- $(CC) $(CFLAGS) -c $< -o $@
+++ /dev/null
-SRC = main.c commands.c
-
-OBJS = $(SRC:%.c=%.o)
-
-PROG = standalone
-LDLIB = ../lib/libcmdline.a
-
-all: $(PROG)
-
-clean:
- rm -f $(PROG) $(OBJS)
-
-$(PROG): $(OBJS) $(LDLIB)
- $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LDLIB)
-
-%.o: %.c
- $(CC) $(CFLAGS) -c $< -o $@
+++ /dev/null
-SRC = main.c
-
-OBJS = $(SRC:%.c=%.o)
-
-PROG = client
-
-all: $(PROG)
-
-clean:
- rm -f $(PROG) $(OBJS)
-
-$(PROG): $(OBJS) $(LDLIB)
- $(CC) $(LDFLAGS) -o $@ $(OBJS)
-
-%.o: %.c
- $(CC) $(CFLAGS) -c $< -o $@
+++ /dev/null
-SRC = main.c commands.c parse_obj_list.c
-
-OBJS = $(SRC:%.c=%.o)
-
-PROG = extension_example
-LDLIB = ../lib/libcmdline.a
-
-all: $(PROG)
-
-clean:
- rm -f $(PROG) $(OBJS)
-
-$(PROG): $(OBJS) $(LDLIB)
- $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LDLIB)
-
-%.o: %.c
- $(CC) $(CFLAGS) -c $< -o $@
+++ /dev/null
-SRC := conf_parser.c conf_htable.c expression.c parser_common.c dotconfig.c
-SRC += main.c parse_confnode.c commands.c
-SRC += confnode.c confnode_comment.c confnode_config.c
-SRC += confnode_menu.c confnode_menuconfig.c confnode_if.c
-SRC += confnode_choice.c confnode_intconfig.c confnode_strconfig.c
-SRC += confnode_choiceconfig.c confnode_root.c
-
-OBJS = $(SRC:%.c=%.o)
-
-PROG = genconf
-LDLIB = ../lib/libcmdline.a
-
-all: $(PROG)
-
-clean:
- rm -f $(PROG) $(OBJS)
-
-$(PROG): $(OBJS) $(LDLIB)
- $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LDLIB)
-
-%.o: %.c
- $(CC) $(CFLAGS) -c $< -o $@
+++ /dev/null
-SRC = cmdline_vt100.c cmdline_cirbuf.c
-SRC += cmdline.c cmdline_socket.c
-SRC += cmdline_parse.c cmdline_parse_num.c
-SRC += cmdline_parse_string.c cmdline_rdline.c
-SRC += cmdline_parse_ipaddr.c
-SRC += cmdline_parse_etheraddr.c
-SRC += cmdline_parse_file.c
-
-OBJS = $(SRC:%.c=%.o)
-
-LIB = libcmdline.a
-
-all: $(LIB)
-
-clean:
- rm -f $(OBJS) $(LIB)
-
-$(LIB): $(OBJS)
- $(AR) cru $(LIB) $(OBJS)
- ranlib $(LIB)
-
-%.o: %.c
- $(CC) $(CFLAGS) -c $< -o $@
+++ /dev/null
-SRC = main.c
-
-OBJS = $(SRC:%.c=%.o)
-
-PROG = trivial_rdline
-LDLIB = ../lib/libcmdline.a
-
-all: $(PROG)
-
-clean:
- rm -f $(PROG) $(OBJS)
-
-$(PROG): $(OBJS) $(LDLIB)
- $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LDLIB)
-
-%.o: %.c
- $(CC) $(CFLAGS) -c $< -o $@
--- /dev/null
+VPATH += $(SRCDIR)/$(S)
+
+OBJS := $(SRCS:%.c=%.o)
+DEPS := $(SRCS:%.c=%.d)
+
+INST := $(addsuffix _install,$(INSTALL_HEADERS))
+
+all: $(LIB).so $(LIB).a
+
+RANLIB ?= ranlib
+$(LIB).a: $(OBJS)
+ $(AR) cru $(LIB).a $(OBJS)
+ $(RANLIB) $(LIB).a
+
+$(LIB).so: $(OBJS)
+ $(CC) $(LDFLAGS) -shared $(OBJS) -o $@
+
+%.o: %.c
+ $(CC) -Wp,-MD,$(@:%.o=%.d) $(CFLAGS) -o $@ -c $<
+
+clean:
+ rm -f $(OBJS) $(DEPS) $(LIB).a $(LIB).so
+
+%_install: %
+ @echo "Install $< in $(PREFIX)/include"; \
+ cp $< $(PREFIX)/include || exit 1
+
+install: $(INST)
+ @echo "Install $(LIB).so in $(PREFIX)/lib"; \
+ cp $(LIB).so $(PREFIX)/lib || exit 1
+
+uninstall: $(UNINST)
+ @for i in $(INSTALL_HEADERS); do \
+ echo "Uninstall $$i from $(PREFIX)/include"; \
+ rm -f $(PREFIX)/include/$$i; \
+ done
+ @echo "Uninstall $(LIB).so"
+ @rm -f $(PREFIX)/lib/$(LIB).so
+
+.PHONY: all clean install uninstall
+
+-include $(DEPS)
--- /dev/null
+VPATH += $(SRCDIR)/$(S)
+
+OBJS := $(SRCS:%.c=%.o)
+DEPS := $(SRCS:%.c=%.d)
+
+all: $(PROG)
+
+$(PROG): $(OBJS)
+ $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LDLIBS)
+
+%.o: %.c
+ $(CC) -Wp,-MD,$(@:%.o=%.d) $(CFLAGS) -o $@ -c $<
+
+clean:
+ rm -f $(OBJS) $(DEPS) $(PROG)
+
+install:
+
+uninstall:
+
+.PHONY: all clean install uninstall
+
+-include $(DEPS)
--- /dev/null
+ifeq ($(S),)
+S = .
+endif
+
+_all: all
+
+all clean install uninstall:
+ @for i in $(SUBDIRS) ; do \
+ echo "== $$i"; \
+ mkdir -p $(BUILDDIR)/$(S)/$$i; \
+ $(MAKE) -C $(BUILDDIR)/$(S)/$$i \
+ -f $(SRCDIR)/$(S)/$$i/Makefile \
+ S=$(S)/$$i $@ || exit $$? ; \
+ done
+
+.PHONY: _all all clean install uninstall
--- /dev/null
+CC = $(CROSS)gcc
+AR = $(CROSS)ar
+RANLIB = $(CROSS)ranlib
+
+# uncomment if you don't have libevent
+HAVE_EVENT_LIB=y
+
+# configuration for lib, not adviced to modify it except for
+# really small devices, because it changes the API.
+# CFLAGS += -DNO_RDLINE_HISTORY
+# CFLAGS += -DNO_RDLINE_KILL_BUF
+CFLAGS += -DCMDLINE_HAVE_FLOAT
+CFLAGS += -DCMDLINE_HAVE_SOCKET
+
+CFLAGS += -fPIC
+CFLAGS += -Wall -Werror
+CFLAGS += -O0 -g
+
+CFLAGS += -I$(SRCDIR)/lib
+
+# needed if you want to parse float
+LDFLAGS += -lm
--- /dev/null
+include $(TOPDIR)/libcmdline.vars.mk
+
+PROG = calculator_server
+
+LDLIBS = $(BUILDDIR)/lib/libcmdline.a
+SRCS = commands.c main.c
+
+include $(TOPDIR)/libcmdline.prog.mk
--- /dev/null
+include $(TOPDIR)/libcmdline.vars.mk
+
+PROG = calculator_standalone
+
+LDLIBS = $(BUILDDIR)/lib/libcmdline.a
+SRCS = commands.c main.c
+
+include $(TOPDIR)/libcmdline.prog.mk
--- /dev/null
+include $(TOPDIR)/libcmdline.vars.mk
+
+PROG = client
+
+LDLIBS = $(BUILDDIR)/lib/libcmdline.a
+SRCS = main.c
+
+include $(TOPDIR)/libcmdline.prog.mk
--- /dev/null
+include $(TOPDIR)/libcmdline.vars.mk
+
+PROG = event_server
+
+LDLIBS = -levent $(BUILDDIR)/lib/libcmdline.a
+SRCS = commands.c main.c
+
+include $(TOPDIR)/libcmdline.prog.mk
--- /dev/null
+include $(TOPDIR)/libcmdline.vars.mk
+
+PROG = extension_example
+
+LDLIBS = $(BUILDDIR)/lib/libcmdline.a
+SRCS = commands.c parse_obj_list.c main.c
+
+include $(TOPDIR)/libcmdline.prog.mk
--- /dev/null
+include $(TOPDIR)/libcmdline.vars.mk
+
+PROG = genconf
+
+LDLIBS = $(BUILDDIR)/lib/libcmdline.a
+SRCS = commands.c
+SRCS += conf_htable.c
+SRCS += confnode.c
+SRCS += confnode_choice.c
+SRCS += confnode_choiceconfig.c
+SRCS += confnode_comment.c
+SRCS += confnode_config.c
+SRCS += confnode_if.c
+SRCS += confnode_intconfig.c
+SRCS += confnode_menu.c
+SRCS += confnode_menuconfig.c
+SRCS += confnode_root.c
+SRCS += confnode_strconfig.c
+SRCS += conf_parser.c
+SRCS += dotconfig.c
+SRCS += expression.c
+SRCS += main.c
+SRCS += parse_confnode.c
+SRCS += parser_common.c
+
+include $(TOPDIR)/libcmdline.prog.mk
--- /dev/null
+include $(TOPDIR)/libcmdline.vars.mk
+
+LIB = libcmdline
+
+INSTALL_HEADERS = cmdline.h
+INSTALL_HEADERS += cmdline_cirbuf.h
+INSTALL_HEADERS += cmdline_parse_etheraddr.h
+INSTALL_HEADERS += cmdline_parse_file.h
+INSTALL_HEADERS += cmdline_parse.h
+INSTALL_HEADERS += cmdline_parse_ipaddr.h
+INSTALL_HEADERS += cmdline_parse_num.h
+INSTALL_HEADERS += cmdline_parse_string.h
+INSTALL_HEADERS += cmdline_rdline.h
+INSTALL_HEADERS += cmdline_socket.h
+INSTALL_HEADERS += cmdline_vt100.h
+
+SRCS = cmdline_vt100.c cmdline_cirbuf.c
+SRCS += cmdline.c cmdline_socket.c
+SRCS += cmdline_parse.c cmdline_parse_num.c
+SRCS += cmdline_parse_string.c cmdline_rdline.c
+SRCS += cmdline_parse_ipaddr.c
+SRCS += cmdline_parse_etheraddr.c
+SRCS += cmdline_parse_file.c
+
+include $(TOPDIR)/libcmdline.lib.mk
--- /dev/null
+include $(TOPDIR)/libcmdline.vars.mk
+
+PROG = trivial_rdline
+
+LDLIBS = $(BUILDDIR)/lib/libcmdline.a
+SRCS = main.c
+
+include $(TOPDIR)/libcmdline.prog.mk