build: Switch to autotools

This commit is contained in:
Guillem Jover 2010-12-17 11:13:04 +01:00
parent 0aa777f47e
commit dcaa93d984
9 changed files with 250 additions and 238 deletions

13
.gitignore vendored
View File

@ -1,6 +1,19 @@
ChangeLog
*.pc
*.la
*.lo
*.o
*.so*
*.a
.deps/
.libs/
Makefile
Makefile.in
aclocal.m4
autom4te.cache/
build-aux/
configure
config.*
libtool
m4/
stamp-h1

237
Makefile
View File

@ -1,237 +0,0 @@
VERSION := $(shell ./get-version)
LIB_NAME := libbsd
LIB_VERSION_MAJOR := 0
LIB_VERSION_MINOR := 3
LIB_VERSION_MICRO := 0
LIB_VERSION := $(LIB_VERSION_MAJOR).$(LIB_VERSION_MINOR).$(LIB_VERSION_MICRO)
LIB_PKGCONFIG := src/$(LIB_NAME).pc
LIB_PKGCONFIG_OVERLAY := src/$(LIB_NAME)-overlay.pc
LIB_STATIC := $(LIB_NAME).a
LIB_SHARED_SO := $(LIB_NAME).so
LIB_SONAME := $(LIB_SHARED_SO).$(LIB_VERSION_MAJOR)
LIB_SHARED := $(LIB_SONAME).$(LIB_VERSION_MINOR).$(LIB_VERSION_MICRO)
TAR_NAME := $(LIB_NAME)-$(VERSION)
TAR_FILE := $(TAR_NAME).tar.gz
LIB_DIST := \
ChangeLog
LIB_SRCS_GEN := \
hash/md5hl.c
LIB_SRCS := \
arc4random.c \
bsd_getopt.c \
err.c \
fgetln.c \
flopen.c \
fpurge.c \
getpeereid.c \
heapsort.c \
merge.c \
humanize_number.c \
dehumanize_number.c \
inet_net_pton.c \
hash/md5.c \
pidfile.c \
readpassphrase.c \
reallocf.c \
setmode.c \
setproctitle.c \
strmode.c \
strtonum.c \
strlcat.c strlcpy.c \
fmtcheck.c \
nlist.c \
progname.c \
radixsort.c \
vis.c unvis.c \
$(LIB_SRCS_GEN)
LIB_SRCS_GEN := $(patsubst %,src/%,$(LIB_SRCS_GEN))
LIB_SRCS := $(patsubst %,src/%,$(LIB_SRCS))
LIB_INCLUDES := \
bsd/cdefs.h \
bsd/queue.h \
bsd/ip_icmp.h \
bsd/sys/cdefs.h \
bsd/sys/bitstring.h \
bsd/sys/endian.h \
bsd/sys/poll.h \
bsd/sys/queue.h \
bsd/sys/tree.h \
bsd/netinet/ip_icmp.h \
bsd/err.h \
bsd/getopt.h \
bsd/inet.h \
bsd/random.h \
bsd/md5.h \
bsd/string.h \
bsd/bsd.h \
bsd/stdio.h \
bsd/stdlib.h \
bsd/readpassphrase.h \
bsd/unistd.h \
bsd/nlist.h \
bsd/vis.h \
bsd/libutil.h \
nlist.h \
vis.h \
libutil.h
LIB_MANS_GEN := \
md5.3bsd
LIB_MANS := \
arc4random.3 \
arc4random_addrandom.3 \
arc4random_buf.3 \
arc4random_stir.3 \
arc4random_uniform.3 \
dehumanize_number.3 \
strtonum.3 \
strlcpy.3 \
strlcat.3 \
fgetln.3 \
flopen.3 \
getpeereid.3 \
readpassphrase.3 \
reallocf.3 \
heapsort.3 \
humanize_number.3 \
fmtcheck.3 \
mergesort.3 \
radixsort.3 \
sradixsort.3 \
nlist.3 \
pidfile.3 \
setmode.3 \
getmode.3 \
strmode.3 \
unvis.3 \
vis.3 \
$(LIB_MANS_GEN)
LIB_MANS_GEN := $(patsubst %,man/%,$(LIB_MANS_GEN))
LIB_MANS := $(patsubst %,man/%,$(LIB_MANS))
LIB_STATIC_OBJS := $(LIB_SRCS:%.c=%.o)
LIB_SHARED_OBJS := $(LIB_SRCS:%.c=%.lo)
AR = ar
CC = gcc
CCLD = $(CC)
# Set default values for user variables
CPPFLAGS ?=
CFLAGS ?= -g -Wall -Wextra -Wno-unused-variable
LDFLAGS ?=
# Internal makefile variables
MK_CPPFLAGS := -isystem include/bsd/ \
-DLIBBSD_OVERLAY -DLIBBSD_DISABLE_DEPRECATED \
-D_GNU_SOURCE -D__REENTRANT
MK_CFLAGS :=
MK_LDFLAGS :=
COMPILE = $(CC) $(MK_CPPFLAGS) $(CPPFLAGS) $(MK_CFLAGS) $(CFLAGS)
LINK = $(CCLD) $(MK_CFLAGS) $(CFLAGS) $(MK_LDFLAGS) $(LDFLAGS)
prefix = /usr
exec_prefix =
libdir = ${exec_prefix}/lib
usrlibdir = ${prefix}/lib
includedir = ${prefix}/include
pkgconfigdir = ${usrlibdir}/pkgconfig
mandir = ${prefix}/share/man
.PHONY: libs
libs: $(LIB_STATIC) $(LIB_SHARED_SO) $(LIB_PKGCONFIG) $(LIB_PKGCONFIG_OVERLAY)
.PHONY: man
man: $(LIB_MANS)
%.lo: %.c
$(COMPILE) -o $@ -DPIC -fPIC -c $<
%.o: %.c
$(COMPILE) -o $@ -c $<
man/md5.3bsd: man/mdX.3
sed -e 's/mdX/md5/g' -e 's/mdY/md4/g' -e 's/MDX/MD5/g' $< > $@
src/hash/md5hl.c: src/hash/helper.c
sed -e 's:hashinc:bsd/md5.h:g' -e 's:HASH:MD5:g' $< > $@
%.pc: %.pc.in
sed -e 's:@VERSION@:$(VERSION):' \
-e 's:@prefix@:$(value prefix):' \
-e 's:@exec_prefix@:$(value exec_prefix):' \
-e 's:@libdir@:$(value usrlibdir):' \
-e 's:@includedir@:$(value includedir):' \
$< > $@
$(LIB_STATIC): $(LIB_STATIC_OBJS)
$(AR) rcs $@ $^
$(LIB_SHARED_SO): $(LIB_SONAME)
ln -fs $^ $@
$(LIB_SONAME): $(LIB_SHARED)
ln -fs $^ $@
$(LIB_SHARED): $(LIB_SHARED_OBJS)
$(LINK) \
-shared \
-Wl,-soname -Wl,$(LIB_SONAME) \
-Wl,--version-script=src/libbsd.map \
-o $@ $^
.PHONY: ChangeLog
ChangeLog:
-git log --stat -C >$@
.PHONY: dist
dist: $(LIB_DIST)
mkdir $(TAR_NAME)
echo $(VERSION) >$(TAR_NAME)/.dist-version
cp -a --parents $(LIB_DIST) `git ls-files` $(TAR_NAME)
tar czf $(TAR_FILE) --exclude=.gitignore $(TAR_NAME)
rm -rf $(TAR_NAME)
gpg -a -b $(TAR_FILE)
.PHONY: install
install: libs man
mkdir -p $(DESTDIR)$(libdir)
mkdir -p $(DESTDIR)$(usrlibdir)
mkdir -p $(DESTDIR)$(includedir)/bsd/
mkdir -p $(DESTDIR)$(includedir)/bsd/sys/
mkdir -p $(DESTDIR)$(includedir)/bsd/netinet/
mkdir -p $(DESTDIR)$(mandir)/man3
mkdir -p $(DESTDIR)$(pkgconfigdir)
install -m644 $(LIB_STATIC) $(DESTDIR)$(usrlibdir)
install -m755 $(LIB_SHARED) $(DESTDIR)$(libdir)
for i in $(LIB_INCLUDES); do \
install -m644 include/$$i $(DESTDIR)$(includedir)/$$i; \
done
install -m644 $(LIB_MANS) $(DESTDIR)$(mandir)/man3
install -m644 $(LIB_PKGCONFIG) $(DESTDIR)$(pkgconfigdir)
install -m644 $(LIB_PKGCONFIG_OVERLAY) $(DESTDIR)$(pkgconfigdir)
ifeq ($(libdir),$(usrlibdir))
# If both dirs are the same, do a relative symlink.
ln -sf $(LIB_SHARED) $(DESTDIR)$(usrlibdir)/$(LIB_SHARED_SO)
else
# Otherwise, do an absolute one.
ln -sf $(libdir)/$(LIB_SHARED) $(DESTDIR)$(usrlibdir)/$(LIB_SHARED_SO)
endif
ln -sf $(LIB_SHARED) $(DESTDIR)$(libdir)/$(LIB_SONAME)
.PHONY: clean
clean:
rm -f $(LIB_PKGCONFIG)
rm -f $(LIB_PKGCONFIG_OVERLAY)
rm -f $(LIB_SRCS_GEN) $(LIB_MANS_GEN)
rm -f $(LIB_STATIC_OBJS)
rm -f $(LIB_STATIC)
rm -f $(LIB_SHARED_OBJS)
rm -f $(LIB_SHARED) $(LIB_SONAME) $(LIB_SHARED_SO)

