Skip to content

Commit 4ff3129

Browse files
committed
Fix grid package build
1 parent 1c450d2 commit 4ff3129

File tree

6 files changed

+761
-814
lines changed

6 files changed

+761
-814
lines changed

com.oracle.truffle.r.native/gnur/patch/src/library/grid/Makefile

Lines changed: 83 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,96 @@
2727
#
2828
# Therefore we do not reuse the grid installed in GNU-R, but we build grid
2929
# from scratch from our own patched version that lives next to this Makefile
30+
# With that grid distribution, we continue like with other packages replacing
31+
# the shared library with one that we build from our sources (from "src" next
32+
# to this Makefile)
33+
34+
# As a temporary solution, this is copy&paste of ../lib.mk + the necessary changes
3035

3136
ifneq ($(MAKECMDGOALS),clean)
3237
include $(TOPDIR)/platform.mk
3338
endif
3439

35-
.PHONY: all clean
40+
.PHONY: all clean cleanlib cleanobj force libr libcommon
3641

37-
# Note: FASTR_LIBRARY_DIR is defined by the upper level Makefile that calls us
38-
PKGNAME := grid
39-
PKGDIR := $(FASTR_LIBRARY_DIR)/$(PKGNAME)
42+
# This is necessary so that #include "grid.h" works
43+
PKG_INCLUDES = -I src
4044

41-
$(PKGDIR): $(PKGNAME)
42-
$(GNUR_HOME_BINARY)/bin/R CMD INSTALL --library=$(FASTR_LIBRARY_DIR) $(PKGNAME)
45+
PKG = $(PACKAGE)
4346

44-
all: $(PKGDIR)
47+
SRC = src
48+
OBJ = lib
4549

