Make libite standalone

Add basic .gitignore, cleanup inherited Makefile from Finit
and add a small rules.mk from libuEv.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson committed 2015-06-17 21:13:02 +02:00
1 parent 1758f9a847
commit 22a79ee947
3 files changed
+77 -17

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
*.d
*.o
*.so
*.so.*
*.a
+63 -17
View File
@@ -1,6 +1,6 @@
# Finit libite -- Light-weight utility functions and C-library extensions # libite -- Light-weight utility functions and C-library extensions
# #
# Copyright (c) 2008-2014 Joachim Nilsson <troglobit@gmail.com> # Copyright (c) 2008-2015 Joachim Nilsson <troglobit@gmail.com>
# #
# Permission is hereby granted, free of charge, to any person obtaining a copy # Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal # of this software and associated documentation files (the "Software"), to deal
@@ -19,58 +19,91 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE. # THE SOFTWARE.
.EXPORT_ALL_VARIABLES:
.PHONY: all install clean .PHONY: all install clean
include ../common.mk # Figure out root of library, unless used as submodule
ROOTDIR ?= $(shell pwd)
#VERSION = $(shell git tag -l | tail -1)
VERSION ?= 1.0.0
NAME = libite
PKG = $(NAME)-$(VERSION)
ARCHIVE = $(PKG).tar.xz
CC ?= $(CROSS)gcc
AR ?= $(CROSS)ar
STRIP ?= $(CROSS)strip
INSTALL := install --backup=off
STRIPINST := $(INSTALL) -s --strip-program=$(CROSS)strip -m 0755
ifneq ($(STATIC), 1) ifneq ($(STATIC), 1)
CFLAGS += -fPIC CFLAGS += -fPIC
endif endif
CFLAGS += -Os
CPPFLAGS += -W -Wall -Werror
ARFLAGS = crus
MAKEFLAGS = --no-print-directory --silent
DISTFILES = README LICENSE
HEADERS = lite.h HEADERS = lite.h
OBJS := copyfile.o dir.o fexist.o fisdir.o fmode.o rsync.o OBJS := copyfile.o dir.o fexist.o fisdir.o fmode.o rsync.o
OBJS += strlcpy.o strlcat.o strtonum.o OBJS += strlcpy.o strlcat.o strtonum.o
DEPS := $(OBJS:.o=.d) DEPS := $(OBJS:.o=.d)
JUNK = *~ *.bak *.map .*.d *.d DEADJOE semantic.cache *.gdb *.elf core core.*
VER = 0 VER = 1
LIBNAME = libite LIBNAME = $(NAME)
SOLIB = $(LIBNAME).so.$(VER) SOLIB = $(LIBNAME).so.$(VER)
SYMLIB = $(LIBNAME).so SYMLIB = $(LIBNAME).so
STATICLIB = $(LIBNAME).a STATICLIB = $(LIBNAME).a
ifeq ($(STATIC), 1) ifdef STATIC
TARGET = $(STATICLIB) TARGET = $(STATICLIB)
else else
TARGET = $(STATICLIB) $(SOLIB) TARGET = $(SOLIB)
endif endif
# Default install paths
prefix ?= /usr/local
libdir ?= $(prefix)/lib
datadir ?= $(prefix)/share/doc/$(LIBNAME)
incdir ?= $(prefix)/include
# This magic trick looks like a comment, but works on BSD PMake
#include <rules.mk>
include rules.mk
# Build rules
all: $(TARGET) all: $(TARGET)
$(OBJS): Makefile $(OBJS): Makefile
$(SOLIB): $(OBJS) $(SOLIB): Makefile $(OBJS)
@printf " LINK %s\n" $@ @printf " LINK %s\n" $@
@$(CC) $(LDFLAGS) -shared $(OBJS) -lrt -lcrypt -Wl,-soname,$@ -o $@ @$(CC) $(LDFLAGS) -shared -Wl,-soname,$@ -o $@ $(OBJS) -lrt -lcrypt
$(STATICLIB): Makefile $(OBJS) $(STATICLIB): Makefile $(OBJS)
@printf " ARCHIVE $@\n" @printf " ARCHIVE $@\n"
@$(AR) $(ARFLAGS) $@ $(OBJS) @$(AR) $(ARFLAGS) $@ $(OBJS)
install-exec: all install-exec: all
@install -d $(DESTDIR)$(libdir) ifndef STATIC
@printf " INSTALL $(DESTDIR)$(libdir)/$(SOLIB)\n" @printf " INSTALL $(DESTDIR)$(libdir)/$(SOLIB)\n"
@$(STRIPINST) $(STATICLIB) $(DESTDIR)$(libdir)/$(STATICLIB) @install -d $(DESTDIR)$(libdir)
ifeq ($(STATIC), 0) @$(STRIPINST) $(SOLIB) $(DESTDIR)$(libdir)/$(SOLIB)
@$(STRIPINST) $(SOLIB) $(DESTDIR)$(libdir)/$(SOLIB)
@ln -sf $(SOLIB) $(DESTDIR)$(libdir)/$(SYMLIB) @ln -sf $(SOLIB) $(DESTDIR)$(libdir)/$(SYMLIB)
endif endif
install-dev: install-dev:
@install -d $(DESTDIR)$(incdir)
@for file in $(HEADERS); do \ @for file in $(HEADERS); do \
printf " INSTALL $(DESTDIR)$(incdir)/$$file\n"; \ printf " INSTALL $(DESTDIR)$(incdir)/$$file\n"; \
$(INSTALL) -m 0644 $$file $(DESTDIR)$(incdir)/$$file; \ $(INSTALL) -m 0644 $$file $(DESTDIR)$(incdir)/$$file; \
done done
ifdef STATIC
@printf " INSTALL $(DESTDIR)$(libdir)/$(STATICLIB)\n"
@install -d $(DESTDIR)$(libdir)
@$(INSTALL) $(STATICLIB) $(DESTDIR)$(libdir)/$(STATICLIB)
endif
install: install-exec install-dev install: install-exec install-dev
@@ -82,12 +115,25 @@ uninstall:
$(RM) $(DESTDIR)$(incdir)/$$file; \ $(RM) $(DESTDIR)$(incdir)/$$file; \
done done
strip: $(TARGET)
@printf " STRIP %s\n" $(TARGET)
@$(STRIP) --strip-unneeded $(TARGET)
@size $(TARGET)
# Runs Clang scan-build on the whole tree
check: clean
@scan-build $(MAKE) all
clean: clean:
-@$(RM) $(OBJS) $(DEPS) $(TARGET) $(SOLIB) $(STATICLIB) -@$(RM) $(OBJS) $(DEPS) $(TARGET) $(SOLIB) $(STATICLIB)
distclean: distclean:
-@$(RM) $(JUNK) unittest *.o *.a *.so* *.unittest -@$(RM) $(JUNK) unittest *.o *.a *.so* *.unittest
ifneq ($(MAKECMDGOALS),distclean) dist:
@echo "Building .xz tarball of $(PKG) in parent dir..."
git archive --format=tar --prefix=$(PKG)/ v$(VERSION) | xz >../$(ARCHIVE)
@(cd ..; md5sum $(ARCHIVE) | tee $(ARCHIVE).md5)
# Include automatically generated rules
-include $(DEPS) -include $(DEPS)
endif
+9
View File
@@ -0,0 +1,9 @@
# Pretty printing and GCC -M for auto dep files
%.o: %.c
@printf " CC $(subst $(ROOTDIR)/,,$(shell pwd)/)$@\n"
@$(CC) $(CFLAGS) $(CPPFLAGS) -c -MMD -MP -o $@ $<
%: %.o
@printf " LINK $(subst $(ROOTDIR)/,,$(shell pwd)/)$@\n"
@$(CC) $(CFLAGS) $(LDFLAGS) -Wl,-Map,$@.map -o $@ $^ $(LDLIBS$(LDLIBS-$(@)))