libucontext/Makefile

224 lines
6.6 KiB
Makefile
Raw Normal View History

2020-12-08 01:14:51 +00:00
SCDOC := scdoc
2018-01-31 05:58:26 +00:00
ARCH := $(shell uname -m)
2019-09-18 14:54:53 +00:00
ifeq ($(ARCH),$(filter $(ARCH),i386 i686))
override ARCH = x86
endif
ifeq ($(ARCH),$(filter $(ARCH),sh2 sh4))
override ARCH = sh
endif
ifeq ($(ARCH),$(filter $(ARCH),ppc64le))
override ARCH = ppc64
endif
2018-01-30 03:41:02 +00:00
LIBDIR := /lib
2020-12-06 10:01:26 +00:00
INCLUDEDIR := /usr/include
PKGCONFIGDIR := /usr/lib/pkgconfig
2020-12-04 01:24:08 +00:00
CFLAGS := -ggdb3 -O2 -Wall
CPPFLAGS := -Iinclude -Iarch/${ARCH} -Iarch/common
EXPORT_UNPREFIXED := yes
FREESTANDING := no
ifeq ($(FREESTANDING),yes)
CFLAGS += -DFREESTANDING -isystem arch/${ARCH}/freestanding
EXPORT_UNPREFIXED = no
endif
ifeq ($(EXPORT_UNPREFIXED),yes)
CFLAGS += -DEXPORT_UNPREFIXED
endif
2018-01-30 03:41:02 +00:00
LIBUCONTEXT_C_SRC = $(wildcard arch/${ARCH}/*.c)
LIBUCONTEXT_S_SRC = $(wildcard arch/${ARCH}/*.S)
2020-12-08 10:49:52 +00:00
LIBUCONTEXT_VERSION := 0.13.1
LIBUCONTEXT_OBJ = ${LIBUCONTEXT_C_SRC:.c=.o} ${LIBUCONTEXT_S_SRC:.S=.o}
LIBUCONTEXT_SOVERSION = 0
2018-01-30 03:53:04 +00:00
LIBUCONTEXT_NAME = libucontext.so
2019-04-09 13:07:39 +00:00
LIBUCONTEXT_STATIC_NAME = libucontext.a
LIBUCONTEXT_PC = libucontext.pc
2018-01-30 03:53:04 +00:00
LIBUCONTEXT_SONAME = libucontext.so.${LIBUCONTEXT_SOVERSION}
LIBUCONTEXT_PATH = ${LIBDIR}/${LIBUCONTEXT_SONAME}
LIBUCONTEXT_STATIC_PATH = ${LIBDIR}/${LIBUCONTEXT_STATIC_NAME}
LIBUCONTEXT_HEADERS = \
include/libucontext/libucontext.h \
include/libucontext/bits.h
2020-12-08 01:15:18 +00:00
LIBUCONTEXT_EXAMPLES = \
examples/cooperative_threading
LIBUCONTEXT_POSIX_NAME = libucontext_posix.so
LIBUCONTEXT_POSIX_STATIC_NAME = libucontext_posix.a
LIBUCONTEXT_POSIX_C_SRC = libucontext_posix.c
LIBUCONTEXT_POSIX_OBJ = ${LIBUCONTEXT_POSIX_C_SRC:.c=.o}
LIBUCONTEXT_POSIX_SONAME = libucontext_posix.so.${LIBUCONTEXT_SOVERSION}
LIBUCONTEXT_POSIX_PATH = ${LIBDIR}/${LIBUCONTEXT_POSIX_SONAME}
LIBUCONTEXT_POSIX_STATIC_PATH = ${LIBDIR}/${LIBUCONTEXT_POSIX_STATIC_NAME}
ifeq ($(FREESTANDING),yes)
LIBUCONTEXT_POSIX_NAME =
LIBUCONTEXT_POSIX_STATIC_NAME =
endif
all: ${LIBUCONTEXT_SONAME} ${LIBUCONTEXT_STATIC_NAME} ${LIBUCONTEXT_POSIX_NAME} ${LIBUCONTEXT_POSIX_STATIC_NAME} ${LIBUCONTEXT_PC}
${LIBUCONTEXT_POSIX_NAME}: ${LIBUCONTEXT_NAME} ${LIBUCONTEXT_POSIX_OBJ}
$(CC) -fPIC -o ${LIBUCONTEXT_POSIX_NAME} -Wl,-soname,${LIBUCONTEXT_POSIX_SONAME} \
-shared ${LIBUCONTEXT_POSIX_OBJ} ${LDFLAGS}
${LIBUCONTEXT_POSIX_STATIC_NAME}: ${LIBUCONTEXT_POSIX_OBJ}
$(AR) rcs ${LIBUCONTEXT_POSIX_STATIC_NAME} ${LIBUCONTEXT_POSIX_OBJ}
2019-04-09 13:07:39 +00:00
${LIBUCONTEXT_POSIX_SONAME}: ${LIBUCONTEXT_POSIX_NAME}
ln -sf ${LIBUCONTEXT_POSIX_NAME} ${LIBUCONTEXT_POSIX_SONAME}
2019-04-09 13:07:39 +00:00
${LIBUCONTEXT_STATIC_NAME}: ${LIBUCONTEXT_OBJ}
$(AR) rcs ${LIBUCONTEXT_STATIC_NAME} ${LIBUCONTEXT_OBJ}
${LIBUCONTEXT_NAME}: ${LIBUCONTEXT_HEADERS} ${LIBUCONTEXT_OBJ}
$(CC) -fPIC -o ${LIBUCONTEXT_NAME} -Wl,-soname,${LIBUCONTEXT_SONAME} \
-shared ${LIBUCONTEXT_OBJ} ${LDFLAGS}
2018-01-30 03:53:04 +00:00
${LIBUCONTEXT_SONAME}: ${LIBUCONTEXT_NAME}
ln -sf ${LIBUCONTEXT_NAME} ${LIBUCONTEXT_SONAME}
${LIBUCONTEXT_PC}: libucontext.pc.in
sed -e s:@LIBUCONTEXT_VERSION@:${LIBUCONTEXT_VERSION}:g \
-e s:@LIBUCONTEXT_LIBDIR@:${LIBDIR}:g \
-e s:@LIBUCONTEXT_INCLUDEDIR@:${INCLUDEDIR}:g $< > $@
2020-12-08 01:14:51 +00:00
MANPAGES_SYMLINKS_3 = \
2020-12-08 01:19:37 +00:00
libucontext_getcontext.3 \
libucontext_makecontext.3 \
libucontext_setcontext.3 \
libucontext_swapcontext.3
2020-12-08 01:14:51 +00:00
MANPAGES_3 = doc/libucontext.3
MANPAGES = ${MANPAGES_3}
.scd.3:
${SCDOC} < $< > $@
.SUFFIXES: .scd .3
docs: ${MANPAGES}
.c.o:
2020-12-11 23:18:04 +00:00
$(CC) -std=gnu99 -D_BSD_SOURCE -fPIC -DPIC ${CFLAGS} ${CPPFLAGS} -c -o $@ $<
.S.o:
$(CC) -fPIC -DPIC -DLIBUCONTEXT_ASSEMBLY ${CFLAGS} ${CPPFLAGS} -c -o $@ $<
${LIBUCONTEXT_NAME}_clean:
rm -f ${LIBUCONTEXT_NAME}
${LIBUCONTEXT_SONAME}_clean:
rm -f ${LIBUCONTEXT_SONAME}
${LIBUCONTEXT_STATIC_NAME}_clean:
rm -f ${LIBUCONTEXT_STATIC_NAME}
libucontext_obj_clean:
rm -f ${LIBUCONTEXT_OBJ}
${LIBUCONTEXT_PC}_clean:
rm -f ${LIBUCONTEXT_PC}
bits_clean:
rm -f include/libucontext/bits.h
${LIBUCONTEXT_POSIX_NAME}_clean:
rm -f ${LIBUCONTEXT_POSIX_NAME}
${LIBUCONTEXT_POSIX_STATIC_NAME}_clean:
rm -f ${LIBUCONTEXT_POSIX_STATIC_NAME}
libucontext_posix_obj_clean:
rm -f ${LIBUCONTEXT_POSIX_OBJ}
check_clean: check_bare_clean check_posix_clean
check_bare_clean:
rm -f test_libucontext
check_posix_clean:
rm -f test_libucontext_posix
docs_clean:
rm -f ${MANPAGES}
clean: ${LIBUCONTEXT_NAME}_clean
clean: ${LIBUCONTEXT_SONAME}_clean
clean: ${LIBUCONTEXT_STATIC_NAME}_clean
clean: ${LIBUCONTEXT_PC}_clean
clean: bits_clean
clean: ${LIBUCONTEXT_POSIX_NAME}_clean
clean: ${LIBUCONTEXT_POSIX_STATIC_NAME}_clean
clean: libucontext_posix_obj_clean
clean: libucontext_obj_clean
clean: check_clean
clean: docs_clean
install: all
install -D -m755 ${LIBUCONTEXT_NAME} ${DESTDIR}${LIBUCONTEXT_PATH}
install -D -m664 ${LIBUCONTEXT_STATIC_NAME} ${DESTDIR}${LIBUCONTEXT_STATIC_PATH}
ln -sf ${LIBUCONTEXT_SONAME} ${DESTDIR}${LIBDIR}/${LIBUCONTEXT_NAME}
2020-12-06 10:01:26 +00:00
for i in ${LIBUCONTEXT_HEADERS}; do \
destfn=$$(echo $$i | sed s:include/::g); \
install -D -m644 $$i ${DESTDIR}${INCLUDEDIR}/$$destfn; \
done
install -D -m644 ${LIBUCONTEXT_PC} ${DESTDIR}${PKGCONFIGDIR}/${LIBUCONTEXT_PC}
if [ -n ${LIBUCONTEXT_POSIX_NAME} ]; then \
install -D -m755 ${LIBUCONTEXT_POSIX_NAME} ${DESTDIR}${LIBUCONTEXT_POSIX_PATH}; \
install -D -m644 ${LIBUCONTEXT_STATIC_POSIX_NAME} ${DESTDIR}${LIBUCONTEXT_STATIC_POSIX_PATH}; \
fi
2018-01-30 03:53:04 +00:00
2020-12-08 01:19:37 +00:00
install_docs: docs
install -D -m644 doc/libucontext.3 ${DESTDIR}/usr/share/man/man3/libucontext.3
for i in ${MANPAGES_SYMLINKS_3}; do \
ln -s libucontext.3 ${DESTDIR}/usr/share/man/man3/$$i; \
done
ifneq (${FREESTANDING},yes)
check: check_libucontext_posix
check_libucontext_posix: test_libucontext_posix ${LIBUCONTEXT_POSIX_SONAME}
env LD_LIBRARY_PATH=$(shell pwd) ./test_libucontext_posix
test_libucontext_posix: test_libucontext_posix.c ${LIBUCONTEXT_POSIX_NAME}
$(CC) -std=gnu99 -D_BSD_SOURCE ${CFLAGS} ${CPPFLAGS} $@.c -o $@ -L. -lucontext -lucontext_posix
endif
2018-01-30 03:53:04 +00:00
check: test_libucontext ${LIBUCONTEXT_SONAME}
env LD_LIBRARY_PATH=$(shell pwd) ./test_libucontext
2018-01-30 03:53:04 +00:00
test_libucontext: test_libucontext.c ${LIBUCONTEXT_NAME}
2020-12-11 23:18:04 +00:00
$(CC) -std=gnu99 -D_BSD_SOURCE ${CFLAGS} ${CPPFLAGS} $@.c -o $@ -L. -lucontext
2018-01-30 03:53:04 +00:00
2020-12-08 01:15:18 +00:00
examples: ${LIBUCONTEXT_EXAMPLES}
examples/cooperative_threading: examples/cooperative_threading.c ${LIBUCONTEXT_NAME}
2020-12-11 23:18:04 +00:00
$(CC) -std=gnu99 -D_BSD_SOURCE ${CFLAGS} ${CPPFLAGS} $@.c -o $@ -L. -lucontext
2020-12-08 01:15:18 +00:00
ifeq ($(FREESTANDING),no)
include/libucontext/bits.h: arch/common/bits.h
cp arch/common/bits.h $@
else
include/libucontext/bits.h: arch/${ARCH}/freestanding/bits.h
cp arch/${ARCH}/freestanding/bits.h $@
endif
2020-12-08 01:28:02 +00:00
PACKAGE_NAME = libucontext
PACKAGE_VERSION = ${LIBUCONTEXT_VERSION}
DIST_NAME = ${PACKAGE_NAME}-${PACKAGE_VERSION}
DIST_TARBALL = ${DIST_NAME}.tar.xz
distcheck: check dist
dist: ${DIST_TARBALL}
${DIST_TARBALL}:
git archive --format=tar --prefix=${DIST_NAME}/ -o ${DIST_NAME}.tar ${DIST_NAME}
xz ${DIST_NAME}.tar
.PHONY: check dist