19
Makefile.am Normal file
View File

@ -0,0 +1,19 @@
## Process this file with automake to produce Makefile.in
SUBDIRS = include man src
ACLOCAL_AMFLAGS = -I m4
EXTRA_DIST = \
autogen \
get-version \
$(nil)
DISTCLEANFILES = ChangeLog
.PHONY: ChangeLog
ChangeLog:
git log --stat -C >$@
dist-hook:
echo $(VERSION) >$(distdir)/.dist-version

5
autogen Executable file
View File

@ -0,0 +1,5 @@
#!/bin/sh
mkdir -p m4
autoreconf -f -i
rm -rf autom4te.cache

50
configure.ac Normal file
View File

@ -0,0 +1,50 @@
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.67])
AC_INIT([libbsd], m4_esyscmd([./get-version]), [libbsd@lists.freedesktop.org])
AC_CONFIG_SRCDIR([src/fgetln.c])
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_MACRO_DIR([m4])
AM_INIT_AUTOMAKE([1.8 foreign nostdinc])
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])],
[AC_SUBST([AM_DEFAULT_VERBOSITY], [1])])
# Checks for operating system services and capabilities.
AC_USE_SYSTEM_EXTENSIONS
AC_SYS_LARGEFILE
LT_INIT
# Checks for programs.
AC_PROG_CC
AC_PROG_INSTALL
AC_PROG_LN_S
# Checks for libraries.
# Checks for header files.
# Checks for typedefs, structures, and compiler characteristics.
AC_TYPE_UID_T
AC_C_INLINE
AC_TYPE_INT64_T
AC_TYPE_MODE_T
AC_TYPE_OFF_T
AC_TYPE_PID_T
AC_TYPE_SIZE_T
AC_TYPE_SSIZE_T
# Checks for library functions.
AC_CONFIG_FILES([
Makefile
include/Makefile
man/Makefile
src/Makefile
src/libbsd.pc
src/libbsd-overlay.pc
])
AC_CONFIG_HEADERS([config.h])
AC_OUTPUT

