mirror of
https://github.com/arachsys/libelf.git
synced 2026-01-27 01:44:27 +00:00
The Makefile supports the usual DESTDIR and PREFIX to control the install paths, as well as specific INCDIR and LIBDIR variables. The shared library is built with a soname and minor version to match the upstream release. Our config.h should provide sensible definitions to build and install on either musl or glibc, and using either clang or gcc. It might need manual adjustment on very old or non-Linux systems.
53 lines
1.3 KiB
Makefile
53 lines
1.3 KiB
Makefile
INCDIR = $(PREFIX)/include
|
|
LIBDIR = $(PREFIX)/lib
|
|
|
|
CFLAGS = -O2 -Wall
|
|
LDFLAGS =
|
|
LDLIBS = -lz
|
|
|
|
MAJOR = 1
|
|
MINOR = 0.185
|
|
|
|
HEADERS = $(wildcard include/*.h src/*.h)
|
|
SOURCES = $(wildcard src/*.c)
|
|
LIBOBJS = $(patsubst %.c,%.o,$(SOURCES))
|
|
PICOBJS = $(patsubst %.c,%.os,$(SOURCES))
|
|
|
|
override CFLAGS += -DHAVE_CONFIG_H -Iinclude -Isrc
|
|
|
|
all: libelf.a libelf.so
|
|
|
|
clean:
|
|
rm -f src/*.o src/*.os libelf.a libelf.so
|
|
|
|
libelf.a: $(LIBOBJS) Makefile
|
|
$(AR) rcs $@ $(LIBOBJS)
|
|
|
|
libelf.so: $(PICOBJS) Makefile
|
|
$(CC) $(LDFLAGS) -shared -Wl,-soname,libelf.so.$(MAJOR) \
|
|
-o $@ $(PICOBJS) $(LDLIBS)
|
|
|
|
%.o:: %.c $(HEADERS) Makefile
|
|
$(CC) $(CFLAGS) -c -o $@ $<
|
|
|
|
%.os:: %.c $(HEADERS) Makefile
|
|
$(CC) $(CFLAGS) -fPIC -c -o $@ $<
|
|
|
|
install: install-headers install-static install-shared
|
|
|
|
install-headers: include/*.h
|
|
mkdir -p $(DESTDIR)$(INCDIR)
|
|
install -m 0644 include/*.h $(DESTDIR)$(INCDIR)
|
|
|
|
install-static: libelf.a install-headers
|
|
mkdir -p $(DESTDIR)$(LIBDIR)
|
|
install -m 0644 $< $(DESTDIR)$(LIBDIR)
|
|
|
|
install-shared: libelf.so install-headers
|
|
mkdir -p $(DESTDIR)$(LIBDIR)
|
|
install $< $(DESTDIR)$(LIBDIR)/libelf.so.$(MAJOR).$(MINOR)
|
|
ln -f -s libelf.so.$(MAJOR).$(MINOR) $(DESTDIR)$(LIBDIR)/libelf.so.$(MAJOR)
|
|
ln -f -s libelf.so.$(MAJOR).$(MINOR) $(DESTDIR)$(LIBDIR)/libelf.so
|
|
|
|
.PHONY: all clean install install-*
|