dsys2

changeset 13:6bab2c0b0e4b

- added a shared library rule - changed all the names from dsys2 to dsys
author John Tsiombikas <nuclear@mutantstargoat.com>
date Mon, 05 Sep 2011 04:08:40 +0300
parents d7d173fcd44e
children 66d4fe7a8613
files Makefile src/dsys.c src/dsys.h src/dsys2.h src/dsys_impl.h
diffstat 5 files changed, 101 insertions(+), 79 deletions(-) [+]
line diff
     1.1 --- a/Makefile	Mon Sep 05 03:05:24 2011 +0300
     1.2 +++ b/Makefile	Mon Sep 05 04:08:40 2011 +0300
     1.3 @@ -4,11 +4,29 @@
     1.4  obj = $(src:.c=.o)
     1.5  dep = $(obj:.o=.d)
     1.6  
     1.7 -lib_a = libdsys2.a
     1.8 +lib_a = libdsys.a
     1.9 +soname = libdsys.so.$(somajor)
    1.10 +lib_so = $(lib_so_$(sys))
    1.11 +
    1.12 +somajor = 0
    1.13 +sominor = 0
    1.14 +
    1.15 +lib_so_unix = $(soname).$(sominor)
    1.16 +lib_so_mac = libdsys.dylib
    1.17 +
    1.18 +sharedopt_unix = -shared -Wl,-soname,$(soname)
    1.19 +sharedopt_mac = -dynamiclib
    1.20 +
    1.21 +ifeq ($(shell uname -s), Darwin)
    1.22 +	sys = mac
    1.23 +else
    1.24 +	sys = unix
    1.25 +endif
    1.26 +
    1.27  
    1.28  CC = gcc
    1.29  AR = ar
    1.30 -CFLAGS = -pedantic -Wall -g -Isrc
    1.31 +CFLAGS = -pedantic -Wall -g -Isrc -fPIC
    1.32  
    1.33  ifeq ($(shell uname -s), Darwin)
    1.34  	libgl = -framework OpenGL -framework GLUT
    1.35 @@ -16,12 +34,15 @@
    1.36  	libgl = -lGL -lGLU -lglut
    1.37  endif
    1.38  
    1.39 -test: test.o $(lib_a)
    1.40 +test: test.o $(lib_a) $(lib_so)
    1.41  	$(CC) $(CFLAGS) -o $@ test.o $(lib_a) $(libgl) -lm
    1.42  
    1.43  $(lib_a): $(obj)
    1.44  	$(AR) rcs $@ $(obj)
    1.45  
    1.46 +$(lib_so): $(obj)
    1.47 +	$(CC) $(sharedopt_$(sys)) -o $@ $(obj) $(LDFLAGS)
    1.48 +
    1.49  -include $(dep)
    1.50  
    1.51  %.d: %.c
    1.52 @@ -29,7 +50,7 @@
    1.53  
    1.54  .PHONY: clean
    1.55  clean:
    1.56 -	rm -f $(obj) $(bin)
    1.57 +	rm -f $(obj) $(bin) $(lib_a) $(lib_so)
    1.58  
    1.59  .PHONY: cleandep
    1.60  cleandep:
    1.61 @@ -39,8 +60,9 @@
    1.62  install: $(lib_a)
    1.63  	mkdir -p $(PREFIX)/include $(PREFIX)/lib
    1.64  	cp $(lib_a) $(PREFIX)/lib/$(lib_a)
    1.65 -	cp src/dsys2.h $(PREFIX)/include/dsys2.h
    1.66 +	cp $(lib_so) $(PREFIX)/lib/$(lib_so)
    1.67 +	cp src/dsys.h $(PREFIX)/include/dsys.h
    1.68  
    1.69  .PHONY: uninstall
    1.70  uninstall:
    1.71 -	rm -f $(PREFIX)/include/dsys2.h $(PREFIX)/lib/$(lib_a)
    1.72 +	rm -f $(PREFIX)/include/dsys.h $(PREFIX)/lib/$(lib_a) $(PREFIX)/lib/$(lib_so)
     2.1 --- a/src/dsys.c	Mon Sep 05 03:05:24 2011 +0300
     2.2 +++ b/src/dsys.c	Mon Sep 05 04:08:40 2011 +0300
     2.3 @@ -4,7 +4,7 @@
     2.4  #include <string.h>
     2.5  #include <ctype.h>
     2.6  #include <errno.h>
     2.7 -#include "dsys2.h"
     2.8 +#include "dsys.h"
     2.9  #include "dsys_impl.h"
    2.10  
    2.11  static int read_script(struct dsys_demo *demo, FILE *fp, const char *fname);
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/dsys.h	Mon Sep 05 04:08:40 2011 +0300
     3.3 @@ -0,0 +1,71 @@
     3.4 +#ifndef DSYS2_H_
     3.5 +#define DSYS2_H_
     3.6 +
     3.7 +#include <stdio.h>
     3.8 +
     3.9 +struct dsys_demo;
    3.10 +struct dsys_event;
    3.11 +
    3.12 +typedef float demotime_t;
    3.13 +
    3.14 +enum dsys_evtype {
    3.15 +	DSYS_SINGLE,
    3.16 +	DSYS_PERIODIC
    3.17 +};
    3.18 +
    3.19 +#ifdef __cplusplus
    3.20 +extern "C" {
    3.21 +#endif
    3.22 +
    3.23 +struct dsys_demo *dsys_open(const char *fname);
    3.24 +struct dsys_demo *dsys_open_stream(FILE *fp);
    3.25 +void dsys_close(struct dsys_demo *demo);
    3.26 +
    3.27 +void dsys_update(struct dsys_demo *demo, demotime_t tm);
    3.28 +
    3.29 +
    3.30 +void dsys_start(struct dsys_demo *demo);
    3.31 +void dsys_stop(struct dsys_demo *demo);
    3.32 +int dsys_is_running(struct dsys_demo *demo);
    3.33 +
    3.34 +
    3.35 +demotime_t dsys_duration(struct dsys_demo *demo);
    3.36 +demotime_t dsys_time(struct dsys_demo *demo);
    3.37 +float dsys_progress(struct dsys_demo *demo);
    3.38 +
    3.39 +/* seek without continuity */
    3.40 +void dsys_seek(struct dsys_demo *demo, demotime_t tm);
    3.41 +void dsys_seek_norm(struct dsys_demo *demo, float t);
    3.42 +
    3.43 +/* seek by accelerating time */
    3.44 +void dsys_warp(struct dsys_demo *demo, demotime_t tm);
    3.45 +void dsys_warp_norm(struct dsys_demo *demo, float t);
    3.46 +
    3.47 +
    3.48 +/* events */
    3.49 +struct dsys_event *dsys_event(struct dsys_demo *demo, const char *name);
    3.50 +
    3.51 +enum dsys_evtype dsys_event_type(struct dsys_event *ev);
    3.52 +float dsys_event_value(struct dsys_event *ev);
    3.53 +
    3.54 +int dsys_event_callback(struct dsys_event *ev, void (*func)(struct dsys_event*, void*), void *cls);
    3.55 +int dsys_event_link(struct dsys_event *ev, float *link);
    3.56 +
    3.57 +/* event evaluators */
    3.58 +float dsys_eval_step(struct dsys_event *ev, demotime_t t);
    3.59 +float dsys_eval_lerp(struct dsys_event *ev, demotime_t t);
    3.60 +float dsys_eval_sigmoid(struct dsys_event *ev, demotime_t t);
    3.61 +
    3.62 +/* time conversion */
    3.63 +demotime_t dsys_sec_to_dtime(float sec);
    3.64 +demotime_t dsys_msec_to_dtime(unsigned long msec);
    3.65 +
    3.66 +float dsys_dtime_to_sec(demotime_t tm);
    3.67 +unsigned long dsys_dtime_to_msec(demotime_t tm);
    3.68 +
    3.69 +#ifdef __cplusplus
    3.70 +}
    3.71 +#endif
    3.72 +
    3.73 +
    3.74 +#endif	/* DSYS2_H_ */
     4.1 --- a/src/dsys2.h	Mon Sep 05 03:05:24 2011 +0300
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,71 +0,0 @@
     4.4 -#ifndef DSYS2_H_
     4.5 -#define DSYS2_H_
     4.6 -
     4.7 -#include <stdio.h>
     4.8 -
     4.9 -struct dsys_demo;
    4.10 -struct dsys_event;
    4.11 -
    4.12 -typedef float demotime_t;
    4.13 -
    4.14 -enum dsys_evtype {
    4.15 -	DSYS_SINGLE,
    4.16 -	DSYS_PERIODIC
    4.17 -};
    4.18 -
    4.19 -#ifdef __cplusplus
    4.20 -extern "C" {
    4.21 -#endif
    4.22 -
    4.23 -struct dsys_demo *dsys_open(const char *fname);
    4.24 -struct dsys_demo *dsys_open_stream(FILE *fp);
    4.25 -void dsys_close(struct dsys_demo *demo);
    4.26 -
    4.27 -void dsys_update(struct dsys_demo *demo, demotime_t tm);
    4.28 -
    4.29 -
    4.30 -void dsys_start(struct dsys_demo *demo);
    4.31 -void dsys_stop(struct dsys_demo *demo);
    4.32 -int dsys_is_running(struct dsys_demo *demo);
    4.33 -
    4.34 -
    4.35 -demotime_t dsys_duration(struct dsys_demo *demo);
    4.36 -demotime_t dsys_time(struct dsys_demo *demo);
    4.37 -float dsys_progress(struct dsys_demo *demo);
    4.38 -
    4.39 -/* seek without continuity */
    4.40 -void dsys_seek(struct dsys_demo *demo, demotime_t tm);
    4.41 -void dsys_seek_norm(struct dsys_demo *demo, float t);
    4.42 -
    4.43 -/* seek by accelerating time */
    4.44 -void dsys_warp(struct dsys_demo *demo, demotime_t tm);
    4.45 -void dsys_warp_norm(struct dsys_demo *demo, float t);
    4.46 -
    4.47 -
    4.48 -/* events */
    4.49 -struct dsys_event *dsys_event(struct dsys_demo *demo, const char *name);
    4.50 -
    4.51 -enum dsys_evtype dsys_event_type(struct dsys_event *ev);
    4.52 -float dsys_event_value(struct dsys_event *ev);
    4.53 -
    4.54 -int dsys_event_callback(struct dsys_event *ev, void (*func)(struct dsys_event*, void*), void *cls);
    4.55 -int dsys_event_link(struct dsys_event *ev, float *link);
    4.56 -
    4.57 -/* event evaluators */
    4.58 -float dsys_eval_step(struct dsys_event *ev, demotime_t t);
    4.59 -float dsys_eval_lerp(struct dsys_event *ev, demotime_t t);
    4.60 -float dsys_eval_sigmoid(struct dsys_event *ev, demotime_t t);
    4.61 -
    4.62 -/* time conversion */
    4.63 -demotime_t dsys_sec_to_dtime(float sec);
    4.64 -demotime_t dsys_msec_to_dtime(unsigned long msec);
    4.65 -
    4.66 -float dsys_dtime_to_sec(demotime_t tm);
    4.67 -unsigned long dsys_dtime_to_msec(demotime_t tm);
    4.68 -
    4.69 -#ifdef __cplusplus
    4.70 -}
    4.71 -#endif
    4.72 -
    4.73 -
    4.74 -#endif	/* DSYS2_H_ */
     5.1 --- a/src/dsys_impl.h	Mon Sep 05 03:05:24 2011 +0300
     5.2 +++ b/src/dsys_impl.h	Mon Sep 05 04:08:40 2011 +0300
     5.3 @@ -1,7 +1,7 @@
     5.4  #ifndef DSYS_IMPL_H_
     5.5  #define DSYS_IMPL_H_
     5.6  
     5.7 -#include "dsys2.h"
     5.8 +#include "dsys.h"
     5.9  
    5.10  struct dsys_demo {
    5.11  	demotime_t tm, src_tm, start_tm, stop_tm, duration;