View File

@ -44,4 +44,5 @@ else
exit 1
fi
echo "$version"
# Use printf to avoid the trailing new line that m4_esyscmd would not handle.
printf "$version"

31
include/Makefile.am Normal file
View File

@ -0,0 +1,31 @@
## Process this file with automake to produce Makefile.in
nobase_include_HEADERS = \
bsd/sys/bitstring.h \
bsd/sys/cdefs.h \
bsd/sys/endian.h \
bsd/sys/poll.h \
bsd/sys/queue.h \
bsd/sys/tree.h \
bsd/netinet/ip_icmp.h \
bsd/bsd.h \
bsd/cdefs.h \
bsd/err.h \
bsd/getopt.h \
bsd/inet.h \
bsd/ip_icmp.h \
bsd/libutil.h \
bsd/md5.h \
bsd/nlist.h \
bsd/queue.h \
bsd/random.h \
bsd/readpassphrase.h \
bsd/stdio.h \
bsd/stdlib.h \
bsd/string.h \
bsd/unistd.h \
bsd/vis.h \
libutil.h \
nlist.h \
vis.h \
$(nil)

45
man/Makefile.am Normal file
View File

@ -0,0 +1,45 @@
## Process this file with automake to produce Makefile.in
EXTRA_DIST = \
mdX.3 \
$(nil)
CLEANFILES = \
md5.3bsd \
$(nil)
SED_MD5_SUBST = -e 's/mdX/md5/g' -e 's/mdY/md4/g' -e 's/MDX/MD5/g'
md5.3bsd: $(srcdir)/mdX.3
$(AM_V_GEN) sed $(SED_MD5_SUBST) $< > $@
dist_man_MANS = \
arc4random.3 \
arc4random_addrandom.3 \
arc4random_buf.3 \
arc4random_stir.3 \
arc4random_uniform.3 \
dehumanize_number.3 \
fgetln.3 \
flopen.3 \
fmtcheck.3 \
getmode.3 \
getpeereid.3 \
heapsort.3 \
humanize_number.3 \
md5.3bsd \
mergesort.3 \
nlist.3 \
pidfile.3 \
radixsort.3 \
readpassphrase.3 \
reallocf.3 \
setmode.3 \
sradixsort.3 \
strlcat.3 \
strlcpy.3 \
strmode.3 \
strtonum.3 \
unvis.3 \
vis.3 \
$(nil)

