Skip to content

Commit

Permalink
Windows: use libxml2 from Rtools if found
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroen committed Dec 16, 2024
1 parent bd8a5c6 commit 8f62602
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# xml2 (development version)

* Windows: use libxml2 from Rtools if found

# xml2 1.3.6

* Now compatible with libxml2 2.12.0 and later (@KNnut).
Expand Down
30 changes: 18 additions & 12 deletions src/Makevars.win
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
VERSION=2.10.3
RWINLIB=../windows/libxml2-$(VERSION)
PKG_CPPFLAGS=-I../inst/include -I$(RWINLIB)/include/libxml2 \
-DLIBXML_STATIC
PKG_CONFIG_NAME = libxml-2.0
PKG_CONFIG ?= $(BINPREF)pkg-config
PKG_LIBS := $(shell $(PKG_CONFIG) --libs $(PKG_CONFIG_NAME))
STATIC_CFLAGS = -DLIBXML_STATIC -I../inst/include

ifneq ($(PKG_LIBS),)
$(info using $(PKG_CONFIG_NAME) from Rtools)
PKG_CPPFLAGS := $(shell $(PKG_CONFIG) --cflags $(PKG_CONFIG_NAME)) $(STATIC_CFLAGS)
else
RWINLIB = ../windows/libxml2-2.10.3
PKG_CPPFLAGS = -I$(RWINLIB)/include -I$(RWINLIB)/include/libxml2 $(STATIC_CFLAGS)
PKG_LIBS = -L$(RWINLIB)/lib${subst gcc,,$(COMPILED_BY)}$(R_ARCH) \
-L$(RWINLIB)/lib$(R_ARCH)\
-lxml2 -llzma -liconv -lz -lws2_32
-L$(RWINLIB)/lib$(R_ARCH) -lxml2 -llzma -liconv -lz -lws2_32
endif

all: clean winlibs
all: $(SHLIB)

clean:
rm -f $(OBJECTS) $(SHLIB)
$(OBJECTS): $(RWINLIB)

winlibs:
"${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" "../tools/winlibs.R" $(VERSION)
$(RWINLIB):
"${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" "../tools/winlibs.R"

.PHONY: all winlibs clean
clean:
rm -f $(SHLIB) $(OBJECTS)
6 changes: 2 additions & 4 deletions tools/winlibs.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Build against static libraries from rwinlib
VERSION <- commandArgs(TRUE)
if(!file.exists(sprintf("../windows/libxml2-%s/include/libxml2/libxml/parser.h", VERSION))){
if(getRversion() < "3.3.0") setInternet2()
download.file(sprintf("https://github.com/rwinlib/libxml2/archive/v%s.zip", VERSION), "lib.zip", quiet = TRUE)
if(!file.exists("../windows/libxml2-2.10.3/include/libxml2/libxml/parser.h")){
download.file("https://github.com/rwinlib/libxml2/archive/v2.10.3.zip", "lib.zip", quiet = TRUE)
dir.create("../windows", showWarnings = FALSE)
unzip("lib.zip", exdir = "../windows")
unlink("lib.zip")
Expand Down

0 comments on commit 8f62602

Please sign in to comment.