Skip to content

Commit 8d0d897

Browse files
committed
one shared lib
1 parent 6c415ce commit 8d0d897

File tree

2 files changed

+59
-51
lines changed

2 files changed

+59
-51
lines changed

beanstalk.h

Lines changed: 45 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -41,43 +41,60 @@ typedef struct bs_job {
4141
// fd: file descriptor of the socket
4242
typedef int (*bs_poll_function)(int rw, int fd);
4343

44+
/* Handle DSO symbol visibility - Stolen from zmq.h */
45+
#if defined _WIN32
46+
# if defined DLL_EXPORT
47+
# define BSC_EXPORT __declspec(dllexport)
48+
# else
49+
# define BSC_EXPORT __declspec(dllimport)
50+
# endif
51+
#else
52+
# if defined __SUNPRO_C || defined __SUNPRO_CC
53+
# define BSC_EXPORT __global
54+
# elif (defined __GNUC__ && __GNUC__ >= 4) || defined __INTEL_COMPILER
55+
# define BSC_EXPORT __attribute__ ((visibility("default")))
56+
# else
57+
# define BSC_EXPORT
58+
# endif
59+
#endif
60+
4461
// polling setup
45-
void bs_start_polling(bs_poll_function f);
46-
void bs_reset_polling(void);
62+
BSC_EXPORT void bs_start_polling(bs_poll_function f);
63+
BSC_EXPORT void bs_reset_polling(void);
4764

4865
// returns a descriptive text of the error code.
49-
const char* bs_status_text(int code);
66+
BSC_EXPORT const char* bs_status_text(int code);
5067

51-
void bs_free_message(BSM* m);
52-
void bs_free_job(BSJ *job);
68+
BSC_EXPORT void bs_free_message(BSM* m);
69+
BSC_EXPORT void bs_free_job(BSJ *job);
5370

5471
// returns socket descriptor or BS_STATUS_FAIL
55-
int bs_connect(char *host, int port);
72+
BSC_EXPORT int bs_connect(char *host, int port);
5673
// returns job id or one of the negative failure codes.
57-
int bs_put(int fd, int priority, int delay, int ttr, char *data, size_t bytes);
74+
BSC_EXPORT int bs_put(int fd, int priority, int delay, int ttr, char *data, size_t bytes);
5875

5976
// rest return BS_STATUS_OK or one of the failure codes.
60-
int bs_disconnect(int fd);
61-
int bs_use(int fd, char *tube);
62-
int bs_watch(int fd, char *tube);
63-
int bs_ignore(int fd, char *tube);
64-
int bs_delete(int fd, int job);
65-
int bs_reserve(int fd, BSJ **job);
66-
int bs_reserve_with_timeout(int fd, int ttl, BSJ **job);
67-
int bs_release(int fd, int id, int priority, int delay);
68-
int bs_bury(int fd, int id, int priority);
69-
int bs_touch(int fd, int id);
70-
int bs_peek(int fd, int id, BSJ **job);
71-
int bs_peek_ready(int fd, BSJ **job);
72-
int bs_peek_delayed(int fd, BSJ **job);
73-
int bs_peek_buried(int fd, BSJ **job);
74-
int bs_kick(int fd, int bound);
75-
int bs_list_tube_used(int fd, char **tube);
76-
int bs_list_tubes(int fd, char **yaml);
77-
int bs_list_tubes_watched(int fd, char **yaml);
78-
int bs_stats(int fd, char **yaml);
79-
int bs_stats_job(int fd, int id, char **yaml);
80-
int bs_stats_tube(int fd, char *tube, char **yaml);
77+
BSC_EXPORT int bs_disconnect(int fd);
78+
BSC_EXPORT int bs_use(int fd, char *tube);
79+
BSC_EXPORT int bs_watch(int fd, char *tube);
80+
BSC_EXPORT int bs_ignore(int fd, char *tube);
81+
BSC_EXPORT int bs_delete(int fd, int job);
82+
BSC_EXPORT int bs_reserve(int fd, BSJ **job);
83+
BSC_EXPORT int bs_reserve_with_timeout(int fd, int ttl, BSJ **job);
84+
BSC_EXPORT int bs_release(int fd, int id, int priority, int delay);
85+
BSC_EXPORT int bs_bury(int fd, int id, int priority);
86+
BSC_EXPORT int bs_touch(int fd, int id);
87+
BSC_EXPORT int bs_peek(int fd, int id, BSJ **job);
88+
BSC_EXPORT int bs_peek_ready(int fd, BSJ **job);
89+
BSC_EXPORT int bs_peek_delayed(int fd, BSJ **job);
90+
BSC_EXPORT int bs_peek_buried(int fd, BSJ **job);
91+
BSC_EXPORT int bs_kick(int fd, int bound);
92+
BSC_EXPORT int bs_list_tube_used(int fd, char **tube);
93+
BSC_EXPORT int bs_list_tubes(int fd, char **yaml);
94+
BSC_EXPORT int bs_list_tubes_watched(int fd, char **yaml);
95+
BSC_EXPORT int bs_stats(int fd, char **yaml);
96+
BSC_EXPORT int bs_stats_job(int fd, int id, char **yaml);
97+
BSC_EXPORT int bs_stats_tube(int fd, char *tube, char **yaml);
8198

8299
#ifdef __cplusplus
83100
}

