Skip to content

Commit 6203f43

Browse files
committed
Better crosscompilation handling
1 parent 61961e1 commit 6203f43

9 files changed

Lines changed: 264 additions & 112 deletions

File tree

JavaGUI/jni/include/TSDRLibrary.h

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,32 @@
11
#ifndef _TSDRLibrary
22
#define _TSDRLibrary
33

4+
#if defined _WIN32 || defined __CYGWIN__
5+
#ifdef BUILDING_STATIC
6+
#ifdef __GNUC__
7+
#define TSDR_PUBLIC __attribute__ ((dllimport))
8+
#else
9+
#define TSDR_PUBLIC __declspec(dllimport) // Note: actually gcc seems to also supports this syntax.
10+
#endif
11+
#else
12+
#ifdef __GNUC__
13+
#define TSDR_PUBLIC __attribute__ ((dllexport))
14+
#else
15+
#define TSDR_PUBLIC __declspec(dllexport) // Note: actually gcc seems to also supports this syntax.
16+
#endif
17+
#endif
18+
#define TSDR_LOCAL
19+
#else
20+
#if __GNUC__ >= 4
21+
#define TSDR_PUBLIC __attribute__ ((visibility ("default")))
22+
#define TSDR_LOCAL __attribute__ ((visibility ("hidden")))
23+
#else
24+
#define TSDR_PUBLIC
25+
#define TSDR_LOCAL
26+
#endif
27+
#endif
28+
29+
430
#include <stdint.h>
531

632
#define DIRECTION_CUSTOM (0)
@@ -33,17 +59,17 @@
3359

3460
typedef void(*tsdr_readasync_function)(float *buf, int width, int height, void *ctx);
3561

36-
void tsdr_init(tsdr_lib_t * tsdr);
37-
int tsdr_setsamplerate(tsdr_lib_t * tsdr, uint32_t rate);
38-
int tsdr_setbasefreq(tsdr_lib_t * tsdr, uint32_t freq);
39-
int tsdr_stop(tsdr_lib_t * tsdr);
40-
int tsdr_setgain(tsdr_lib_t * tsdr, float gain);
41-
int tsdr_readasync(tsdr_lib_t * tsdr, const char * pluginfilepath, tsdr_readasync_function cb, void *, const char * params);
42-
int tsdr_unloadplugin(tsdr_lib_t * tsdr);
43-
int tsdr_setresolution(tsdr_lib_t * tsdr, int width, int height, double refreshrate);
44-
int tsdr_isrunning(tsdr_lib_t * tsdr);
45-
int tsdr_sync(tsdr_lib_t * tsdr, int pixels, int direction);
46-
int tsdr_motionblur(tsdr_lib_t * tsdr, float coeff);
47-
char * tsdr_getlasterrortext(tsdr_lib_t * tsdr);
62+
TSDR_PUBLIC void tsdr_init(tsdr_lib_t * tsdr);
63+
TSDR_PUBLIC int tsdr_setsamplerate(tsdr_lib_t * tsdr, uint32_t rate);
64+
TSDR_PUBLIC int tsdr_setbasefreq(tsdr_lib_t * tsdr, uint32_t freq);
65+
TSDR_PUBLIC int tsdr_stop(tsdr_lib_t * tsdr);
66+
TSDR_PUBLIC int tsdr_setgain(tsdr_lib_t * tsdr, float gain);
67+
TSDR_PUBLIC int tsdr_readasync(tsdr_lib_t * tsdr, const char * pluginfilepath, tsdr_readasync_function cb, void *, const char * params);
68+
TSDR_PUBLIC int tsdr_unloadplugin(tsdr_lib_t * tsdr);
69+
TSDR_PUBLIC int tsdr_setresolution(tsdr_lib_t * tsdr, int width, int height, double refreshrate);
70+
TSDR_PUBLIC int tsdr_isrunning(tsdr_lib_t * tsdr);
71+
TSDR_PUBLIC int tsdr_sync(tsdr_lib_t * tsdr, int pixels, int direction);
72+
TSDR_PUBLIC int tsdr_motionblur(tsdr_lib_t * tsdr, float coeff);
73+
TSDR_PUBLIC char * tsdr_getlasterrortext(tsdr_lib_t * tsdr);
4874

4975
#endif

JavaGUI/jni/makefile

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,33 @@ ifndef JAVA_HOME
33
$(warning JAVA_HOME should be set so it points to your jdk installation dir)
44
endif
55

6-
# Flags
7-
CFLAGS=-O3
8-
96
# Define all of the C files here
107
OBJS = TSDRLibraryNDK.o
118

129
# Define all of the dependencies here
1310
DEPS = TSDRLibraryNDK.h include/TSDRLibrary.h include/TSDRCodes.h
1411

12+
# Flags
13+
CFLAGS+=-O3
14+
1515
# Headers
1616
INC = "$(JAVA_HOME)/include" "$(JAVA_HOME)/include/win32"
1717