46-
clean:
47-
rm -rf $(PKGDIR)
48-
rm $(PKGNAME)/src/*.o
49-
rm $(PKGNAME)/src/*.so
50+
C_SOURCES := $(wildcard $(SRC)/*.c)
51+
C_SOURCES := $(filter-out $(C_SOURCES_EXCLUDED), $(C_SOURCES))
5052

51-
# Original version that builds grid from GNU-R:
52-
# This is necessary so that #include "grid.h" works
53-
# PKG_INCLUDES = -I src
54-
#
55-
# include ../lib.mk
53+
C_OBJECTS := $(subst $(SRC)/,$(OBJ)/,$(C_SOURCES:.c=.o))
54+
55+
F_SOURCES := $(wildcard $(SRC)/*.f)
56+
F_SOURCES := $(filter-out $(F_SOURCES_EXCLUDED), $(F_SOURCES))
57+
58+
F_OBJECTS := $(subst $(SRC)/,$(OBJ)/,$(F_SOURCES:.f=.o))
59+
60+
H_SOURCES := $(wildcard $(SRC)/*.h)
61+
62+
LIBDIR := $(OBJ)
63+
64+
# packages seem to use .so even on Mac OS X and no "lib"
65+
LIB_PKG := $(OBJ)/$(PKG).so
66+
67+
JNI_INCLUDES = -I $(JAVA_HOME)/include -I $(JAVA_HOME)/include/$(JDK_OS_DIR)
68+
FFI_INCLUDES = -I$(TOPDIR)/include -I$(TOPDIR)/include/R_ext
69+
70+
INCLUDES := $(JNI_INCLUDES) $(FFI_INCLUDES) $(PKG_INCLUDES)
71+
72+
PKGDIR := $(FASTR_LIBRARY_DIR)/$(PKG)
73+
74+
F2C := -lf2c
75+
76+
SUPPRESS_WARNINGS := -Wno-int-conversion -Wno-implicit-function-declaration
77+
78+
ifeq ($(NO_LIBRARY),)
79+
all: $(LIB_PKG_PRE) libcommon $(LIB_PKG) $(LIB_PKG_POST)
80+
else
81+
all: $(LIB_PKG_PRE) libcommon $(LIB_PKG_POST)
82+
endif
83+
84+
libcommon: $(PKGDIR)
85+
86+
# Copy the package's artifacts to FASTR_LIBRARY_DIR. The binaries will be replaced at a later stage.
87+
$(PKGDIR): grid
88+
$(GNUR_HOME_BINARY)/bin/R CMD INSTALL --library=$(FASTR_LIBRARY_DIR) grid
89+
touch $(PKGDIR)
90+
91+
$(C_OBJECTS): | $(OBJ)
92+
93+
$(F_OBJECTS): | $(OBJ)
94+
95+
$(OBJ):
96+
mkdir -p $(OBJ)
97+
98+
ifeq ($(OS_NAME),Darwin)
99+
RPATH_OPT = -Wl,-undefined,dynamic_lookup
100+
else
101+
RPATH = $$ORIGIN/../../../lib/
102+
RPATH_OPT = -Wl,-rpath='$(RPATH)'
103+
endif
104+
105+
$(LIB_PKG): $(C_OBJECTS) $(F_OBJECTS) $(PKGDIR) $(XTRA_C_OBJECTS)
106+
mkdir -p $(LIBDIR)
107+
$(DYLIB_LD) $(DYLIB_LDFLAGS) -L$(FASTR_LIB_DIR) $(RPATH_OPT) -o $(LIB_PKG) $(C_OBJECTS) $(F_OBJECTS) $(XTRA_C_OBJECTS) $(PKG_LIBS) -lR -lz $(F2C) -lRlapack
108+
mkdir -p $(FASTR_LIBRARY_DIR)/$(PKG)/libs
109+
cp "$(LIB_PKG)" $(FASTR_LIBRARY_DIR)/$(PKG)/libs
110+
ifeq ($(OS_NAME),Darwin)
111+
install_name_tool -id @rpath/../library/$(PKG)/libs/$(PKG).so $(FASTR_LIBRARY_DIR)/$(PKG)/libs/$(PKG).so
112+
endif
113+
114+
$(OBJ)/%.o: $(SRC)/%.c $(H_SOURCES)
115+
$(CC) $(CFLAGS) $(INCLUDES) $(XTRA_C_OPTS) -c $< -o $@
116+
117+
$(OBJ)/%.o: $(SRC)/%.f
118+
$(FC) $(FFLAGS) $(FPICFLAGS) $(XTRA_F_OPTS) -c $< -o $@
119+
120+
clean: $(CLEAN_PKG)
121+
rm -rf $(LIBDIR)/*
122+
rm -rf $(FASTR_LIBRARY_DIR)/$(PKG)
Binary file not shown.

com.oracle.truffle.r.native/gnur/patch/src/library/grid/src/grid.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1139,7 +1139,8 @@ SEXP L_convert(SEXP x, SEXP whatfrom,
11391139
* In these cases do NOT transform thru INCHES
11401140
* (to avoid divide-by-zero, but still do something useful)
11411141
*/
1142-
relConvert = ((unitUnit(x, i) == L_NATIVE || unitUnit(x, i) == L_NPC) &&
1142+
relConvert = (!isUnitArithmetic(x) && !isUnitList(x) &&
1143+
(unitUnit(x, i) == L_NATIVE || unitUnit(x, i) == L_NPC) &&
11431144
(TOunit == L_NATIVE || TOunit == L_NPC) &&
11441145
((FROMaxis == TOaxis) ||
11451146
(FROMaxis == 0 && TOaxis == 2) ||

com.oracle.truffle.r.native/gnur/patch/src/library/grid/src/grid.h

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,6 @@
138138
#define GRID_ARROWENDS 2
139139
#define GRID_ARROWTYPE 3
140140

141-
/*
142-
* Helpers for unit types
143-
*/
144-
#define uValue(X) REAL(VECTOR_ELT(X, 0))[0]
145-
#define uData(X) VECTOR_ELT(X, 1)
146-
#define uUnit(X) INTEGER(VECTOR_ELT(X, 2))[0]
147-
148141
typedef double LTransform[3][3];
149142

150143
typedef double LLocation[3];
@@ -201,20 +194,9 @@ typedef enum {
201194
L_MYLINES = 103,
202195
L_MYCHAR = 104,
203196
L_MYSTRINGWIDTH = 105,
204-
L_MYSTRINGHEIGHT = 106,
205-
/*
206-
* Arithmetic units
207-
*/
208-
L_SUM = 201,
209-
L_MIN = 202,
210-
L_MAX = 203
197+
L_MYSTRINGHEIGHT = 106
211198
} LUnit;
212199

213-
#define isAbsolute(X) ((X > 1000 || (X >= L_MYLINES && X <= L_MYSTRINGHEIGHT) || (X < L_GROBX && X > L_NPC && X != L_NATIVE && X != L_SNPC)))
214-
#define isArith(X) (X >= L_SUM && X <= L_MAX)
215-
#define isStringUnit(X) (X >= L_STRINGWIDTH && X <= L_STRINGDESCENT)
216-
#define isGrobUnit(X) (X >= L_GROBX && X <= L_GROBDESCENT)
217-
218200
typedef enum {
219201
L_LEFT = 0,
220202
L_RIGHT = 1,
@@ -353,6 +335,10 @@ void location(double x, double y, LLocation v);
353335
void trans(LLocation vin, LTransform m, LLocation vout);
354336

355337
/* From unit.c */
338+
int isUnitArithmetic(SEXP ua);
339+
340+
int isUnitList(SEXP ul);
341+
356342
SEXP unit(double value, int unit);
357343

358344
double unitValue(SEXP unit, int index);
@@ -652,15 +638,6 @@ SEXP L_xsplinePoints(SEXP x, SEXP y, SEXP s, SEXP o, SEXP a, SEXP rep,
652638

653639
/* From unit.c */
654640
SEXP validUnits(SEXP units);
655-
SEXP constructUnits(SEXP amount, SEXP data, SEXP unit);
656-
SEXP asUnit(SEXP simpleUnit);
657-
SEXP conformingUnits(SEXP unitList);
658-
SEXP matchUnit(SEXP units, SEXP unit);
659-
SEXP addUnits(SEXP u1, SEXP u2);
660-
SEXP multUnits(SEXP units, SEXP values);
661-
SEXP flipUnits(SEXP units);
662-
SEXP absoluteUnits(SEXP units);
663-
SEXP summaryUnits(SEXP units, SEXP op_type);
664641

665642
/* From gpar.c */
666643
SEXP L_getGPar(void);

com.oracle.truffle.r.native/gnur/patch/src/library/grid/src/register.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,6 @@ static const R_CallMethodDef callMethods[] = {
8787
LCALLDEF(xsplinePoints, 8),
8888
LCALLDEF(stringMetric, 1),
8989
{"validUnits", (DL_FUNC) &validUnits, 1},
90-
{"constructUnits", (DL_FUNC) &constructUnits, 3},
91-
{"asUnit", (DL_FUNC) &asUnit, 1},
92-
{"conformingUnits", (DL_FUNC) &conformingUnits, 1},
93-
{"matchUnit", (DL_FUNC) &matchUnit, 2},
94-
{"addUnits", (DL_FUNC) &addUnits, 2},
95-
{"multUnits", (DL_FUNC) &multUnits, 2},
96-
{"flipUnits", (DL_FUNC) &flipUnits, 1},
97-
{"absoluteUnits", (DL_FUNC) &absoluteUnits, 1},
98-
{"summaryUnits", (DL_FUNC) &summaryUnits, 2},
9990
{ NULL, NULL, 0 }
10091
};
10192

0 commit comments

Comments
 (0)