diff --git a/libserialport.h b/libserialport.h index 7467f74..e886fd2 100644 --- a/libserialport.h +++ b/libserialport.h @@ -280,20 +280,32 @@ extern "C" { /** @cond */ #ifdef _MSC_VER -/* Microsoft Visual C/C++ compiler in use */ -#ifdef LIBSERIALPORT_MSBUILD -/* Building the library - need to export DLL symbols */ -#define SP_API __declspec(dllexport) + /* Microsoft Visual C/C++ compiler in use */ + #ifdef LIBSERIALPORT_MSBUILD + // Building the library - need to export DLL symbols + #define SP_API __declspec(dllexport) + #else + // Using the library - need to import DLL symbols + #define SP_API __declspec(dllimport) + #endif + // #define SP_CALL +#elif defined(__MINGW32__) + // You should define LIBSERIALPORT_MINGW64BUILD *only* when building the DLL. + #ifdef LIBSERIALPORT_MINGW64BUILD + #define SP_API __declspec(dllexport) + #else + #define SP_API __declspec(dllimport) + #endif + // Define calling convention in one place, for convenience. + // On MinGW64 "__cdecl" is default value. + // #define SP_CALL __cdecl #else -/* Using the library - need to import DLL symbols */ -#define SP_API __declspec(dllimport) -#endif -#else -/* Some other compiler in use */ -#ifndef LIBSERIALPORT_ATBUILD -/* Not building the library itself - don't need any special prefixes. */ -#define SP_API -#endif + /* Some other compiler in use */ + #ifndef LIBSERIALPORT_ATBUILD + /* Not building the library itself - don't need any special prefixes. */ + #define SP_API + #endif + // #define SP_CALL #endif /** @endcond */ diff --git a/libserialport_internal.h b/libserialport_internal.h index ecf8fe9..a66f103 100644 --- a/libserialport_internal.h +++ b/libserialport_internal.h @@ -47,6 +47,16 @@ #define SP_PRIV #endif +#ifdef LIBSERIALPORT_MINGW64BUILD +/* If building with MinGW64 tools, define necessary things that + would otherwise appear in config.h. */ +#define SP_PRIV +#endif + +#ifndef SP_PRIV +#error "You should define one of LIBSERIALPORT_ATBUILD, LIBSERIALPORT_MSBUILD, LIBSERIALPORT_MINGW64BUILD" +#endif + #include "libserialport.h" #include diff --git a/mingw64.mak b/mingw64.mak new file mode 100644 index 0000000..445b1b1 --- /dev/null +++ b/mingw64.mak @@ -0,0 +1,53 @@ +# mingw64.mak: build libserialport.dll using MinGW64-w64 + +# Program for compiling C programs +CC = gcc + +# Extra flags to give to the C preprocessor +CPPFLAGS = +CPPFLAGS += -DLIBSERIALPORT_MINGW64BUILD +# CPPFLAGS += -DLIBSERIALPORT_MSBUILD +# CPPFLAGS += -DLIBSERIALPORT_ATBUILD +# CPPFLAGS += -DHAVE_CONFIG_H + +# Extra flags to give to the C compiler. +CFLAGS = +CFLAGS += -I. -std=c99 +CFLAGS += -Wall -Wextra -pedantic -Wmissing-prototypes -Wshadow +CFLAGS += -g -O2 + +# Extra flags when invoking the linker +LDFLAGS = -s -shared -Wl,--subsystem,windows + +# Library flags or names when invoking the linker +LDLIBS = -lsetupapi + +# Command to remove a file +RM = rm -f + +H_FILES = libserialport_internal.h libserialport.h +O_FILES = serialport.o timing.o windows.o + +all: libserialport.dll + +libserialport.dll: $(O_FILES) + gcc -o libserialport.dll $(O_FILES) $(LDFLAGS) $(LDLIBS) + +serialport.o: serialport.c $(H_FILES) + $(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $< + +timing.o: timing.c $(H_FILES) + $(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $< + +windows.o: windows.c $(H_FILES) + $(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $< + +install: + @echo "install is not yet implemented" + exit 1 + +clean: + $(RM) libserialport.dll + $(RM) *.o + +.PHONY: all install clean