1818
# Detect library extension depending on OS
1919
ifeq ($(OS),Windows_NT)
20+
2021
EXT=.dll
2122
OSNAME = WINDOWS
22-
ifeq ($(PROCESSOR_ARCHITECTURE),AMD64)
23-
ARCHNAME = X64
24-
endif
25-
ifeq ($(PROCESSOR_ARCHITECTURE),x86)
26-
ARCHNAME = X86
23+
24+
ifndef $(ARCHNAME)
25+
26+
ifeq ($(PROCESSOR_ARCHITECTURE),AMD64)
27+
ARCHNAME = X64
28+
endif
29+
ifeq ($(PROCESSOR_ARCHITECTURE),x86)
30+
ARCHNAME = X86
31+
endif
32+
2733
endif
2834
else
2935
UNAME_S := $(shell uname -s)
@@ -36,18 +42,36 @@ else
3642
EXT=.a
3743
OSNAME = OSX
3844
endif
39-
UNAME_P := $(shell uname -p)
40-
ifeq ($(UNAME_P),x86_64)
41-
ARCHNAME = X64
42-
endif
43-
ifneq ($(filter %86,$(UNAME_P)),)
44-
ARCHNAME = X86
45-
endif
46-
ifneq ($(filter arm%,$(UNAME_P)),)
47-
ARCHNAME = ARM
45+
46+
ifndef $(ARCHNAME)
47+
48+
UNAME_P := $(shell uname -p)
49+
ifeq ($(UNAME_P),x86_64)
50+
ARCHNAME = X64
51+
endif
52+
ifneq ($(filter %86,$(UNAME_P)),)
53+
ARCHNAME = X86
54+
endif
55+
ifneq ($(filter arm%,$(UNAME_P)),)
56+
ARCHNAME = ARM
57+
endif
58+
4859
endif
4960
endif
5061

62+
ifeq ($(ARCHNAME),X86)
63+
COMPILATION_TYPE=-m32
64+
else ifeq ($(ARCHNAME),X64)
65+
COMPILATION_TYPE=-m64
66+
endif
67+
68+
# OS specific flags
69+
ifeq ($(OSNAME),LINUX)
70+
CFLAGS+=-fPIC
71+
else ifeq ($(OSNAME),WINDOWS)
72+
LDFLAGS+=-Wl,--add-stdcall-alias
73+
endif
74+
5175
# The folder that will contain the libraries
5276
OUTPUTFOLDER=../lib/$(OSNAME)/$(ARCHNAME)
5377

@@ -62,7 +86,7 @@ all : rebuildtempestsdr library
6286

6387
# Linking
6488
library : $(_OBJS)
65-
gcc -L../../TempestSDR/bin/$(OSNAME)/$(ARCHNAME)/ -lTSDRLibrary -Wl -shared -o $(OUTPUTFOLDER)/$(LIBPREFIX)TSDRLibraryNDK$(EXT) $< -fPIC
89+
gcc -L../../TempestSDR/bin/$(OSNAME)/$(ARCHNAME)/ -lTSDRLibrary -shared $(LDFLAGS) $(COMPILATION_TYPE) -o $(OUTPUTFOLDER)/$(LIBPREFIX)TSDRLibraryNDK$(EXT) $<
6690

6791
# Rebuild the main library so that we have the most up-to-date version
6892
# The main library is assumed to be two levels below this jni folder
@@ -77,7 +101,7 @@ rebuildtempestsdr :
77101

78102
# Compile the sources to obj files
79103
$(OBJFOLDER)/%.o : %.c $(DEPS)
80-
gcc $(foreach d, $(INC), -I$d) $(CFLAGS) -c $< -o $@ -fPIC
104+
gcc $(foreach d, $(INC), -I$d) $(CFLAGS) $(COMPILATION_TYPE) -c $< -o $@
81105

82106
# Generate the java header based on the class
83107
TSDRLibraryNDK.h : ../bin/martin/tempest/core/TSDRLibrary.class

JavaGUI/src/martin/tempest/core/TSDRLibrary.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ private static final void loadLibrary(final String name) throws TSDRLibraryNotCo
115115
System.loadLibrary(name);
116116
} catch (Throwable t) {
117117
final File library = extractLibrary(name);
118-
System.out.println("File exists "+library.exists());
119118
System.load(library.getAbsolutePath());
120119
library.delete();
121120
}

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ This is the Java wrapper and GUI. It builds all projects and supported plugins i
5151
On Windows 8 x64 this could look like
5252

5353
make all JAVA_HOME=C:/PROGRA~2/Java/jdk1.7.0_45
54+
55+
To force compilation for X64 or X32, do the following
56+
57+
make all JAVA_HOME=C:/PROGRA~2/Java/jdk1.7.0_45 ARCHNAME=X64
5458

5559
On Ubuntu with openjdk it could look like
5660

TSDRPlugin_Mirics/makefile

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ PLUGNAME=TSDRPlugin_Mirics
66
OBJS=$(PLUGNAME).o
77
DEPS=TSDRPlugin.h TSDRCodes.h
88

