Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makefile: various improvements, including POSIX compatibility #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 55 additions & 33 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,63 +1,85 @@
prefix=/usr/local
libdir=$(prefix)/lib
includedir=$(prefix)/include

CC=gcc
AR=ar
RANLIB=ranlib
INSTALL=./install.sh
.POSIX:

PREFIX=/usr/local
INCLUDEDIR=$(PREFIX)/include
LIBDIR=$(PREFIX)/lib
PKGCONFIGDIR=$(LIBDIR)/pkgconfig

PICFLAGS=-fPIC
WFLAGS=-Wall
CFLAGS?=-O2
INCLUDES=-Iinclude

SHAREDLIB=libnl-tiny.so
STATICLIB=libnl-tiny.a
PCFILE=libnl-tiny.pc
ALL_LIBS=$(SHAREDLIB) $(STATICLIB)
ALL_INCLUDES=$(sort $(wildcard include/*.h include/*/*.h include/*/*/*.h))
ALL_INCLUDES=\
include/netlink-generic.h \
include/netlink-local.h \
include/netlink-types.h \
include/netlink/addr.h \
include/netlink/attr.h \
include/netlink/cache-api.h \
include/netlink/cache.h \
include/netlink/data.h \
include/netlink/errno.h \
include/netlink/genl/ctrl.h \
include/netlink/genl/family.h \
include/netlink/genl/genl.h \
include/netlink/genl/mngt.h \
include/netlink/handlers.h \
include/netlink/list.h \
include/netlink/msg.h \
include/netlink/netlink-compat.h \
include/netlink/netlink-kernel.h \
include/netlink/netlink.h \
include/netlink/object-api.h \
include/netlink/object.h \
include/netlink/socket.h \
include/netlink/types.h \
include/netlink/utils.h \
include/netlink/version.h \
include/unl.h

LIBNL_SRCS=nl.c handlers.c msg.c attr.c cache.c cache_mngt.c object.c socket.c error.c
GENL_SRCS=genl.c genl_family.c genl_ctrl.c genl_mngt.c unl.c
SRCS=$(LIBNL_SRCS) $(GENL_SRCS)
OBJS=$(SRCS:.c=.o)

PICFLAGS=-fPIC

-include config.mak

all: $(ALL_LIBS) $(PCFILE)
ALL_CFLAGS=$(CFLAGS) $(PICFLAGS) $(WFLAGS) $(INCLUDES)

install: $(ALL_LIBS:%=$(DESTDIR)$(libdir)/%) \
$(ALL_INCLUDES:include/%=$(DESTDIR)$(includedir)/libnl-tiny/%) \
$(PCFILE:%=$(DESTDIR)$(libdir)/pkgconfig/%)
all: $(ALL_LIBS) $(PCFILE)

clean:
rm -f $(OBJS) $(ALL_LIBS) $(PCFILE)

%.o: %.c
$(CC) $(CPPFLAGS) -c -o $@ $(INCLUDES) $(CFLAGS) $(PICFLAGS) $<
.c.o:
$(CC) $(CPPFLAGS) -c -o $@ $(ALL_CFLAGS) $<


$(SHAREDLIB): $(OBJS)
$(CC) -shared -o $@ $^ $(LDFLAGS)
$(CC) -shared -o $@ $(LDFLAGS) $(OBJS)

$(STATICLIB): $(OBJS)
rm -f $@
$(AR) rc $@ $^
$(RANLIB) $@
$(AR) -rc $@ $(OBJS)

$(PCFILE): $(PCFILE).in
sed s,@prefix@,$(prefix),g $< > $@


$(DESTDIR)$(includedir)/libnl-tiny/%: include/%
$(INSTALL) -D -m 644 $< $@

$(DESTDIR)$(libdir)/%: %
$(INSTALL) -D -m 644 $< $@

$(DESTDIR)$(libdir)/pkgconfig/%: %
$(INSTALL) -D -m 644 $< $@

sed 's,@prefix@,$(prefix),g' $(PCFILE).in > $@

install: $(ALL_LIBS) $(ALL_INCLUDES) $(PCFILE)
mkdir -p "$(DESTDIR)$(INCLUDEDIR)/libnl-tiny/netlink/genl"
for f in $(ALL_INCLUDES); do \
f="$${f#include/}"; \
cp "include/$$f" "$(DESTDIR)$(INCLUDEDIR)/libnl-tiny/$${f%/*}"; \
done
mkdir -p "$(DESTDIR)$(LIBDIR)"
for f in $(ALL_LIBS); do \
cp "$$f" "$(DESTDIR)$(LIBDIR)/"; \
done
mkdir -p "$(DESTDIR)$(PKGCONFIGDIR)"
cp "$(PCFILE)" "$(DESTDIR)$(PKGCONFIGDIR)/"

.PHONY: all clean install
67 changes: 0 additions & 67 deletions install.sh

This file was deleted.