85
src/Makefile.am Normal file
View File

@ -0,0 +1,85 @@
## Process this file with automake to produce Makefile.in
# Set default values for user variables
CFLAGS = -Wall -Wextra -Wno-unused-variable
AM_CPPFLAGS = \
-I$(top_builddir) \
-isystem $(top_srcdir)/include/bsd/ \
-DLIBBSD_OVERLAY -DLIBBSD_DISABLE_DEPRECATED \
-D_GNU_SOURCE -D__REENTRANT
EXTRA_DIST = \
libbsd.map \
libbsd.pc.in \
libbsd-overlay.pc.in \
hash/helper.c \
$(nil)
CLEANFILES = \
hash/md5hl.c \
$(nil)
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = \
libbsd.pc \
libbsd-overlay.pc \
$(nil)
lib_LTLIBRARIES = libbsd.la
hash/md5hl.c: $(srcdir)/hash/helper.c
$(MKDIR_P) hash
$(AM_V_GEN) sed -e 's:hashinc:bsd/md5.h:g' -e 's:HASH:MD5:g' $< > $@
libbsd_la_DEPENDENCIES = \
libbsd.map
libbsd_la_LDFLAGS = \
-Wl,--version-script=$(srcdir)/libbsd.map \
-version-number 0:3:0
libbsd_la_SOURCES = \
arc4random.c \
bsd_getopt.c \
dehumanize_number.c \
err.c \
fgetln.c \
flopen.c \
fmtcheck.c \
fpurge.c \
getpeereid.c \
hash/md5.c \
hash/md5hl.c \
heapsort.c \
humanize_number.c \
inet_net_pton.c \
local-elf.h \
merge.c \
nlist.c \
pidfile.c \
progname.c \
radixsort.c \
readpassphrase.c \
reallocf.c \
setmode.c \
setproctitle.c \
strlcat.c \
strlcpy.c \
strmode.c \
strtonum.c \
unvis.c \
vis.c \
$(nil)
install-exec-hook:
if [ "$(libdir)" != "$(runtimelibdir)" ]; then \
mkdir -p $(DESTDIR)$(runtimelibdir); \
mv $(DESTDIR)$(libdir)/libbsd*.so.* \
$(DESTDIR)$(runtimelibdir)/; \
soname=`readlink $(DESTDIR)$(libdir)/libbsd.so`; \
sorelprefix=`echo $(libdir) | sed -r -e 's:(^/)?[^/]+:..:g'`; \
ln -sf $$sorelprefix$(runtimelibdir)/$$soname \
$(DESTDIR)$(libdir)/libbsd.so; \
fi
uninstall-hook:
rm -f $(DESTDIR)$(runtimelibdir)/libbsd*.so*