From 76c910e166d2b1887c5d355df4efec47ec0ce3bd Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Thu, 16 Sep 2021 18:10:26 +0200 Subject: Improve makefile, fix warnings, and fix libhaiku_perror linking MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- Makefile | 28 +++++++++++++++++++--------- config.mk | 4 +++- libhaiku.c | 8 +++++--- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index b22a6af..3ee1e78 100644 --- a/Makefile +++ b/Makefile @@ -16,21 +16,28 @@ LIB_VERSION = $(LIB_MAJOR).$(LIB_MINOR) MAN3 = libhaiku.7 MAN7 = libhaiku_generic.3 libhaiku_perror.3 libhaiku_perror2.3 libhaiku_strerror.3 +OBJ = libhaiku.o +HDR = libhaiku.h + +LOBJ = $(OBJ:.o=.lo) + all: libhaiku.a libhaiku.$(LIBEXT) +$(OBJ): $(HDR) +$(LOBJ): $(HDR) -libhaiku.o: libhaiku.c libhaiku.h - $(CC) -c -o $@ libhaiku.c $(CFLAGS) $(CPPFLAGS) +.c.o: + $(CC) -c -o $@ $< $(CFLAGS) $(CPPFLAGS) -libhaiku.lo: libhaiku.c libhaiku.h - $(CC) -fPIC -c -o $@ libhaiku.c $(CFLAGS) $(CPPFLAGS) +.c.lo: + $(CC) -fPIC -c -o $@ $< $(CFLAGS) $(CPPFLAGS) -libhaiku.$(LIBEXT): libhaiku.lo - $(CC) $(LIBFLAGS) -o $@ libhaiku.lo $(LDFLAGS) +libhaiku.$(LIBEXT): $(LOBJ) + $(CC) $(LIBFLAGS) -o $@ $(LOBJ) $(LDFLAGS) -libhaiku.a: libhaiku.o +libhaiku.a: $(OBJ) -rm -f -- $@ - $(AR) rc $@ libhaiku.o + $(AR) rc $@ $(OBJ) $(AR) -s $@ install: libhaiku.$(LIBEXT) libhaiku.a @@ -56,6 +63,9 @@ uninstall: -cd -- "$(DESTDIR)$(MANPREFIX)/man7/" && rm -rf -- $(MAN7) clean: - -rm -f -- *.o *.lo *.a *.su *.$(LIBEXT) *.$(LIBEXT).* *.*.$(LIBEXT) + -rm -f -- *.o *.lo *.a *.su *.$(LIBEXT) *.$(LIBEXT).* + +.SUFFIXES: +.SUFFIXES: .lo .o .c .PHONY: all install uninstall clean diff --git a/config.mk b/config.mk index c0709b5..f087ea4 100644 --- a/config.mk +++ b/config.mk @@ -1,6 +1,8 @@ PREFIX = /usr MANPREFIX = $(PREFIX)/share/man -CPPFLAGS = +CC = cc + +CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700 CFLAGS = -std=c99 -Wall -O2 LDFLAGS = -s diff --git a/libhaiku.c b/libhaiku.c index 04b94a9..870093a 100644 --- a/libhaiku.c +++ b/libhaiku.c @@ -31,12 +31,14 @@ static int random_int(int n) { static int initialised = 0; - double r, ri; + double r; + int ri; if (!initialised) { srand((unsigned)time(NULL)); initialised = 1; } - r = (double)rand() * (double)n / ((double)RAND_MAX + 1.0); + ri = rand(); + r = (double)ri * (double)n / ((double)RAND_MAX + (double)1); ri = ((int)r) % n; return ri < 0 ? (ri + n) : ri; } @@ -307,4 +309,4 @@ libhaiku_perror2(const char *prefix, int errnum) * @param prefix Unless `NULL` or empty, each line will be prefixed * by the specified string followed by a colon and a space */ -extern void libhaiku_perror(const char *prefix); +extern inline void libhaiku_perror(const char *prefix); -- cgit v1.2.3-70-g09d2