From 1caa844dad647b03cf3c1d11bf211e9fcde4b7f1 Mon Sep 17 00:00:00 2001 From: mwturvey Date: Wed, 15 Mar 2017 11:38:22 -0700 Subject: Windows Compiling --- include/libsurvive/survive.h | 46 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/libsurvive/survive.h b/include/libsurvive/survive.h index 349a93e..db04a9d 100644 --- a/include/libsurvive/survive.h +++ b/include/libsurvive/survive.h @@ -136,10 +136,38 @@ void survive_default_angle_process( SurviveObject * so, int sensor_id, int acode ////////////////////// Survive Drivers //////////////////////////// +// The following macros were taken from StackOverflow here: +// http://stackoverflow.com/questions/1113409/attribute-constructor-equivalent-in-vc +// The author, Joe Lowe explicitly released this code into the public domain as part of his post. +#ifdef __cplusplus +#define INITIALIZER(f) \ + static void f(void); \ + struct f##_t_ { f##_t_(void) { f(); } }; static f##_t_ f##_; \ + static void f(void) +#elif defined(_MSC_VER) +#pragma section(".CRT$XCU",read) +#define INITIALIZER2_(f,p) \ + static void f(void); \ + __declspec(allocate(".CRT$XCU")) void (*f##_)(void) = f; \ + __pragma(comment(linker,"/include:" p #f "_")) \ + static void f(void) +#ifdef _WIN64 +#define INITIALIZER(f) INITIALIZER2_(f,"") +#else +#define INITIALIZER(f) INITIALIZER2_(f,"_") +#endif +#else +#define INITIALIZER(f) \ + static void f(void) __attribute__((constructor)); \ + static void f(void) +#endif +// End macros from StackOverflow. + + void RegisterDriver( const char * name, void * data ); #define REGISTER_LINKTIME( func ) \ - void __attribute__((constructor)) REGISTER##func() { RegisterDriver( #func, &func ); } + INITIALIZER(LTRegister##func) { RegisterDriver( #func, &func ); } @@ -151,19 +179,29 @@ void survive_add_driver( SurviveContext * ctx, void * payload, DeviceDriverCb po //For lightcap, etc. Don't change this structure at all. Regular vive is dependent on it being exactly as-is. //When you write drivers, you can use this to send survive lightcap data. +#ifdef _WIN32 +#pragma pack(push,1) +#endif typedef struct { uint8_t sensor_id; uint8_t type; //Mostly unused. Set to 255 to ignore it. uint16_t length; uint32_t timestamp; -} __attribute__((packed)) LightcapElement; +} +#ifdef __linux__ +__attribute__((packed)) +#endif +LightcapElement; +#ifdef _WIN32 +#pragma pack(pop) +#endif //This is the disambiguator function, for taking light timing and figuring out place-in-sweep for a given photodiode. void handle_lightcap( SurviveObject * so, LightcapElement * le ); -#define SV_INFO( x... ) { char stbuff[1024]; sprintf( stbuff, x ); ctx->notefunction( ctx, stbuff ); } -#define SV_ERROR( x... ) { char stbuff[1024]; sprintf( stbuff, x ); ctx->faultfunction( ctx, stbuff ); } +#define SV_INFO( ... ) { char stbuff[1024]; sprintf( stbuff, __VA_ARGS__ ); ctx->notefunction( ctx, stbuff ); } +#define SV_ERROR( ... ) { char stbuff[1024]; sprintf( stbuff, __VA_ARGS__ ); ctx->faultfunction( ctx, stbuff ); } #define SV_KILL() exit(0) //XXX This should likely be re-defined. #endif -- cgit v1.2.3 From a409645cd3e2b8f0cc67541a9e4c88bf2cd96a79 Mon Sep 17 00:00:00 2001 From: mwturvey Date: Wed, 15 Mar 2017 15:31:17 -0700 Subject: Building & basic running --- include/libsurvive/survive.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/libsurvive/survive.h b/include/libsurvive/survive.h index db04a9d..2663c57 100644 --- a/include/libsurvive/survive.h +++ b/include/libsurvive/survive.h @@ -147,10 +147,10 @@ void survive_default_angle_process( SurviveObject * so, int sensor_id, int acode #elif defined(_MSC_VER) #pragma section(".CRT$XCU",read) #define INITIALIZER2_(f,p) \ - static void f(void); \ + __declspec(dllexport) void f(void); \ __declspec(allocate(".CRT$XCU")) void (*f##_)(void) = f; \ __pragma(comment(linker,"/include:" p #f "_")) \ - static void f(void) + void f(void) #ifdef _WIN64 #define INITIALIZER(f) INITIALIZER2_(f,"") #else @@ -163,11 +163,19 @@ void survive_default_angle_process( SurviveObject * so, int sensor_id, int acode #endif // End macros from StackOverflow. +//static void foo(void) +//{ +// int a=0; +//} +// +//INITIALIZER(foo); + void RegisterDriver( const char * name, void * data ); #define REGISTER_LINKTIME( func ) \ - INITIALIZER(LTRegister##func) { RegisterDriver( #func, &func ); } + __declspec(dllexport) void LTRegister##func() { RegisterDriver( #func, &func ); } \ + INITIALIZER(LTRegister##func) -- cgit v1.2.3 From fa0f4825937ed93163bb2cd165c001d7444d8928 Mon Sep 17 00:00:00 2001 From: mwturvey Date: Thu, 16 Mar 2017 10:31:19 -0700 Subject: Last try at getting linktime registration working under MSVC --- include/libsurvive/survive.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'include') diff --git a/include/libsurvive/survive.h b/include/libsurvive/survive.h index 2663c57..deb91c4 100644 --- a/include/libsurvive/survive.h +++ b/include/libsurvive/survive.h @@ -149,6 +149,7 @@ void survive_default_angle_process( SurviveObject * so, int sensor_id, int acode #define INITIALIZER2_(f,p) \ __declspec(dllexport) void f(void); \ __declspec(allocate(".CRT$XCU")) void (*f##_)(void) = f; \ + volatile static void * LTRegistrationPinnerFor##f = &##f; \ __pragma(comment(linker,"/include:" p #f "_")) \ void f(void) #ifdef _WIN64 @@ -176,6 +177,9 @@ void RegisterDriver( const char * name, void * data ); #define REGISTER_LINKTIME( func ) \ __declspec(dllexport) void LTRegister##func() { RegisterDriver( #func, &func ); } \ INITIALIZER(LTRegister##func) + + + //void __attribute__((constructor)) LTRegister##func() { RegisterDriver(#func, &func); } -- cgit v1.2.3 From 27c9edd889c746e818dc3aa55971d9cd6d8595a7 Mon Sep 17 00:00:00 2001 From: mwturvey Date: Thu, 16 Mar 2017 10:32:18 -0700 Subject: Manual registration on Windows --- include/libsurvive/survive.h | 46 ++++---------------------------------------- 1 file changed, 4 insertions(+), 42 deletions(-) (limited to 'include') diff --git a/include/libsurvive/survive.h b/include/libsurvive/survive.h index deb91c4..3bc3b33 100644 --- a/include/libsurvive/survive.h +++ b/include/libsurvive/survive.h @@ -136,50 +136,12 @@ void survive_default_angle_process( SurviveObject * so, int sensor_id, int acode ////////////////////// Survive Drivers //////////////////////////// -// The following macros were taken from StackOverflow here: -// http://stackoverflow.com/questions/1113409/attribute-constructor-equivalent-in-vc -// The author, Joe Lowe explicitly released this code into the public domain as part of his post. -#ifdef __cplusplus -#define INITIALIZER(f) \ - static void f(void); \ - struct f##_t_ { f##_t_(void) { f(); } }; static f##_t_ f##_; \ - static void f(void) -#elif defined(_MSC_VER) -#pragma section(".CRT$XCU",read) -#define INITIALIZER2_(f,p) \ - __declspec(dllexport) void f(void); \ - __declspec(allocate(".CRT$XCU")) void (*f##_)(void) = f; \ - volatile static void * LTRegistrationPinnerFor##f = &##f; \ - __pragma(comment(linker,"/include:" p #f "_")) \ - void f(void) -#ifdef _WIN64 -#define INITIALIZER(f) INITIALIZER2_(f,"") -#else -#define INITIALIZER(f) INITIALIZER2_(f,"_") -#endif +#ifdef _WIN32 +#define REGISTER_LINKTIME( func ) #else -#define INITIALIZER(f) \ - static void f(void) __attribute__((constructor)); \ - static void f(void) -#endif -// End macros from StackOverflow. - -//static void foo(void) -//{ -// int a=0; -//} -// -//INITIALIZER(foo); - - -void RegisterDriver( const char * name, void * data ); - #define REGISTER_LINKTIME( func ) \ - __declspec(dllexport) void LTRegister##func() { RegisterDriver( #func, &func ); } \ - INITIALIZER(LTRegister##func) - - - //void __attribute__((constructor)) LTRegister##func() { RegisterDriver(#func, &func); } + void __attribute__((constructor)) LTRegister##func() { RegisterDriver(#func, &func); } +#endif -- cgit v1.2.3 From d9c9ebe6de1e6f255d645dd6e641f2c288238bc2 Mon Sep 17 00:00:00 2001 From: mwturvey Date: Thu, 16 Mar 2017 10:42:56 -0700 Subject: fix linux build --- include/libsurvive/survive.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/libsurvive/survive.h b/include/libsurvive/survive.h index 3bc3b33..eb30252 100644 --- a/include/libsurvive/survive.h +++ b/include/libsurvive/survive.h @@ -136,11 +136,13 @@ void survive_default_angle_process( SurviveObject * so, int sensor_id, int acode ////////////////////// Survive Drivers //////////////////////////// +void RegisterDriver( const char * name, void * data ); + #ifdef _WIN32 #define REGISTER_LINKTIME( func ) #else #define REGISTER_LINKTIME( func ) \ - void __attribute__((constructor)) LTRegister##func() { RegisterDriver(#func, &func); } + void __attribute__((constructor)) REGISTER##func() { RegisterDriver(#func, &func); } #endif -- cgit v1.2.3