From: Olivier Matz Date: Fri, 17 Feb 2012 19:20:31 +0000 (+0100) Subject: cmdline: new build system X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=refs%2Fheads%2Fmaster;p=libcmdline.git cmdline: new build system Signed-off-by: Olivier Matz --- diff --git a/Makefile b/Makefile index 45a51f8..c79f93c 100644 --- a/Makefile +++ b/Makefile @@ -1,37 +1,26 @@ -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 diff --git a/README b/README new file mode 100644 index 0000000..150f0cd --- /dev/null +++ b/README @@ -0,0 +1,18 @@ +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- diff --git a/build/calculator_server/Makefile b/build/calculator_server/Makefile deleted file mode 100755 index 523a8a8..0000000 --- a/build/calculator_server/Makefile +++ /dev/null @@ -1,17 +0,0 @@ -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 $@ diff --git a/build/calculator_standalone/Makefile b/build/calculator_standalone/Makefile deleted file mode 100755 index 53383be..0000000 --- a/build/calculator_standalone/Makefile +++ /dev/null @@ -1,17 +0,0 @@ -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 $@ diff --git a/build/client/Makefile b/build/client/Makefile deleted file mode 100755 index 57a440f..0000000 --- a/build/client/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -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 $@ diff --git a/build/extension_example/Makefile b/build/extension_example/Makefile deleted file mode 100755 index 6839965..0000000 --- a/build/extension_example/Makefile +++ /dev/null @@ -1,17 +0,0 @@ -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 $@ diff --git a/build/genconf/Makefile b/build/genconf/Makefile deleted file mode 100644 index 3e98788..0000000 --- a/build/genconf/Makefile +++ /dev/null @@ -1,22 +0,0 @@ -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 $@ diff --git a/build/lib/Makefile b/build/lib/Makefile deleted file mode 100755 index 56187d6..0000000 --- a/build/lib/Makefile +++ /dev/null @@ -1,23 +0,0 @@ -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 $@ diff --git a/build/trivial_rdline/Makefile b/build/trivial_rdline/Makefile deleted file mode 100755 index 73aec4a..0000000 --- a/build/trivial_rdline/Makefile +++ /dev/null @@ -1,17 +0,0 @@ -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 $@ diff --git a/libcmdline.lib.mk b/libcmdline.lib.mk new file mode 100644 index 0000000..2a2f898 --- /dev/null +++ b/libcmdline.lib.mk @@ -0,0 +1,42 @@ +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) diff --git a/libcmdline.prog.mk b/libcmdline.prog.mk new file mode 100644 index 0000000..cd6d199 --- /dev/null +++ b/libcmdline.prog.mk @@ -0,0 +1,23 @@ +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) diff --git a/libcmdline.subdir.mk b/libcmdline.subdir.mk new file mode 100644 index 0000000..e01cbb5 --- /dev/null +++ b/libcmdline.subdir.mk @@ -0,0 +1,16 @@ +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 diff --git a/libcmdline.vars.mk b/libcmdline.vars.mk new file mode 100644 index 0000000..23312d2 --- /dev/null +++ b/libcmdline.vars.mk @@ -0,0 +1,22 @@ +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 diff --git a/src/calculator_server/Makefile b/src/calculator_server/Makefile new file mode 100644 index 0000000..7daf2ee --- /dev/null +++ b/src/calculator_server/Makefile @@ -0,0 +1,8 @@ +include $(TOPDIR)/libcmdline.vars.mk + +PROG = calculator_server + +LDLIBS = $(BUILDDIR)/lib/libcmdline.a +SRCS = commands.c main.c + +include $(TOPDIR)/libcmdline.prog.mk diff --git a/src/calculator_standalone/Makefile b/src/calculator_standalone/Makefile new file mode 100644 index 0000000..a627509 --- /dev/null +++ b/src/calculator_standalone/Makefile @@ -0,0 +1,8 @@ +include $(TOPDIR)/libcmdline.vars.mk + +PROG = calculator_standalone + +LDLIBS = $(BUILDDIR)/lib/libcmdline.a +SRCS = commands.c main.c + +include $(TOPDIR)/libcmdline.prog.mk diff --git a/src/client/Makefile b/src/client/Makefile new file mode 100644 index 0000000..cea1196 --- /dev/null +++ b/src/client/Makefile @@ -0,0 +1,8 @@ +include $(TOPDIR)/libcmdline.vars.mk + +PROG = client + +LDLIBS = $(BUILDDIR)/lib/libcmdline.a +SRCS = main.c + +include $(TOPDIR)/libcmdline.prog.mk diff --git a/src/event_server/Makefile b/src/event_server/Makefile new file mode 100644 index 0000000..46c3031 --- /dev/null +++ b/src/event_server/Makefile @@ -0,0 +1,8 @@ +include $(TOPDIR)/libcmdline.vars.mk + +PROG = event_server + +LDLIBS = -levent $(BUILDDIR)/lib/libcmdline.a +SRCS = commands.c main.c + +include $(TOPDIR)/libcmdline.prog.mk diff --git a/src/extension_example/Makefile b/src/extension_example/Makefile new file mode 100644 index 0000000..7bcfa9d --- /dev/null +++ b/src/extension_example/Makefile @@ -0,0 +1,8 @@ +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 diff --git a/src/genconf/Makefile b/src/genconf/Makefile new file mode 100644 index 0000000..c0cf9be --- /dev/null +++ b/src/genconf/Makefile @@ -0,0 +1,26 @@ +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 diff --git a/src/lib/Makefile b/src/lib/Makefile new file mode 100644 index 0000000..5549798 --- /dev/null +++ b/src/lib/Makefile @@ -0,0 +1,25 @@ +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 diff --git a/src/trivial_rdline/Makefile b/src/trivial_rdline/Makefile new file mode 100644 index 0000000..d07b7e9 --- /dev/null +++ b/src/trivial_rdline/Makefile @@ -0,0 +1,8 @@ +include $(TOPDIR)/libcmdline.vars.mk + +PROG = trivial_rdline + +LDLIBS = $(BUILDDIR)/lib/libcmdline.a +SRCS = main.c + +include $(TOPDIR)/libcmdline.prog.mk