aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--Makefile49
-rw-r--r--config.mk2
-rw-r--r--mk/linux.mk6
-rw-r--r--mk/macos.mk6
-rw-r--r--mk/windows.mk6
-rw-r--r--strtoi64.c6
6 files changed, 61 insertions, 14 deletions
diff --git a/Makefile b/Makefile
index 6976479..5d45bc4 100644
--- a/Makefile
+++ b/Makefile
@@ -3,6 +3,19 @@
CONFIGFILE = config.mk
include $(CONFIGFILE)
+OS = linux
+# Linux: linux
+# Mac OS: macos
+# Windows: windows
+include mk/$(OS).mk
+
+
+LIB_MAJOR = 1
+LIB_MINOR = 0
+LIB_VERSION = $(LIB_MAJOR).$(LIB_MINOR)
+LIB_NAME = simple
+
+
SUBHDR =\
libsimple/aligned_alloc.h\
libsimple/aligned_allocz.h\
@@ -449,52 +462,68 @@ MAN3 =\
TESTS = $(OBJ:.o=.test) libsimple-arg.test
-all: libsimple.a $(TESTS)
+LOBJ = $(OBJ:.o=.lo)
+
+all: libsimple.a libsimple.$(LIBEXT) $(TESTS)
tests: $(TESTS)
$(OBJ): $(HDR)
$(TESTS): test.o libsimple.a
$(TESTS:.test=.to): $(HDR) test.h
test.o: test.c $(HDR) test.h
- $(CC) -c -o $@ test.c $(CFLAGS) -DTEST -O0 -ffreestanding
+ $(CC) -c -o $@ test.c $(CFLAGS) $(CPPFLAGS) -DTEST -O0 -ffreestanding
libsimple.a: $(OBJ)
@rm -f -- $@
$(AR) rc $@ $(OBJ)
$(AR) -s $@
+libsimple.$(LIBEXT): $(LOBJ)
+ $(CC) $(LIBFLAGS) -o $@ $(LOBJ) $(LDFLAGS)
+
.to.test:
$(CC) -o $@ $< test.o libsimple.a $(LDFLAGS)
.c.to:
- $(CC) -c -o $@ $< $(CFLAGS) -DTEST -O0
+ $(CC) -c -o $@ $< $(CFLAGS) $(CPPFLAGS) -DTEST -O0
+
+.c.o:
+ $(CC) -c -o $@ $< $(CFLAGS) $(CPPFLAGS)
+
+.c.lo:
+ $(CC) -fPIC -c -o $@ $< $(CFLAGS) $(CPPFLAGS)
check: $(TESTS)
@set -e; for t in $(TESTS); do printf '%s\n' "./$$t"; $(CHECK_PREFIX) "./$$t"; done
-install: libsimple.a
+install: libsimple.a libsimple.$(LIBEXT)
mkdir -p -- "$(DESTDIR)$(PREFIX)/lib"
mkdir -p -- "$(DESTDIR)$(PREFIX)/include/libsimple"
- mkdir -p -- "$(DESTDIR)$(PREFIX)/share/man/man0"
- mkdir -p -- "$(DESTDIR)$(PREFIX)/share/man/man3"
+ mkdir -p -- "$(DESTDIR)$(MANPREFIX)/man0"
+ mkdir -p -- "$(DESTDIR)$(MANPREFIX)/man3"
cp -- libsimple.a "$(DESTDIR)$(PREFIX)/lib"
+ cp -- libsimple.$(LIBEXT) "$(DESTDIR)$(PREFIX)/lib/libsimple.$(LIBMINOREXT)"
+ $(FIX_INSTALL_NAME) "$(DESTDIR)$(PREFIX)/lib/libsimple.$(LIBMINOREXT)"
+ ln -sf -- libsimple.$(LIBMINOREXT) "$(DESTDIR)$(PREFIX)/lib/libsimple.$(LIBMAJOREXT)"
+ ln -sf -- libsimple.$(LIBMAJOREXT) "$(DESTDIR)$(PREFIX)/lib/libsimple.$(LIBEXT)"
cp -- libsimple.h "$(DESTDIR)$(PREFIX)/include"
cp -- libsimple-arg.h "$(DESTDIR)$(PREFIX)/include"
cp -- $(SUBHDR) "$(DESTDIR)$(PREFIX)/include/libsimple"
- cp -- $(MAN0) "$(DESTDIR)$(PREFIX)/share/man/man0"
- cp -P -- $(MAN3) "$(DESTDIR)$(PREFIX)/share/man/man3"
+ cp -P -- $(MAN0) "$(DESTDIR)$(MANPREFIX)/man0"
+ cp -P -- $(MAN3) "$(DESTDIR)$(MANPREFIX)/man3"
uninstall:
-rm -f -- "$(DESTDIR)$(PREFIX)/lib/libsimple.a"
-rm -f -- "$(DESTDIR)$(PREFIX)/include/libsimple.h"
-rm -f -- "$(DESTDIR)$(PREFIX)/include/libsimple-arg.h"
-rm -rf -- "$(DESTDIR)$(PREFIX)/include/libsimple"
- -cd -- "$(DESTDIR)$(PREFIX)/share/man" && rm -f -- $(MAN0) $(MAN3)
+ -cd -- "$(DESTDIR)$(MANPREFIX)/man0" && rm -f -- $(MAN0)
+ -cd -- "$(DESTDIR)$(MANPREFIX)/man3" && rm -f -- $(MAN3)
clean:
-rm -rf -- *.o *.su *.a *.so *.so.* *.gch *.gcda *.gcno *.gcov *.lo *.test *.to
.SUFFIXES:
-.SUFFIXES: .test .to .o .c
+.SUFFIXES: .test .to .lo .o .c
.PHONY: all check install uninstall clean
diff --git a/config.mk b/config.mk
index 605a704..c9919fd 100644
--- a/config.mk
+++ b/config.mk
@@ -4,5 +4,5 @@ MANPREFIX = $(PREFIX)/share/man
CC = cc
CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700
-CFLAGS = -std=c11 -Wall -Wextra -O2 $(CPPFLAGS)
+CFLAGS = -std=c11 -Wall -Wextra -O2
LDFLAGS = -s
diff --git a/mk/linux.mk b/mk/linux.mk
new file mode 100644
index 0000000..ad58f69
--- /dev/null
+++ b/mk/linux.mk
@@ -0,0 +1,6 @@
+LIBEXT = so
+LIBFLAGS = -shared -Wl,-soname,lib$(LIB_NAME).$(LIBEXT).$(LIB_MAJOR)
+LIBMAJOREXT = $(LIBEXT).$(LIB_MAJOR)
+LIBMINOREXT = $(LIBEXT).$(LIB_VERSION)
+
+FIX_INSTALL_NAME = :
diff --git a/mk/macos.mk b/mk/macos.mk
new file mode 100644
index 0000000..00e8236
--- /dev/null
+++ b/mk/macos.mk
@@ -0,0 +1,6 @@
+LIBEXT = dylib
+LIBFLAGS = -dynamiclib -Wl,-compatibility_version,$(LIB_MAJOR) -Wl,-current_version,$(LIB_VERSION)
+LIBMAJOREXT = $(LIB_MAJOR).$(LIBEXT)
+LIBMINOREXT = $(LIB_VERSION).$(LIBEXT)
+
+FIX_INSTALL_NAME = install_name_tool -id "$(PREFIX)/lib/lib$(LIB_NAME).$(LIBMAJOREXT)"
diff --git a/mk/windows.mk b/mk/windows.mk
new file mode 100644
index 0000000..ed5ec8d
--- /dev/null
+++ b/mk/windows.mk
@@ -0,0 +1,6 @@
+LIBEXT = dll
+LIBFLAGS = -shared
+LIBMAJOREXT = $(LIB_MAJOR).$(LIBEXT)
+LIBMINOREXT = $(LIB_VERSION).$(LIBEXT)
+
+FIX_INSTALL_NAME = :
diff --git a/strtoi64.c b/strtoi64.c
index d34940c..6e0a898 100644
--- a/strtoi64.c
+++ b/strtoi64.c
@@ -6,8 +6,8 @@
#define RET_MIN (-RET_MAX - 1LL)
-int_least32_t
-libsimple_strtoi32(const char *restrict nptr, char **restrict end, int base) /* TODO test, man */
+int_least64_t
+libsimple_strtoi64(const char *restrict nptr, char **restrict end, int base) /* TODO test, man */
{
intmax_t r = strtoimax(nptr, end, base);
if(r < RET_MIN) {
@@ -17,7 +17,7 @@ libsimple_strtoi32(const char *restrict nptr, char **restrict end, int base) /*
r = RET_MAX;
errno = ERANGE;
}
- return (int_least32_t)r;
+ return (int_least64_t)r;
}