makefile

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@ CEXAMPLES := $(SOURCES2:%.c=%)
66
CPPEXAMPLES := $(SOURCES3:%.cc=%)
77

88
VERSION = 1.0.0
9-
CSHAREDLIB = libbeanstalk.so
10-
CPPSHAREDLIB = libbeanstalkcpp.so
9+
SHAREDLIB = libbeanstalk.so
1110
CFLAGS = -Wall -g -I.
12-
CLDFLAGS = -L. -lbeanstalk
13-
CPPLDFLAGS = -L. -lbeanstalkcpp
11+
LDFLAGS = -L. -lbeanstalk
1412
CC = gcc
1513
CPP = g++
1614

@@ -19,51 +17,44 @@ all: $(CEXAMPLES) $(CPPEXAMPLES)
1917
test: $(TESTS)
2018
test/run-all
2119

22-
$(TESTS): test/%:test/%.o libbeanstalk.so
23-
$(CPP) -o $@ $< $(CLDFLAGS) -lgtest -lpthread
20+
$(TESTS): test/%:test/%.o $(SHAREDLIB)
21+
$(CPP) -o $@ $< $(LDFLAGS) -lgtest -lpthread
2422

2523
test/%.o: test/%.cc
2624
$(CPP) $(CFLAGS) -c -o $@ $<
2725

2826
$(CEXAMPLES): examples/c/%:examples/c/%.o libbeanstalk.so
29-
$(CC) -o $@ $< $(CLDFLAGS)
27+
$(CC) -o $@ $< $(LDFLAGS)
3028

3129
examples/c/%.o: examples/c/%.c
3230
$(CC) $(CFLAGS) -c -o $@ $<
3331

34-
$(CPPEXAMPLES): examples/cpp/%:examples/cpp/%.o libbeanstalkcpp.so
35-
$(CPP) -o $@ $< $(CPPLDFLAGS)
32+
$(CPPEXAMPLES): examples/cpp/%:examples/cpp/%.o libbeanstalk.so
33+
$(CPP) -o $@ $< $(LDFLAGS)
3634

3735
examples/cpp/%.o: examples/cpp/%.cc
3836
$(CPP) $(CFLAGS) -c -o $@ $<
3937

40-
$(CSHAREDLIB): beanstalk.o
41-
$(CC) -shared -o $(CSHAREDLIB) beanstalk.o
38+
$(SHAREDLIB): beanstalk.o beanstalkcpp.o
39+
$(CPP) -shared -o $(SHAREDLIB) beanstalk.o beanstalkcpp.o
4240

4341
beanstalk.o: beanstalk.c beanstalk.h makefile
4442
$(CC) $(CFLAGS) -fPIC -c -o beanstalk.o beanstalk.c
4543

46-
$(CPPSHAREDLIB): beanstalkcpp.o beanstalk.o
47-
$(CPP) -shared -o $(CPPSHAREDLIB) beanstalkcpp.o beanstalk.o
48-
4944
beanstalkcpp.o: beanstalk.cc beanstalk.hpp makefile
5045
$(CPP) $(CFLAGS) -fPIC -c -o beanstalkcpp.o beanstalk.cc
5146

52-
install: $(CSHAREDLIB) $(CPPSHAREDLIB)
47+
install: $(SHAREDLIB)
5348
cp beanstalk.h /usr/include
5449
cp beanstalk.hpp /usr/include
55-
cp $(CSHAREDLIB) /usr/lib/$(CSHAREDLIB).$(VERSION)
56-
ln -sfT /usr/lib/$(CSHAREDLIB).$(VERSION) /usr/lib/$(CSHAREDLIB).1
57-
ln -sfT /usr/lib/$(CSHAREDLIB).$(VERSION) /usr/lib/$(CSHAREDLIB)
58-
cp $(CPPSHAREDLIB) /usr/lib/$(CPPSHAREDLIB).$(VERSION)
59-
ln -sfT /usr/lib/$(CPPSHAREDLIB).$(VERSION) /usr/lib/$(CPPSHAREDLIB).1
60-
ln -sfT /usr/lib/$(CPPSHAREDLIB).$(VERSION) /usr/lib/$(CPPSHAREDLIB)
50+
cp $(SHAREDLIB) /usr/lib/$(SHAREDLIB).$(VERSION)
51+
ln -sfT /usr/lib/$(SHAREDLIB).$(VERSION) /usr/lib/$(SHAREDLIB).1
52+
ln -sfT /usr/lib/$(SHAREDLIB).$(VERSION) /usr/lib/$(SHAREDLIB)
6153

6254
uninstall:
6355
rm -f /usr/include/beanstalk.h
6456
rm -f /usr/include/beanstalk.hpp
65-
rm -f /usr/lib/$(CSHAREDLIB)*
66-
rm -f /usr/lib/$(CPPSHAREDLIB)*
57+
rm -f /usr/lib/$(SHAREDLIB)*
6758

6859
clean:
6960
rm -f *.o *.so *.so.* test/test[0-9] test/*.o examples/**/*.o examples/**/example?

0 commit comments

Comments
 (0)