9+
# Flags
10+
CFLAGS+=-O3
11+
912
# Headers
1013
INC = "$(MIRICS_HOME)/API/inc"
1114

@@ -16,44 +19,59 @@ HEADLOCATION=../TempestSDR/src/include/
1619

1720
# Discover the library extension for each OS
1821
ifeq ($(OS),Windows_NT)
22+
1923
EXT=.dll
2024
OSNAME = WINDOWS
21-
ifeq ($(PROCESSOR_ARCHITECTURE),AMD64)
22-
ARCHNAME = X64
23-
endif
24-
ifeq ($(PROCESSOR_ARCHITECTURE),x86)
25-
ARCHNAME = X86
25+
26+
ifndef $(ARCHNAME)
27+
28+
ifeq ($(PROCESSOR_ARCHITECTURE),AMD64)
29+
ARCHNAME = X64
30+
endif
31+
ifeq ($(PROCESSOR_ARCHITECTURE),x86)
32+
ARCHNAME = X86
33+
endif
34+
2635
endif
2736
else
2837
UNAME_S := $(shell uname -s)
2938
ifeq ($(UNAME_S),Linux)
3039
EXT=.so
3140
OSNAME = LINUX
41+
LIBPREFIX=lib
3242
endif
3343
ifeq ($(UNAME_S),Darwin)
3444
EXT=.a
3545
OSNAME = OSX
3646
endif
37-
UNAME_P := $(shell uname -p)
38-
ifeq ($(UNAME_P),x86_64)
39-
ARCHNAME = X64
40-
endif
41-
ifneq ($(filter %86,$(UNAME_P)),)
42-
ARCHNAME = X86
43-
endif
44-
ifneq ($(filter arm%,$(UNAME_P)),)
45-
ARCHNAME = ARM
47+
48+
ifndef $(ARCHNAME)
49+
50+
UNAME_P := $(shell uname -p)
51+
ifeq ($(UNAME_P),x86_64)
52+
ARCHNAME = X64
53+
endif
54+
ifneq ($(filter %86,$(UNAME_P)),)
55+
ARCHNAME = X86
56+
endif
57+
ifneq ($(filter arm%,$(UNAME_P)),)
58+
ARCHNAME = ARM
59+
endif
60+
4661
endif
4762
endif
4863

64+
ifeq ($(ARCHNAME),X86)
65+
COMPILATION_TYPE=-m32
66+
else ifeq ($(ARCHNAME),X64)
67+
COMPILATION_TYPE=-m64
68+
endif
69+
4970
# If you need a different directory structure. Don't change that unless you really want to.
5071
SOURCEFOLDER=src
5172
OUTPUTFOLDER=bin/$(OSNAME)/$(ARCHNAME)
5273
OBJFOLDER=obj
5374

54-
# Flags
55-
CPPFLAGS=-O3
56-
5775
# Calculate the path to dependencies
5876
_OBJS = $(patsubst %,$(OBJFOLDER)/%,$(OBJS))
5977
_DEPS = $(patsubst %,$(SOURCEFOLDER)/%,$(DEPS))
@@ -65,16 +83,23 @@ all : $(OUTPUTFOLDER)/$(PLUGNAME)$(EXT)
6583
copyoverheaderfile:
6684
@cp -f $(HEADLOCATION)/TSDRPlugin.h $(SOURCEFOLDER)/
6785
@cp -f $(HEADLOCATION)/TSDRCodes.h $(SOURCEFOLDER)/
86+
87+
# OS specific flags
88+
ifeq ($(OSNAME),LINUX)
89+
CFLAGS+=-fPIC
90+
else ifeq ($(OSNAME),WINDOWS)
91+
LDFLAGS+=-Wl,--add-stdcall-alias
92+
endif
6893

6994
# Link
7095
$(OUTPUTFOLDER)/$(PLUGNAME)$(EXT): copyoverheaderfile $(_OBJS)
71-
gcc -L"$(MIRICS_HOME)/API/$(ARCHNAME)/" -lmir_sdr_api -Wl,--add-stdcall-alias -shared -o $@ $(_OBJS)
96+
gcc -L"$(MIRICS_HOME)/API/$(ARCHNAME)/" -lmir_sdr_api $(LDFLAGS) -shared $(COMPILATION_TYPE) -o $@ $(_OBJS)
7297

7398
# Make dirs and compile
7499
$(OBJFOLDER)/%.o : $(SOURCEFOLDER)/%.c $(_DEPS)
75100
mkdir -p $(OUTPUTFOLDER)
76101
mkdir -p $(OBJFOLDER)
77-
gcc $(foreach d, $(INC), -I$d) $(CFLAGS) -c $< -o $@
102+
gcc $(foreach d, $(INC), -I$d) $(CFLAGS) $(COMPILATION_TYPE) -c $< -o $@
78103

79104
.PHONY: clean
80105

0 commit comments

Comments
 (0)