http-parser icon indicating copy to clipboard operation
http-parser copied to clipboard

Added support for compiling on MinGW platform

Open claudix opened this issue 9 years ago • 4 comments

Added rules to compile on MinGW platforms (Microsoft Windows environments):

  • Use 'gcc' as compiler.
  • Generate DLL file when compiling the library.
  • Disable -fPIC when compiling the library (on MinGW platforms all code is already position independent and setting this flag issues an error).

claudix avatar Mar 23 '16 09:03 claudix

Sorry for a long delay.

@jasnell @mscdex any of you guys have an access to Windows to give it a try? Thanks!

indutny avatar Apr 19 '16 22:04 indutny

@claudix Can this PR include cygwin platform as well?

I made the following patch

@@ -18,18 +18,30 @@
 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 # IN THE SOFTWARE.

+VERSION = 2.7.0
 PLATFORM ?= $(shell sh -c 'uname -s | tr "[A-Z]" "[a-z]"')
+ifeq ($(findstring cygwin,$(PLATFORM)), cygwin)
+PLATFORM = cygwin
+endif
+ifeq ($(findstring mingw,$(PLATFORM)), mingw)
+PLATFORM = mingw
+endif
+
 HELPER ?=
 BINEXT ?=
 ifeq (darwin,$(PLATFORM))
-SONAME ?= libhttp_parser.2.7.0.dylib
+SONAME ?= libhttp_parser.$(VERSION).dylib
 SOEXT ?= dylib
 else ifeq (wine,$(PLATFORM))
 CC = winegcc
 BINEXT = .exe.so
 HELPER = wine
+else ifneq (,$(filter $(PLATFORM),mingw cygwin))
+CC = gcc
+SONAME ?= libhttp_parser.$(VERSION).dll
+SOEXT  ?= dll
 else
-SONAME ?= libhttp_parser.so.2.7.0
+SONAME ?= libhttp_parser.so.$(VERSION)
 SOEXT ?= so
 endif

@@ -50,7 +62,12 @@
 CFLAGS_DEBUG = $(CFLAGS) -O0 -g $(CFLAGS_DEBUG_EXTRA)
 CFLAGS_FAST = $(CFLAGS) -O3 $(CFLAGS_FAST_EXTRA)
 CFLAGS_BENCH = $(CFLAGS_FAST) -Wno-unused-parameter
+
+ifneq (,$(filter $(PLATFORM),mingw cygwin))
+CFLAGS_LIB = $(CFLAGS_FAST)
+else
 CFLAGS_LIB = $(CFLAGS_FAST) -fPIC
+endif

 LDFLAGS_LIB = $(LDFLAGS) -shared

@@ -141,7 +158,7 @@
    rm -f *.o *.a tags test test_fast test_g \
        http_parser.tar libhttp_parser.so.* \
        url_parser url_parser_g parsertrace parsertrace_g \
-       *.exe *.exe.so
+       *.exe *.exe.so *.dll

 contrib/url_parser.c:  http_parser.h
 contrib/parsertrace.c: http_parser.h

and tested it on CYGWIN_NT-6.1 8308-HSQ0KM1 2.5.2(0.297/5/3) 2016-06-23 14:27 i686 Cygwin

wildart avatar Jun 28 '16 14:06 wildart

@wildart I'd like to. However I recommend you opening your own PR because, as you can notice, my PR has been waiting for 4 months and is still waiting to be merged.... No hope to finally see it merged. BTW, good idea to create the VERSION variable... Repeating the version string throughout the file is error prone and time wasting!

claudix avatar Jul 07 '16 06:07 claudix

It would be nice to include windows related changes into this patch: https://github.com/nodejs/http-parser/pull/321.

BTW, hardcoding gcc compiler is not a good idea. what is wrong with CC variable?

wildart avatar Jul 07 '16 13:07 wildart