Skip to content

Commit 392a321

Browse files
Modify cc so it works in windows with MinGW #6423 (#6429)
* cc.R: - add WIN32 define (-DWIN32) as -c99 do not definie it - in windows replace `system()` with `shell()` - in windows data_table.dll instead of data_table.so (dyn.load()) * Update cc.R * Update cc.R * Apply suggestions from code review Co-authored-by: Michael Chirico <[email protected]> * Update .dev/cc.R Co-authored-by: Michael Chirico <[email protected]> * use dt_object * make log clearer * make OMP clearer, use R"()" in other branch too --------- Co-authored-by: Michael Chirico <[email protected]>
1 parent eaa7cd3 commit 392a321

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

.dev/cc.R

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,35 @@ cc = function(test=FALSE, clean=FALSE, debug=FALSE, omp=!debug, path=Sys.getenv(
7070
dll = grep("data_table.so", dll, fixed=TRUE, value=TRUE)
7171
sapply(dll, dyn.unload)
7272
gc()
73+
74+
# hack for windows under mingw-like environment
75+
# PROJ_PATH must be windows like i.e.: export PROJ_PATH=$(Rscript -e 'getwd()')
76+
if (.Platform$OS.type == "windows") {
77+
system = function(command, ...) shell(shQuote(command, "sh"), shell = "sh",...)
78+
# when -std=c99, macro WIN32 is not defined (MinGW) so we define it
79+
# otherwise will fail as sys/mman.h does not exists in windows (fread.c)
80+
W32 = "-DWIN32"
81+
dt_object = "data_table"
82+
} else {
83+
W32 = ""
84+
dt_object = "data_table.so"
85+
}
7386

7487
old = getwd()
7588
on.exit(setwd(old))
7689
setwd(file.path(path,"src"))
7790
if (!quiet) cat(getwd(),"\n")
7891
if (clean) system("rm *.o *.so")
79-
OMP = if (omp) "" else "no-"
92+
OMP = if (omp) "openmp" else "no-openmp"
8093
if (debug) {
81-
ret = system(ignore.stdout=quiet, sprintf("MAKEFLAGS='-j CC=%s PKG_CFLAGS=-f%sopenmp CFLAGS=-std=c99\\ -O0\\ -ggdb\\ -pedantic' R CMD SHLIB -d -o data_table.so *.c", CC, OMP))
94+
cmd = sprintf(R"(MAKEFLAGS='-j CC=%s PKG_CFLAGS=-f% CFLAGS=-std=c99\ -O0\ -ggdb\ %s\ -pedantic' R CMD SHLIB -d -o data_table.so *.c)", CC, OMP, W32)
8295
} else {
83-
ret = system(ignore.stdout=quiet, sprintf("MAKEFLAGS='-j CC=%s CFLAGS=-f%sopenmp\\ -std=c99\\ -O3\\ -pipe\\ -Wall\\ -pedantic\\ -Wstrict-prototypes\\ -isystem\\ /usr/share/R/include\\ -fno-common' R CMD SHLIB -o data_table.so *.c", CC, OMP))
96+
cmd = sprintf(R"(MAKEFLAGS='-j CC=%s CFLAGS=-f%s\ -std=c99\ -O3\ -pipe\ -Wall\ -pedantic\ -Wstrict-prototypes\ -isystem\ /usr/share/R/include\ %s\ -fno-common' R CMD SHLIB -o data_table.so *.c)", CC, OMP, W32)
8497
# the -isystem suppresses strict-prototypes warnings from R's headers, #5477. Look at the output to see what -I is and pass the same path to -isystem.
8598
# TODO add -Wextra too?
8699
}
100+
cat(sprintf("Running command:\n%s\n", cmd))
101+
ret = system(cmd, ignore.stdout=quiet)
87102
if (ret) return()
88103
# clang -Weverything includes -pedantic and issues many more warnings than gcc
89104
# system("R CMD SHLIB -o data_table.so *.c")
@@ -93,7 +108,7 @@ cc = function(test=FALSE, clean=FALSE, debug=FALSE, omp=!debug, path=Sys.getenv(
93108
break
94109
}
95110
}
96-
dyn.load("data_table.so")
111+
dyn.load(dt_object)
97112
setwd(old)
98113
xx = getDLLRegisteredRoutines("data_table",TRUE)
99114
for (Call in xx$.Call)

0 commit comments

Comments
 (0)