diff options
Diffstat (limited to '')
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | Makefile | 62 | ||||
-rw-r--r-- | blackbody.c | 22 | ||||
-rw-r--r-- | config.mk | 4 | ||||
-rw-r--r-- | generate-table.c | 5 | ||||
-rw-r--r-- | libred.h | 1 | ||||
-rw-r--r-- | mk/linux.mk | 4 | ||||
-rw-r--r-- | mk/macos.mk | 4 | ||||
-rw-r--r-- | mk/windows.mk | 4 | ||||
-rw-r--r-- | solar.c | 3 |
10 files changed, 75 insertions, 36 deletions
@@ -5,5 +5,7 @@ *.i *.su *.so +*.dll +*.dylib *.lo /generate-table @@ -1,47 +1,65 @@ .POSIX: +LIB_MAJOR = 1 +LIB_MINOR = 0 +LIB_VERSION = $(LIB_MAJOR).$(LIB_MINOR) + + CONFIGFILE = config.mk include $(CONFIGFILE) -VERSION_MAJOR = 1 -VERSION = 1.0 +OS = linux +# Linux: linux +# Mac OS: macos +# Windows: windows +include mk/$(OS).mk + + +OBJ =\ + solar.o\ + blackbody.o -all: libred.a libred.so -solar.o: solar.c libred.h -blackbody.o: blackbody.c 10deg-xy.i 10deg-rgb.i libred.h +LOBJ = $(OBJ:.o=.lo) + + +all: libred.a libred.$(LIBEXT) +solar.o: libred.h +blackbody.o: 10deg-xy.i 10deg-rgb.i libred.h +generate-table.o: blackbody.c 10deg-xy.i libred.h 10deg-xy.i: 10deg sed -e 's/^/{/' -e 's/ /, /' -e 's/$$/},/' < 10deg | sed '$$s/,$$//' > $@ -generate-table: generate-table.c blackbody.c 10deg-xy.i libred.h - $(CC) -o $@ generate-table.c $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) - 10deg-rgb.i: generate-table 10deg ./generate-table > $@ +.o: + $(CC) -o $@ $< $(LDFLAGS) + .c.o: - $(CC) -c -o $@ $< $(CPPFLAGS) $(CFLAGS) + $(CC) -c -o $@ $< $(CFLAGS) $(CPPFLAGS) .c.lo: - $(CC) -fPIC -c -o $@ $< $(CPPFLAGS) $(CFLAGS) + $(CC) -fPIC -c -o $@ $< $(CFLAGS) $(CPPFLAGS) -libred.a: solar.o blackbody.o - $(AR) rc $@ $? +libred.a: $(OBJ) + -@rm -f -- $@ + $(AR) rc $@ $(OBJ) $(AR) s $@ -libred.so: solar.lo blackbody.lo - $(CC) -shared -Wl,-soname,libred.so.$(VERSION_MAJOR) -o $@ $(LDFLAGS) solar.lo blackbody.lo +libred.$(LIBEXT): $(LOBJ) + $(CC) $(LIBFLAGS) -o $@ $(LOBJ) $(LDFLAGS) -install: libred.a libred.so +install: libred.a libred.$(LIBEXT) mkdir -p -- "$(DESTDIR)$(PREFIX)/lib" mkdir -p -- "$(DESTDIR)$(PREFIX)/include" mkdir -p -- "$(DESTDIR)$(MANPREFIX)/man0" mkdir -p -- "$(DESTDIR)$(MANPREFIX)/man3" mkdir -p -- "$(DESTDIR)$(MANPREFIX)/man7" cp -- libred.a "$(DESTDIR)$(PREFIX)/lib" - cp -- libred.so "$(DESTDIR)$(PREFIX)/lib/libred.so.$(VERSION_MAJOR)" - ln -sf -- libred.so.$(VERSION_MAJOR) "$(DESTDIR)$(PREFIX)/lib/libred.so.$(VERSION)" - ln -sf -- libred.so.$(VERSION_MAJOR) "$(DESTDIR)$(PREFIX)/lib/libred.so" + cp -- libred.$(LIBEXT) "$(DESTDIR)$(PREFIX)/lib/libred.$(LIBMINOREXT)" + ln -sf -- libred.$(LIBMINOREXT) "$(DESTDIR)$(PREFIX)/lib/libred.$(LIBMAJOREXT)" + ln -sf -- libred.$(LIBMAJOREXT) "$(DESTDIR)$(PREFIX)/lib/libred.$(LIBEXT)" cp -- libred.h "$(DESTDIR)$(PREFIX)/include" cp -- libred.h.0 "$(DESTDIR)$(MANPREFIX)/man0" cp -- libred_check_timetravel.3 libred_get_colour.3 libred_solar_elevation.3 "$(DESTDIR)$(MANPREFIX)/man3" @@ -49,9 +67,9 @@ install: libred.a libred.so uninstall: -rm -f -- "$(DESTDIR)$(PREFIX)/lib/libred.a" - -rm -f -- "$(DESTDIR)$(PREFIX)/lib/libred.so.$(VERSION_MAJOR)" - -rm -f -- "$(DESTDIR)$(PREFIX)/lib/libred.so.$(VERSION)" - -rm -f -- "$(DESTDIR)$(PREFIX)/lib/libred.so" + -rm -f -- "$(DESTDIR)$(PREFIX)/lib/libred.$(LIBMAJOREXT)" + -rm -f -- "$(DESTDIR)$(PREFIX)/lib/libred.$(LIBMINOREXT)" + -rm -f -- "$(DESTDIR)$(PREFIX)/lib/libred.$(LIBEXT)" -rm -f -- "$(DESTDIR)$(PREFIX)/include/libred.h" -rm -f -- "$(DESTDIR)$(MANPREFIX)/man0/libred.h.0" -rm -f -- "$(DESTDIR)$(MANPREFIX)/man3/libred_check_timetravel.3" @@ -60,7 +78,7 @@ uninstall: -rm -f -- "$(DESTDIR)$(MANPREFIX)/man7/libred.7" clean: - -rm -f -- generate-table *.i *.o *.a *.lo *.su *.so + -rm -f -- generate-table *.i *.o *.a *.lo *.su *.so *.dll *.dylib .SUFFIXES: .SUFFIXES: .c .o .lo diff --git a/blackbody.c b/blackbody.c index e654c9d..6edc85a 100644 --- a/blackbody.c +++ b/blackbody.c @@ -1,28 +1,28 @@ /* See LICENSE file for copyright and license details. */ -#if __GNUC__ +#if defined(__GNUC__) # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Wunsuffixed-float-constants" #endif #ifndef LIBRED_COMPILING_PARSER -#include "libred.h" -#include <errno.h> -#include <math.h> -#include <stddef.h> +# include "libred.h" +# include <errno.h> +# include <math.h> +# include <stddef.h> /** * Colour temperatures in CIE xy (xyY without Y) */ static struct xy {double x, y;} xy_table[] = { -#include "10deg-xy.i" +# include "10deg-xy.i" }; /** * Colour temperatures in sRGB */ static struct rgb {double r, g, b;} rgb_table[] = { -#include "10deg-rgb.i" +# include "10deg-rgb.i" }; @@ -145,6 +145,7 @@ libred_get_colour(long int temp, double *r, double *g, double *b) { double x1, y1, x2, y2; size_t i; + long int tmp; if (temp > LIBRED_HIGHEST_TEMPERATURE) temp = LIBRED_HIGHEST_TEMPERATURE; @@ -154,15 +155,16 @@ libred_get_colour(long int temp, double *r, double *g, double *b) return -1; } - if (temp % LIBRED_DELTA_TEMPERATURE) { - i = (temp - LIBRED_LOWEST_TEMPERATURE) / LIBRED_DELTA_TEMPERATURE; + tmp = temp - LIBRED_LOWEST_TEMPERATURE; + + i = (size_t)(tmp / LIBRED_DELTA_TEMPERATURE); + if (tmp % LIBRED_DELTA_TEMPERATURE) { x1 = xy_table[i].x; y1 = xy_table[i].y; x2 = xy_table[i + 1].x; y2 = xy_table[i + 1].y; interpolate(x1, y1, x2, y2, (double)temp, r, g, b); } else { - i = (temp - LIBRED_LOWEST_TEMPERATURE) / LIBRED_DELTA_TEMPERATURE; *r = rgb_table[i].r; *g = rgb_table[i].g; *b = rgb_table[i].b; @@ -1,6 +1,8 @@ -PREFIX = /usr +PREFIX = /usr MANPREFIX = $(PREFIX)/share/man +CC = cc + CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700 -D_GNU_SOURCE CFLAGS = -std=c99 -Wall -O2 LDFLAGS = -lm -s diff --git a/generate-table.c b/generate-table.c index 7be406f..c5c0ca3 100644 --- a/generate-table.c +++ b/generate-table.c @@ -5,10 +5,12 @@ #include <string.h> #include <stdio.h> -#if __GNUC__ +#if defined(__GNUC__) # pragma GCC diagnostic ignored "-Wfloat-equal" +# pragma GCC diagnostic ignored "-Wunsuffixed-float-constants" #endif + /** * Colour temperatures in CIE xy (xyY without Y) */ @@ -20,6 +22,7 @@ static struct xy {double x, y;} xy_table[] = { #define LIBRED_COMPILING_PARSER #include "blackbody.c" + int main(void) { @@ -214,4 +214,3 @@ int libred_get_colour(long int, double *, double *, double *); #endif - diff --git a/mk/linux.mk b/mk/linux.mk new file mode 100644 index 0000000..c180f9b --- /dev/null +++ b/mk/linux.mk @@ -0,0 +1,4 @@ +LIBEXT = so +LIBFLAGS = -shared -Wl,-soname,libred.$(LIBEXT).$(LIB_MAJOR) +LIBMAJOREXT = $(LIBEXT).$(LIB_MAJOR) +LIBMINOREXT = $(LIBEXT).$(LIB_VERSION) diff --git a/mk/macos.mk b/mk/macos.mk new file mode 100644 index 0000000..bd92de6 --- /dev/null +++ b/mk/macos.mk @@ -0,0 +1,4 @@ +LIBEXT = dylib +LIBFLAGS = -dynamiclib +LIBMAJOREXT = $(LIB_MAJOR).$(LIBEXT) +LIBMINOREXT = $(LIB_VERSION).$(LIBEXT) diff --git a/mk/windows.mk b/mk/windows.mk new file mode 100644 index 0000000..e9602e1 --- /dev/null +++ b/mk/windows.mk @@ -0,0 +1,4 @@ +LIBEXT = dll +LIBFLAGS = -mdll +LIBMAJOREXT = $(LIB_MAJOR).$(LIBEXT) +LIBMINOREXT = $(LIB_VERSION).$(LIBEXT) @@ -19,6 +19,7 @@ # define CLOCK_REALTIME_COARSE CLOCK_REALTIME #endif + /** * Get current Julian Centuries time (100 Julian days since J2000) * @@ -26,7 +27,7 @@ * @return 0 on success, -1 on failure * @throws Any error specified for clock_gettime(3) on error */ -static double +static int julian_centuries(double *nowp) { struct timespec now; |