diff --git a/C/c_interface.c b/C/c_interface.c index bcab3a4b5..01cd34c3a 100755 --- a/C/c_interface.c +++ b/C/c_interface.c @@ -2304,21 +2304,23 @@ X_API char *YAP_CompileClause(Term t) { static int yap_lineno = 0; /* do initial boot by consulting the file boot.yap */ -static void do_bootfile(const char *bootfilename USES_REGS) { +static void do_bootfile(const char *b_file USES_REGS) { Term t; int bootfile, osno; Functor functor_query = Yap_MkFunctor(Yap_LookupAtom("?-"), 1); Functor functor_command1 = Yap_MkFunctor(Yap_LookupAtom(":-"), 1); - char full[YAP_FILENAME_MAX + 1]; /* consult boot.pl */ + char *full = malloc(YAP_FILENAME_MAX + 1); + full[0] = '\0'; /* the consult mode does not matter here, really */ - bootfile = YAP_InitConsult(YAP_BOOT_MODE, bootfilename, full, &osno); + bootfile = YAP_InitConsult(YAP_BOOT_MODE, b_file, full, &osno); if (bootfile < 0) { fprintf(stderr, "[ FATAL ERROR: could not open bootfile %s ]\n", - bootfilename); + b_file); exit(1); } +free(full); do { CACHE_REGS YAP_Reset(YAP_FULL_RESET); @@ -2329,7 +2331,7 @@ static void do_bootfile(const char *bootfilename USES_REGS) { if (t == 0) { fprintf(stderr, "[ SYNTAX ERROR: while parsing bootfile %s at line %d ]\n", - bootfilename, yap_lineno); + b_file, yap_lineno); } else if (YAP_IsVarTerm(t) || t == TermNil) { fprintf(stderr, "[ line %d: term cannot be compiled ]", yap_lineno); } else if (YAP_IsPairTerm(t)) { @@ -2420,10 +2422,11 @@ static void do_bootfile(const char *bootfilename USES_REGS) { YAP_file_type_t restore_result = yap_init->boot_file_type; bool do_bootstrap = (restore_result & YAP_CONSULT_MODE); CELL Trail = 0, Stack = 0, Heap = 0, Atts = 0; - char boot_file[YAP_FILENAME_MAX + 1]; + char *boot_file; Int rc; const char *yroot; + boot_file = calloc(YAP_FILENAME_MAX + 1, 1); /* ignore repeated calls to YAP_Init */ if (YAP_initialized) return YAP_FOUND_BOOT_ERROR; @@ -2467,9 +2470,10 @@ static void do_bootfile(const char *bootfilename USES_REGS) { if (yap_init->YapPrologBootFile == NULL) yap_init->YapPrologBootFile = BootFile; #else - yap_init->YapPrologBootFile = - Yap_findFile(yap_init->YapPrologBootFile, BootFile, yroot, boot_file, + + const char *s = Yap_findFile(yap_init->YapPrologBootFile, BootFile, yroot, boot_file, true, YAP_BOOT_PL, true, true); + if (s && s[0] != '\0') strcpy(boot_file, s); #endif } @@ -2619,18 +2623,17 @@ static void do_bootfile(const char *bootfilename USES_REGS) { setBooleanGlobalPrologFlag(SAVED_PROGRAM_FLAG, true); rc = YAP_QLY; } else { - if (!yap_init->YapPrologBootFile) - yap_init->YapPrologBootFile = BootFile; - rc = YAP_BOOT_PL; - do_bootfile(yap_init->YapPrologBootFile); + if (boot_file[0] == '\0') + strcpy(boot_file, BootFile); + do_bootfile(boot_file PASS_REGS); setAtomicGlobalPrologFlag( RESOURCE_DATABASE_FLAG, - MkAtomTerm(Yap_LookupAtom(yap_init->YapPrologBootFile))); + MkAtomTerm(Yap_LookupAtom(boot_file))); setBooleanGlobalPrologFlag(SAVED_PROGRAM_FLAG, false); } start_modules(); YAP_initialized = true; - return rc; + return YAP_BOOT_PL; } #if (DefTrailSpace < MinTrailSpace) diff --git a/C/text.c b/C/text.c index d2becfc00..e88b7bfd9 100644 --- a/C/text.c +++ b/C/text.c @@ -31,6 +31,11 @@ inline static size_t min_size(size_t i, size_t j) { return (i < j ? i : j); } #define wcsnlen(S, N) min_size(N, wcslen(S)) #endif +#ifndef HAVE_STPCPY +inline static void* __stpcpy(void * i, const void * j) { return strcpy(i,j)+strlen(j);} +#define stpcpy __stpcpy +#endif + #ifndef NAN #define NAN (0.0 / 0.0) #endif @@ -993,7 +998,7 @@ bool Yap_Splice_Text(int n, size_t cuts[], seq_tv_t *inp, return false; } b_l0 = strlen((const char *)buf0); - if (bcmp(buf, buf0, b_l0) != 0) { + if (memcmp(buf, buf0, b_l0) != 0) { return false; } u_l0 = strlen_utf8(buf0); @@ -1016,7 +1021,7 @@ bool Yap_Splice_Text(int n, size_t cuts[], seq_tv_t *inp, u_l1 = strlen_utf8(buf1); b_l0 = b_l - b_l1; u_l0 = u_l - u_l1; - if (bcmp(skip_utf8((const unsigned char *)buf, b_l0), buf1, b_l1) != + if (memcmp(skip_utf8((const unsigned char *)buf, b_l0), buf1, b_l1) != 0) { return false; } @@ -1043,35 +1048,6 @@ bool Yap_Splice_Text(int n, size_t cuts[], seq_tv_t *inp, return true; } -/** - * Function to convert a generic text term (string, atom, list of codes, list - of< - atoms) into a buff - er. - * - * @param t the term - * @param buf the buffer, if NULL a buffer is malloced, and the user should - reclai it - * @param len buffer size - * @param enc encoding (UTF-8 is strongly recommended) - * - * @return the buffer, or NULL in case of failure. If so, Yap_Error may be - called. -*/ -const char *Yap_TextTermToText(Term t USES_REGS) { - seq_tv_t inp, out; - inp.val.t = t; - inp.type = Yap_TextType(t); - inp.type = YAP_STRING_ATOM | YAP_STRING_STRING | YAP_STRING_ATOMS_CODES | - YAP_STRING_TERM; - inp.enc = ENC_ISO_UTF8; - out.enc = ENC_ISO_UTF8; - out.type = YAP_STRING_CHARS; - out.val.c = NULL; - if (!Yap_CVT_Text(&inp, &out PASS_REGS)) - return NULL; - return out.val.c; -} /** * Convert from a predicate structure to an UTF-8 string of the form diff --git a/C/yap-args.c b/C/yap-args.c index d3d74c9e1..9efbace59 100755 --- a/C/yap-args.c +++ b/C/yap-args.c @@ -496,11 +496,7 @@ X_API YAP_file_type_t YAP_parse_yap_arguments(int argc, char *argv[], } else if (!strncmp("-home=", p, strlen("-home="))) { GLOBAL_Home = p + strlen("-home="); } else if (!strncmp("-cwd=", p, strlen("-cwd="))) { -#if __WINDOWS__ - if (_chdir(p + strlen("-cwd=")) < 0) { -#else - if (chdir(p + strlen("-cwd=")) < 0) { -#endif + if (!ChDir(p + strlen("-cwd=")) ) { fprintf(stderr, " [ YAP unrecoverable error in setting cwd: %s ]\n", strerror(errno)); } diff --git a/CMakeLists.txt b/CMakeLists.txt index ad6982a9e..4935f2648 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -249,9 +249,6 @@ if (APPLE) endif () endif () -if (ANDROID) - set(datarootdir /assets) -endif () set(prefix ${CMAKE_INSTALL_PREFIX}) #BINDIR}) set(bindir ${CMAKE_INSTALL_PREFIX}/bin) #BINDIR}) set(includedir ${CMAKE_INSTALL_PREFIX}/include) #INCLUDEDIR}) @@ -259,6 +256,10 @@ set(libdir ${CMAKE_INSTALL_PREFIX}/lib) #LIBDIR}) set(exec_prefix ${CMAKE_INSTALL_PREFIX}/libexec) #LIBEXECDIR}) set(datarootdir ${CMAKE_INSTALL_PREFIX}/share) #DATAROOTDIR}) set(datadir ${CMAKE_INSTALL_PREFIX}/share) #DATADIR}) +if (ANDROID) + set(datarootdir ${YAP_APP_DIR}/src/generated/assets) + set(datadir ${YAP_APP_DIR}/src/generated/assets) +endif () set(mandir ${CMAKE_INSTALL_PREFIX}/share/man) #MANDIR}) set(docdir ${CMAKE_INSTALL_PREFIX}/share/docs) #MANDIR}) @@ -458,7 +459,7 @@ endif () OPTION(WITH_SWIG " Enable SWIG interfaces to foreign languages" ON) -IF (WITH_SWIG OR ANDROID) +IF (WITH_SWIG) find_host_package(SWIG) # macro_log_feature (SWIG_FOUND "Swig" # "Use SWIG Interface Generator " @@ -614,11 +615,6 @@ ADD_SUBDIRECTORY(library) ADD_SUBDIRECTORY(swi/library "swiLibrary") -if (ANDROID) - target_link_libraries(libYap android log) - -endif () - set_target_properties(libYap PROPERTIES OUTPUT_NAME Yap ) @@ -638,8 +634,9 @@ if (PYTHONLIBS_FOUND AND SWIG_FOUND) endif () -IF (SWIG_FOUND OR ANDROID) - add_subDIRECTORY(packages/swig NO_POLICY_SCOPE) +IF ( ANDROID) + add_subDIRECTORY(packages/swig ) + target_link_libraries(libYap android log) ENDIF () @@ -801,9 +798,11 @@ CMAKE_DEPENDENT_OPTION(WITH_SYSTEM_MMAP "Use MMAP for shared memory allocation" CMAKE_DEPENDENT_OPTION(WITH_SYSTEM_SHM "Use SHM for shared memory allocation" ON "NOT WITH_YAPOR_THOR; NOT WITH_SYSTEM_MMAP" OFF) +if (NOT ANDROID) + add_subDIRECTORY(library/lammpi) -if (MPI_C_FOUND) +if (MPI_C_FOUND\D) CMAKE_DEPENDENT_OPTION(WITH_MPI ON "Interface to OpenMPI/MPICH" "MPI_C_FOUND" OFF) @@ -822,6 +821,8 @@ if (MPI_C_FOUND) endif () endif (MPI_C_FOUND) +endif(NOT ANDROID) + ## add_subDIRECTORY(utils) # diff --git a/CXX/yapi.cpp b/CXX/yapi.cpp index 2c7a8ae65..d4fba99d0 100644 --- a/CXX/yapi.cpp +++ b/CXX/yapi.cpp @@ -625,7 +625,7 @@ Term YAPEngine::fun(Term t) return 0; } DBTerm *pt = Yap_StoreTermInDB(Yap_GetFromSlot(o), arity); - __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "out %ld", o); + __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "out %d", o); YAP_LeaveGoal(false, &q); Yap_CloseHandles(q.CurSlot); Term rc = Yap_PopTermFromDB(pt); @@ -751,8 +751,8 @@ bool YAPQuery::next() } if (result) { - __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "vnames %d %s %ld", - q_state, vnames.text(), LOCAL_CurSlot); + __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "vnames %d %s %d", + q_state, names.text(), LOCAL_CurSlot); } else { @@ -892,6 +892,8 @@ static size_t Yap_AndroidMax, Yap_AndroidSz; extern void (*Yap_DisplayWithJava)(int c); +static YAPCallback *cb = new YAPCallback(); + void Yap_displayWithJava(int c) { char *ptr = Yap_AndroidBufp; @@ -914,11 +916,12 @@ void Yap_displayWithJava(int c) if (c == '\n') { Yap_AndroidBufp[Yap_AndroidSz] = '\0'; - curren->run(Yap_AndroidBufp); + cb->run(Yap_AndroidBufp); Yap_AndroidSz = 0; } } + #endif @@ -945,14 +948,14 @@ void YAPEngine::doInit(YAP_file_type_t BootMode) YAPQuery initq = YAPQuery(YAPPredicate(p), nullptr); if (initq.next()) { - initq.cut(); + initq.cut(); } CurrentModule = TermUser; } YAPEngine::YAPEngine(int argc, char *argv[], - YAPCallback *cb) + YAPCallback *cb) : _callback(0) { // a single engine can be active YAP_file_type_t BootMode; @@ -961,10 +964,13 @@ YAPEngine::YAPEngine(int argc, char *argv[], // delYAPCallback()b // if (cb) // setYAPCallback(cb); - doInit(BootMode); + + doInit(BootMode); } + + YAPPredicate::YAPPredicate(YAPAtom at) { CACHE_REGS diff --git a/CXX/yapq.hh b/CXX/yapq.hh index 6b90e6646..0d1cfb849 100644 --- a/CXX/yapq.hh +++ b/CXX/yapq.hh @@ -25,6 +25,10 @@ class X_API YAPPredicate; Queries and engines */ +#if __ANDROID__ + +#endif + /** * @brief Queries * @@ -94,11 +98,11 @@ YAPQuery() { inline YAPQuery(const char *s) : YAPPredicate(s, tgoal, tnames) { CELL *qt = nullptr; - __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "got game %ld", + __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "got game %d", LOCAL_CurSlot); if (!ap) return; - __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "%s", vnames.text()); + __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "%s", names.text()); goal = YAPTerm(tgoal); if (IsPairTerm(tgoal)) { qt = RepPair(tgoal); @@ -151,6 +155,7 @@ void close(); /// query variables. void cut(); Term namedVars() {return names.term(); }; +YAPPairTerm namedVarTerms() {return names; }; /// query variables, but copied out std::vector namedVarsVector() { return names.listToArray(); }; @@ -312,10 +317,18 @@ public: init_args.FastBoot = fl; }; - inline bool getFastBoot( ) - { - return init_args.FastBoot; - }; + inline bool getFastBoot( ) + { + return init_args.FastBoot; + }; + +#if __ANDROID__ + //> export ResoourceManager + inline void setAssetManager( AAssetManager *mgr ) + { + init_args.assetManager = mgr; + }; +#endif inline void setArgc( int fl ) { diff --git a/CXX/yapt.hh b/CXX/yapt.hh index 14818c2f3..f3ce6f5b7 100644 --- a/CXX/yapt.hh +++ b/CXX/yapt.hh @@ -112,7 +112,18 @@ public: inline Term term() { return gt(); } /// from YAPTerm to Term (internal YAP representation) - inline void bind(Term b) { LOCAL_HandleBase[t] = b; } + YAPTerm arg(int i) { + BACKUP_MACHINE_REGS(); + Term t0 = gt(); + YAPTerm tf; + if (!IsApplTerm(t0) && !IsPairTerm(t)) + return (Term)0; + tf = YAPTerm(ArgOfTerm(i, t0) ); + RECOVER_MACHINE_REGS(); + return tf; + }; + + inline void bind(Term b) { LOCAL_HandleBase[t] = b; } inline void bind(YAPTerm *b) { LOCAL_HandleBase[t] = b->term(); } /// from YAPTerm to Term (internal YAP representation) /// fetch a sub-term @@ -324,7 +335,7 @@ public: RECOVER_MACHINE_REGS(); return tf; }; - virtual bool isVar() { return false; } /// type check for unbound + virtual bool isVar() { return false; } /// type check for unbound virtual bool isAtom() { return false; } /// type check for atom virtual bool isInteger() { return false; } /// type check for integer virtual bool isFloat() { return false; } /// type check for floating-point @@ -354,6 +365,9 @@ public: YAPPairTerm(); Term getHead() { return (HeadOfTerm(gt())); } Term getTail() { return (TailOfTerm(gt())); } + YAPTerm car() { return YAPTerm(HeadOfTerm(gt())); } + bool nil() { return gt() == TermNil; } + YAPPairTerm cdr() { return YAPPairTerm(TailOfTerm(gt())); } std::vector listToArray() { Term *tailp; Term t1 = gt(); diff --git a/H/YapText.h b/H/YapText.h index e566894a4..e99edc6a0 100644 --- a/H/YapText.h +++ b/H/YapText.h @@ -1433,6 +1433,38 @@ static inline void Yap_OverwriteUTF8BufferToLowCase(void *buf USES_REGS) { } } +/** + * Function to convert a generic text term (string, atom, list of codes, list + of< + atoms) into a buff + er. + * + * @param t the term + * @param buf the buffer, if NULL a buffer is malloced, and the user should + reclai it + * @param len buffer size + * @param enc encoding (UTF-8 is strongly recommended) + * + * @return the buffer, or NULL in case of failure. If so, Yap_Error may be + called. + * + * notice that it must be called from a push memory. +*/ +static inline const char *Yap_TextTermToText(Term t0 USES_REGS) { + seq_tv_t inp, out; + + inp.val.t = t0; + inp.type = YAP_STRING_ATOM | YAP_STRING_STRING | YAP_STRING_CODES | + YAP_STRING_ATOMS_CODES | YAP_STRING_MALLOC; + out.val.uc = NULL; + out.type = YAP_STRING_CHARS; + out.enc = ENC_ISO_UTF8; + + if (!Yap_CVT_Text(&inp, &out PASS_REGS)) + return NULL; + return out.val.c0; +} + static inline const unsigned char *Yap_TextToUTF8Buffer(Term t0 USES_REGS) { seq_tv_t inp, out; @@ -1444,7 +1476,7 @@ static inline const unsigned char *Yap_TextToUTF8Buffer(Term t0 USES_REGS) { out.enc = ENC_ISO_UTF8; if (!Yap_CVT_Text(&inp, &out PASS_REGS)) - return 0L; + return NULL; return out.val.uc0; } @@ -1642,5 +1674,4 @@ static inline Term Yap_SubtractTailString(Term t1, Term th USES_REGS) { #endif // ≈YAP_TEXT_H -extern const char *Yap_TextTermToText(Term t USES_REGS); extern Term Yap_MkTextTerm(const char *s, int guide USES_REGS); diff --git a/H/Yapproto.h b/H/Yapproto.h index 7ffd5c078..183a4e27c 100755 --- a/H/Yapproto.h +++ b/H/Yapproto.h @@ -306,7 +306,6 @@ extern void Yap_CloseReadline(void); extern bool Yap_InitReadline(Term t); extern void Yap_InitItDeepenPreds(void); extern struct AliasDescS *Yap_InitStandardAliases(void); -extern struct vfs *Yap_InitAssetManager(void); /* load_foreign.c */ extern void Yap_InitLoadForeign(void); @@ -436,6 +435,8 @@ extern const char *Yap_AbsoluteFileInBuffer(const char *spec, char *outp, size_t extern const char *Yap_findFile(const char *isource, const char *idef, const char *root, char *result, bool access, YAP_file_type_t ftype, bool expand_root, bool in_lib); +extern bool ChDir(const char *path); + /* threads.c */ extern void Yap_InitThreadPreds(void); extern void Yap_InitFirstWorkerThreadHandle(void); diff --git a/cmake/FindGMP.cmake b/cmake/FindGMP.cmake index 779234e22..9fa56088c 100644 --- a/cmake/FindGMP.cmake +++ b/cmake/FindGMP.cmake @@ -10,12 +10,27 @@ if (ANDROID) -set( GMP_ROOT ${CMAKE_SOURCE_DIR}/../gmp/${ANDROID_ABI} ) - set (GMP_INCLUDE_DIRS ${GMP_ROOT}) - set (GMP_LIBRARIES ${GMP_ROOT}/libgmp.so) -set (GMP_FOUND ON) - set (GMP_LIBRARIES_DIR ${GMP_ROOT}) -elif(MSVC) + + set( GMP_LOC ${CMAKE_SOURCE_DIR}/../gmp/${ANDROID_ABI} ) + if (EXISTS ${GMP_LOC} ) + message("Looking good for ${GMP_LOC}") + set(GMP_INCLUDE_DIRS ${GMP_LOC} CACHE PATH "include search path") + set(GMP_LIBRARIES ${GMP_LOC}/libgmp.so CACHE FILEPATH "include search path") + set(GMP_LIBRARIES_DIR ${GMP_LOC} CACHE PATH "include search path") + else() + message("Bad call: ${GMP_LOC} does not exist") + endif() +find_path(GMP_INCLUDE_DIRS + NAMES gmp.h + HINTS ${GMP_LOC} + NO_SYSTEM_ENVIRONMENT_PATH) + find_library(GMP_LIBRARIES NAMES gmp + PATHS + ${GMP_ROOT} + NO_SYSTEM_ENVIRONMENT_PATH) + + +elseif(MSVC) find_library(GMP_LIBRARIES NAMES mpir mpird PATHS $ENV{GMP_ROOT} @@ -84,6 +99,7 @@ else() ${GMP_LIBRARIES_DIR}/../include ${GMP_LIBRARIES_DIR} ) + endif() get_filename_component(GMP_LIBRARIES_DIR "${GMP_LIBRARIES}" PATH CACHE) @@ -101,5 +117,4 @@ endif() mark_as_advanced(GMP_LIBRARIES GMP_LIBRARIES_DIR GMP_INCLUDE_DIRS) -endif() diff --git a/include/VFS.h b/include/VFS.h index 28894a957..198339c78 100644 --- a/include/VFS.h +++ b/include/VFS.h @@ -33,6 +33,7 @@ #include + typedef struct { dev_t st_dev; /* ID of device containing file */ mode_t st_mode; /* Mode of file (see below) */ @@ -77,10 +78,9 @@ typedef struct vfs { /// a way to identify a file in this VFS: two special cases, prefix and suffix const char *prefix; const char *suffix; - bool (*id)(struct vfs *me, const char *s); + bool (*chDir)(struct vfs *me, const char *s); /** operations */ - void *(*open)(const char *s, - const char *io_mode); /// open an object + void *(*open)(int sno, const char *fname, const char *io_mode); /// open an object /// in this space, usual w,r,a,b flags plus B (store in a buffer) bool (*close)(int sno); /// close the object int (*get_char)(int sno); /// get an octet to the stream @@ -88,15 +88,15 @@ typedef struct vfs { void (*flush)(int sno); /// flush a stream int64_t (*seek)(int sno, int64_t offset, int whence); /// jump around the stream - void *(*opendir)(const char *s); /// open a directory object, if one exists + void *(*opendir)(struct vfs *,const char *s); /// open a directory object, if one exists const char *(*nextdir)(void *d); /// walk to the next entry in a directory object - void (*closedir)(void *d); + bool (*closedir)(void *d); ; /// close access a directory object bool (*stat)(const char *s, vfs_stat *); /// obtain size, age, permissions of a file. - bool (*isdir)(const char *s); /// verify whether is directory. - bool (*exists)(const char *s); /// verify whether a file exists. - bool (*chdir)(const char *s); /// set working directory (may be virtual). + bool (*isdir)(struct vfs *,const char *s); /// verify whether is directory. + bool (*exists)(struct vfs *, const char *s); /// verify whether a file exists. + bool (*chdir)(struct vfs *,const char *s); /// set working directory (may be virtual). encoding_t enc; /// default file encoded. YAP_Term (*parsers)(int sno); // a set of parsers that can read the // stream and generate a YAP_Term @@ -121,12 +121,15 @@ static inline VFS_t *vfs_owner(const char *fname) { size_t sz0 = strlen(fname), sz; while (me) { - if ((me->vflags & VFS_HAS_PREFIX) && strstr(fname, me->prefix) == fname) + bool p = true; + if ((me->vflags & VFS_HAS_PREFIX) && p) { + const char *r = fname, *s = me->prefix; + while (*s && p) p = *s++ == *r++; + if (p && r > fname+1) return me; + } if (me->vflags & VFS_HAS_SUFFIX && (sz = strlen(me->suffix)) && (d = (sz0 - sz)) >= 0 && - strcmp(fname + d, me->suffix) == 0) - return me; - if (me->vflags & VFS_HAS_FUNCTION && (me->id(me, fname))) { + strcmp(fname + d, me->suffix) == 0) { return me; } me = me->next; diff --git a/include/YapDefs.h b/include/YapDefs.h index 634d40361..f02fc29df 100755 --- a/include/YapDefs.h +++ b/include/YapDefs.h @@ -189,6 +189,11 @@ typedef encoding_t YAP_encoding_t; #endif +#if __ANDROID__ +#include +#include +#endif + typedef struct YAP_thread_attr_struct { size_t ssize; size_t tsize; @@ -322,6 +327,10 @@ typedef struct yap_boot_params { int QuietMode; //> 0, maintain default, > 0 use fd-1, < 0 close int inp, out, err; +#if __ANDROID__ + //> android asset support + AAssetManager *assetManager; +#endif /* support nf's ypp preprocessor code */ #define YAP_MAX_YPP_DEFS 100 char *def_var[YAP_MAX_YPP_DEFS]; diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 7c7c3b500..f39857656 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -76,8 +76,8 @@ MY_add_subdirectory(ytest) add_to_group( LIBRARY_PL pl_library) -if (0) - file(COPY ${LIBRARY_PL} DESTINATION ${libpl}) -else() - install(FILES ${LIBRARY_PL} DESTINATION ${libpl}) -endif() +install(FILES ${LIBRARY_PL} DESTINATION ${libpl}) + +if (ANDROID) +file( INSTALL ${LIBRARY_PL} DESTINATION ${libpl} ) +endif() \ No newline at end of file diff --git a/os/assets.c b/os/assets.c index ace50a1f5..40616e121 100644 --- a/os/assets.c +++ b/os/assets.c @@ -33,107 +33,93 @@ static char SccsId[] = "%W% %G%"; // for native asset manager #include -#if __ANDROID__0 +#if __ANDROID__ +#include +#include -static AAssetManager * getMgr(struct vfs *me) +AAssetManager * Yap_assetManager; + +jboolean Java_pt_up_yap_app_assetAssetManager(JNIEnv* env, jclass clazz, jobject assetManager) { - return me->priv[0].mgr; -} - - -void -Java_pt_up_yap_app_YAPDroid_load(JNIEnv *env, - jobject assetManager) { - - AAssetManager *mgr = AAssetManager_fromJava(env, assetManager); - if (mgr == NULL) { - return; - } - VFS_t *me = GLOBAL_VFS; - while ( strcmp(me->name, "/assets") == 0) - me = me->next; - me->priv[0].mgr = mgr; + Yap_assetManager = AAssetManager_fromJava(env, assetManager); } -static bool -open_asset(struct vfs *me, struct stream_desc *st, const char *fname, const char +static void * +open_asset__ + ( int sno, const char *fname, const char *io_mode) { - AAssetManager *mgr; int mode; const void *buf; + VFS_t *me = GLOBAL_Stream[sno].vfs; if (strstr(fname,"/assets") == fname) { - // we're in - mgr = getMgr(me); - if (mgr == NULL) { - return PlIOError(PERMISSION_ERROR_OPEN_SOURCE_SINK, TermNil, - "asset manager", - fname); - } - if (strchr(io_mode, 'w') || strchr(io_mode, 'a')) { - return PlIOError(PERMISSION_ERROR_OPEN_SOURCE_SINK, TermNil, - "%s: no writing but flags are %s", - fname, io_mode); - } - if (strchr(io_mode, 'B')) - mode = AASSET_MODE_BUFFER; - else - { - mode = AASSET_MODE_UNKNOWN; + // we're in + if ( Yap_assetManager == NULL) { + return PlIOError(PERMISSION_ERROR_OPEN_SOURCE_SINK, TermNil, + "asset manager", + fname); } - AAsset *a = AAssetManager_open(mgr , fname, mode); - // try not to use it as an asset - off64_t sz = AAsset_getLength64(a), sz0 = 0; - int fd; - if ((fd = AAsset_openFileDescriptor64(a, &sz0, &sz)) >= 0) { - // can use it as red-only file - st->file = fdopen( fd, "r"); + if (strchr(io_mode, 'w') || strchr(io_mode, 'a')) { + return PlIOError(PERMISSION_ERROR_OPEN_SOURCE_SINK, TermNil, + "%s: no writing but flags are %s", + fname, io_mode); + } + if (strchr(io_mode, 'B')) + mode = AASSET_MODE_BUFFER; + else { + mode = AASSET_MODE_UNKNOWN; + } + AAsset *a = AAssetManager_open( Yap_assetManager, fname, mode); + // try not to use it as an asset + off64_t sz = AAsset_getLength64(a), sz0 = 0; + int fd; + StreamDesc *st = GLOBAL_Stream+sno; + if ((fd = AAsset_openFileDescriptor64(a, &sz0, &sz)) >= 0) { + // can use it as red-only file + st->file = fdopen(fd, "r"); + st->vfs = me; + st->vfs_handle = a; + return a; + } else if ((buf = AAsset_getBuffer(a))) { + // copy to memory + bool rc = Yap_set_stream_to_buf(st, buf, sz); + AAsset_close(a); + return rc; + } + // should be done, but if not + GLOBAL_Stream[sno].vfs_handle= a; st->vfs = me; - st->vfs_handle = a; return true; - } else if ((buf = AAsset_getBuffer(a)) ) { - // copy to memory - bool rc = Yap_set_stream_to_buf(st, buf, sz); - AAsset_close(a); - return rc; - } - // should be done, but if not - st->vfs_handle = a; - st->vfs = me; - return true; - } - if (me->next) { - return me->next->open(me->next, st, fname, io_mode); } return NULL; } static bool -close_asset(struct stream_desc *st) +close_asset(int sno) { - AAsset_close(st->vfs_handle); + AAsset_close(GLOBAL_Stream[sno].vfs_handle); return true; } -static int64_t seek64(struct stream_desc *st, int64_t offset, int whence) +static int64_t seek64(int sno, int64_t offset, int whence) { - return AAsset_seek64(st->vfs_handle, offset, whence); + return AAsset_seek64(GLOBAL_Stream[sno].vfs_handle, offset, whence); } -static int getc_asset(struct stream_desc *st) +static int getc_asset(int sno) { int ch; - if ( AAsset_read (st->vfs_handle, &ch, 1) ) + if ( AAsset_read (GLOBAL_Stream[sno].vfs_handle, &ch, 1) ) return ch; return -1; } -static void *opendir_a(struct vfs *me, const char *dirName) +static void *opendir_a( VFS_t *me, const char *dirName) { - return (void *)AAssetManager_openDir (getMgr(me), dirName); + return (void *)AAssetManager_openDir (Yap_assetManager, dirName); } static const char *readdir_a(void *dirHandle) @@ -148,10 +134,10 @@ static bool closedir_a(void *dirHandle) } -static bool stat_a(struct vfs *me, const char *fname, vfs_stat *out) +static bool stat_a(VFS_t *me, const char *fname, vfs_stat *out) { - struct stat64 bf; - if (stat64( "/assets", &bf)) { + struct stat bf; + if (stat( "/assets", &bf)) { out->st_dev = bf.st_dev; out->st_uid = bf.st_uid; @@ -161,8 +147,7 @@ static bool stat_a(struct vfs *me, const char *fname, vfs_stat *out) memcpy(&out->st_ctimespec, (const void *)&out->st_ctimespec, sizeof(struct timespec)); memcpy(&out->st_birthtimespec, (const void *)&out->st_birthtimespec, sizeof(struct timespec)); } - AAssetManager *mgr = getMgr(me); - AAsset *a = AAssetManager_open(mgr , fname, AASSET_MODE_UNKNOWN); + AAsset *a = AAssetManager_open( Yap_assetManager , fname, AASSET_MODE_UNKNOWN); // try not to use it as an asset out->st_size = AAsset_getLength64(a); AAsset_close(a); @@ -171,11 +156,11 @@ static bool stat_a(struct vfs *me, const char *fname, vfs_stat *out) } static -bool is_dir_a(struct vfs *me, const char *dirName) +bool is_dir_a( VFS_t *me,const char *dirName) { bool rc; // try not to use it as an asset - AAssetDir *d = AAssetManager_openDir (getMgr(me), dirName); + AAssetDir *d = AAssetManager_openDir ( Yap_assetManager, dirName); if (d == NULL) return false; rc = (AAssetDir_getNextFileName(d) != NULL); @@ -184,10 +169,10 @@ bool is_dir_a(struct vfs *me, const char *dirName) } static -bool exists_a(struct vfs *me, const char *dirName) +bool exists_a(VFS_t *me, const char *dirName) { // try not to use it as an asset - AAsset *d = AAssetManager_open (getMgr(me), dirName, AASSET_MODE_UNKNOWN); + AAsset *d = AAssetManager_open ( Yap_assetManager, dirName, AASSET_MODE_UNKNOWN); if (d == NULL) return false; AAsset_close(d); @@ -195,11 +180,11 @@ bool exists_a(struct vfs *me, const char *dirName) } -static bool set_cwd (struct vfs *me, const char *dirName) { +static bool set_cwd (VFS_t *me, const char *dirName) { chdir("/assets"); if (me->virtual_cwd) - free(me->virtual_cwd); + free((void*)(me->virtual_cwd)); me->virtual_cwd = malloc( sizeof(dirName) + 1 ); return me!= NULL; } @@ -209,21 +194,22 @@ static bool set_cwd (struct vfs *me, const char *dirName) { /* create a new alias arg for stream sno */ VFS_t * -Yap_InitAssetManager(void) +Yap_InitAssetManager( AAssetManager* mgr ) { -#if __ANDROID__O +#if __ANDROID__ VFS_t *me; + Yap_assetManager = mgr; /* init standard VFS */ me = (VFS_t *)Yap_AllocCodeSpace(sizeof(struct vfs)); me->name = "/assets"; me->vflags = VFS_CAN_EXEC|VFS_CAN_SEEK|VFS_HAS_PREFIX; /// the main flags describing the operation of the Fs. me->prefix = "/assets"; /** operations */ - me->open = open_asset; /// open an object in this space + me->open = open_asset__; /// open an object in this space me->close= close_asset; /// close the object me->get_char = getc_asset; /// get an octet to the stream - me->putc = NULL; /// output an octet to the stream + me->put_char = NULL; /// output an octet to the stream me->seek = seek64; /// jump around the stream me->opendir = opendir_a; /// open a directory object, if one exists me->nextdir = readdir_a; /// open a directory object, if one exists diff --git a/os/charsio.c b/os/charsio.c index 507861ea4..e8266a8db 100644 --- a/os/charsio.c +++ b/os/charsio.c @@ -865,7 +865,7 @@ as those for `put` (see 6.11). static Int skip_1(USES_REGS1) { /* 'skip'(N) */ Int n; Term t1; - int sno; + int sno = LOCAL_c_output_stream; int ch; if (IsVarTerm(t1 = Deref(ARG1))) { diff --git a/os/files.c b/os/files.c index f18cc8141..b579d832d 100644 --- a/os/files.c +++ b/os/files.c @@ -25,6 +25,7 @@ static char SccsId[] = "%W% %G%"; */ #include "sysbits.h" +#include "yapio.h" #if _MSC_VER || defined(__MINGW32__) #define SYSTEM_STAT _stat diff --git a/os/iopreds.c b/os/iopreds.c index dbc7b0990..f84738fcb 100644 --- a/os/iopreds.c +++ b/os/iopreds.c @@ -246,20 +246,18 @@ static void unix_upd_stream_info(StreamDesc *s) { void Yap_DefaultStreamOps(StreamDesc *st) { CACHE_REGS - if (st->vfs) { - st->stream_wputc = st->vfs->put_char; - st->stream_wgetc = st->vfs->get_char; - st->stream_putc = st->vfs->put_char; - st->stream_wgetc = st->vfs->get_char; - return; - } st->stream_wputc = put_wchar; if (st->encoding == ENC_ISO_UTF8) st->stream_wgetc = get_wchar_UTF8; else st->stream_wgetc = get_wchar; - st->stream_putc = FilePutc; - st->stream_getc = PlGetc; + if (st->vfs) { + st->stream_putc = st->vfs->put_char; + st->stream_wgetc = st->vfs->get_char; + } else { + st->stream_putc = FilePutc; + st->stream_getc = PlGetc; + } if (st->status & (Promptable_Stream_f)) { Yap_ConsoleOps(st); } @@ -300,7 +298,7 @@ static void InitStdStream(int sno, SMALLUNSGN flags, FILE *file, VFS_t *vfsp) { INIT_LOCK(s->streamlock); if (vfsp != NULL) { s->u.private_data = - vfsp->open(vfsp->name, (sno == StdInStream ? "read" : "write")); + vfsp->open(sno, vfsp->name, (sno == StdInStream ? "read" : "write")); if (s->u.private_data == NULL) { (PlIOError(EXISTENCE_ERROR_SOURCE_SINK, MkIntTerm(sno), "%s", vfsp->name)); @@ -1312,7 +1310,7 @@ do_open(Term file_name, Term t2, } struct vfs *vfsp = NULL; if ((vfsp = vfs_owner(fname)) != NULL) { - st->u.private_data = vfsp->open(fname, io_mode); + st->u.private_data = vfsp->open(sno, fname, io_mode); fd = NULL; if (st->u.private_data == NULL) return (PlIOError(EXISTENCE_ERROR_SOURCE_SINK, file_name, "%s", fname)); @@ -1869,8 +1867,11 @@ static Int get_abs_file_parameter(USES_REGS1) { void Yap_InitPlIO(struct yap_boot_params *argi) { Int i; - - if (argi->inp > 0) +#if __ANDROID__ + if (argi->assetManager) + Yap_InitAssetManager( argi->assetManager ); +#endif + if (argi->inp > 0) Yap_stdin = fdopen(argi->inp - 1, "r"); else if (argi->inp) Yap_stdin = NULL; diff --git a/os/iopreds.h b/os/iopreds.h index 7d40ba5b9..5186ddaf3 100644 --- a/os/iopreds.h +++ b/os/iopreds.h @@ -285,6 +285,6 @@ static inline void freeBuffer(const void *ptr) { /** VFS handling */ -VFS_t *Yap_InitAssetManager(void); +VFS_t *Yap_InitAssetManager(AAssetManager *mgr); #endif diff --git a/os/mem.c b/os/mem.c index 66994073a..7e6988073 100644 --- a/os/mem.c +++ b/os/mem.c @@ -24,7 +24,7 @@ static char SccsId[] = "%W% %G%"; */ #include "sysbits.h" - +#include "YapStreams.h" #if !HAVE_FMEMOPEN || !defined(HAVE_FMEMOPEN) @@ -180,7 +180,7 @@ static int MemPutc(int sno, int ch) { return ((int)ch); } -bool Yap_set_stream_to_buf(StreamDesc *st, const char *buf, size_t nchars) { +bool Yap_set_stream_to_buf(StreamDesc *st, const char *buf, size_t nchars USES_REGS) { FILE *f; stream_flags_t flags; @@ -241,14 +241,15 @@ open_mem_read_stream(USES_REGS1) /* $open_mem_read_stream(+List,-Stream) */ { Term t, ti; int sno; - char buf0[YAP_FILENAME_MAX + 1]; + int i = push_text_stack(); const char *buf; ti = Deref(ARG1); - buf = Yap_TextTermToText(ti, buf0, 0, LOCAL_encoding); + buf = Yap_TextTermToText(ti PASS_REGS); if (!buf) { return false; } + buf = pop_output_text_stack(i, buf); sno = Yap_open_buf_read_stream(buf, strlen(buf) + 1, &LOCAL_encoding, MEM_BUF_MALLOC); t = Yap_MkStream(sno); diff --git a/os/sysbits.c b/os/sysbits.c index f671e8c7a..112cc1c11 100644 --- a/os/sysbits.c +++ b/os/sysbits.c @@ -79,7 +79,7 @@ static bool is_directory(const char *FileName) { VFS_t *vfs; if ((vfs = vfs_owner(FileName))) { - return vfs->isdir(FileName); + return vfs->isdir(vfs,FileName); } #ifdef _WIN32 DWORD dwAtts = GetFileAttributes(FileName); @@ -102,10 +102,13 @@ static bool is_directory(const char *FileName) { } bool Yap_Exists(const char *f) { - VFS_t *vfs; + VFS_t *vfs = GLOBAL_VFS; - if ((vfs = vfs_owner(f))) { - return vfs->exists(f); + while(vfs) { + VFS_t *n=vfs->exists(vfs,f); + if (n==vfs) return true; + if (!n) return false; + vfs = n; } #if _WIN32 if (_access(f, 0) == 0) @@ -341,14 +344,14 @@ static char *PrologPath(const char *Y, char *X) { return (char *)Y; } #define HAVE_REALPATH 1 #endif -static bool ChDir(const char *path) { + bool ChDir(const char *path) { bool rc = false; char qp[FILENAME_MAX + 1]; const char *qpath = Yap_AbsoluteFile(path, qp, true); VFS_t *v; if ((v = vfs_owner(path))) { - return v->chdir(path); + return v->chdir(v, path); } #if _WIN32 rc = true; @@ -1242,7 +1245,8 @@ const char *Yap_findFile(const char *isource, const char *idef, if (ftype == YAP_PL) { root = YAP_SHAREDIR; } else if (ftype == YAP_BOOT_PL) { - root = YAP_SHAREDIR; + root = malloc(YAP_FILENAME_MAX+1); + strcpy(root, YAP_SHAREDIR); strcat(root,"/pl"); } else { root = YAP_LIBDIR; diff --git a/os/yapio.h b/os/yapio.h index d8f2827ee..9a19e1a20 100644 --- a/os/yapio.h +++ b/os/yapio.h @@ -22,6 +22,8 @@ #undef HAVE_LIBREADLINE #endif +#include "YapStreams.h" + #include #include @@ -108,8 +110,6 @@ extern Term Yap_StringToNumberTerm(const char *s, encoding_t *encp, extern int Yap_FormatFloat(Float f, char **s, size_t sz); extern int Yap_open_buf_read_stream(const char *buf, size_t nchars, encoding_t *encp, memBufSource src); -extern bool Yap_set_stream_to_buf(struct stream_desc *st, const char *buf, - encoding_t enc, size_t nchars); extern int Yap_open_buf_write_stream(encoding_t enc, memBufSource src); extern Term Yap_BufferToTerm(const unsigned char *s, Term opts); extern X_API Term Yap_BufferToTermWithPrioBindings(const unsigned char *s, @@ -151,4 +151,8 @@ INLINE_ONLY inline EXTERN Term MkCharTerm(Int c) { extern uint64_t Yap_StartOfWTimes; extern bool Yap_HandleSIGINT(void); + + +extern bool Yap_set_stream_to_buf(StreamDesc *st, const char *buf, size_t nchars USES_REGS); + #endif diff --git a/packages/CLPBN/clpbn/horus.yap b/packages/CLPBN/clpbn/horus.yap index 03d5662ff..261f69088 100644 --- a/packages/CLPBN/clpbn/horus.yap +++ b/packages/CLPBN/clpbn/horus.yap @@ -19,7 +19,7 @@ ]). -:- catch(load_foreign_files([horus], [], init_predicates), _, patch_things_up) +:- catch(load_foreign_files([libhorus], [], init_predicates), _, patch_things_up) -> true ; warning. diff --git a/packages/CLPBN/horus/CMakeLists.txt b/packages/CLPBN/horus/CMakeLists.txt index 2723127cd..e8dcf3c8f 100644 --- a/packages/CLPBN/horus/CMakeLists.txt +++ b/packages/CLPBN/horus/CMakeLists.txt @@ -58,7 +58,7 @@ if (CMAKE_MAJOR_VERSION GREATER 2) #set_property(TARGET horus PROPERTY CXX_STANDARD 11) #set_property(TARGET horus PROPERTY CXX_STANDARD_REQUIRED ON) - set_target_properties (horus PROPERTIES PREFIX "" CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON) + set_target_properties (horus PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON) add_executable (HorusCli HorusCli.cpp) diff --git a/packages/bdd/CMakeLists.txt b/packages/bdd/CMakeLists.txt index 4b4e44d34..e2d1d9039 100644 --- a/packages/bdd/CMakeLists.txt +++ b/packages/bdd/CMakeLists.txt @@ -46,9 +46,7 @@ IF (CUDD_FOUND) ) endif() - set_target_properties (cudd PROPERTIES PREFIX "") - - add_subdirectory(simplecudd) + add_subdirectory(simplecudd) add_subdirectory(simplecudd_lfi) set(YAP_SYSTEM_OPTIONS "cudd " ${YAP_SYSTEM_OPTIONS} PARENT_SCOPE) diff --git a/packages/bdd/bdd.yap b/packages/bdd/bdd.yap index 0544f263d..a2ed5bb1c 100644 --- a/packages/bdd/bdd.yap +++ b/packages/bdd/bdd.yap @@ -52,7 +52,7 @@ The following predicates construct a BDD: tell_warning :- print_message(warning,functionality(cudd)). -:- catch(load_foreign_files([cudd], [], init_cudd),_,fail) -> true ; tell_warning. +:- catch(load_foreign_files([libcudd], [], init_cudd),_,fail) -> true ; tell_warning. /** @pred bdd_new(? _Exp_, - _BddHandle_) diff --git a/packages/myddas/pl/CMakeLists.txt b/packages/myddas/pl/CMakeLists.txt index 6456b54f2..7990e261e 100644 --- a/packages/myddas/pl/CMakeLists.txt +++ b/packages/myddas/pl/CMakeLists.txt @@ -11,18 +11,19 @@ set(MYDDAS_YPP set(MYDDAS_DRIVERS "myddas_driver.ypp" ) -message("libpl ${libpl}") -if (0) - set (PREFIX ${libpl} ) + + + if (ANDROID) + set (MYDDAS_PREFIX ${libpl} ) else() - set (PREFIX ${CMAKE_CURRENT_BINARY_DIR} ) + set (MYDDAS_PREFIX ${CMAKE_CURRENT_BINARY_DIR} ) endif() get_property(MYDDAS_FLAGS GLOBAL PROPERTY COMPILE_DEFINITIONS) function(cpp_compile output filename) get_filename_component(base ${filename} NAME_WE) - set(base_abs ${PREFIX}/${base}) + set(base_abs ${MYDDAS_PREFIX}/${base}) set(outfile ${base_abs}.yap) set(${output} ${${output}} ${outfile} PARENT_SCOPE) IF (MSVC) @@ -40,17 +41,13 @@ function(cpp_compile output filename) endfunction() if (ANDROID) -set (MYDDAS_PL_OUTDIR ${YAP_APP_DIR}/src/generated/assets/Yap} ) +set (MYDDAS_PL_OUTDIR ${YAP_APP_DIR}/src/generated/assets/Yap ) else() set (MYDDAS_PL_OUTDIR ${CMAKE_CURRENT_BINARY_DIR} ) endif() function(cpp_driver output dbms filename) - if (0) - set(outfile ${MYDDAS_PL_OUTDIR}/myddas_${dbms}.yap) - else() - set(outfile ${MYDDAS_PL_OUTDIR}/myddas_${dbms}.yap) - endif() + set(outfile ${MYDDAS_PL_OUTDIR}/myddas_${dbms}.yap) set(${output} ${${output}} ${outfile} PARENT_SCOPE) IF (MSVC) add_custom_command( diff --git a/packages/myddas/pl/myddas_driver.ypp b/packages/myddas/pl/myddas_driver.ypp index 40c3ad71b..ab14beeca 100644 --- a/packages/myddas/pl/myddas_driver.ypp +++ b/packages/myddas/pl/myddas_driver.ypp @@ -18,21 +18,21 @@ #undef sqlite3 #define DBMS(x) sqlite3_##x #define c_DBMS(x) c_sqlite3_##x -#define NAME() 'Yapsqlite3' +#define NAME() 'libYapsqlite3' #define MODULE() myddas_sqlite3 #define INIT() init_sqlite3 #elif defined( odbc ) #undef odbc #define DBMS(x) odbc_##x #define c_DBMS(x) c_odbc_##x -#define NAME() 'Yapodbc' +#define NAME() 'libYapodbc' #define MODULE() myddas_odbc #define INIT() init_odbc #elif defined( postgres ) #undef postgres #define DBMS(x) postgres_##x #define c_DBMS(x) c_postgres_##x -#define NAME() 'Yappostgres' +#define NAME() 'libYappostgres' #define MODULE() myddas_postgres #define INIT() init_odbc #endif diff --git a/packages/myddas/sqlite3/CMakeLists.txt b/packages/myddas/sqlite3/CMakeLists.txt index 91c76b649..c069ab12f 100644 --- a/packages/myddas/sqlite3/CMakeLists.txt +++ b/packages/myddas/sqlite3/CMakeLists.txt @@ -60,7 +60,6 @@ set_target_properties(Yapsqlite3 # RPATH ${libdir} VERSION ${LIBYAPTAI_FULL_VERSION} # SOVERSION ${LIBYAPTAI_MAJOR_VERSION}.${LIBYAPTAI_MINOR_VERSION} POSITION_INDEPENDENT_CODE TRUE - PREFIX "" ) target_link_libraries(Yapsqlite3 libYap) diff --git a/packages/swig/android/CMakeLists.txt b/packages/swig/android/CMakeLists.txt index 95f8d281c..95a1275d0 100644 --- a/packages/swig/android/CMakeLists.txt +++ b/packages/swig/android/CMakeLists.txt @@ -1,72 +1,73 @@ +include (UseSWIG) + +INCLUDE_DIRECTORIES( + ../../../H + ../../../H/generated + ../../../OPTYap + ../../../include + ../../../CXX + . + .. + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_SOURCE_DIR} + ) + +set_property(GLOBAL + APPEND PROPERTY + COMPILE_DEFINITIONS + -Dmmap=mmap64) + # This is a CMake file for SWIG and Android -FILE( MAKE_DIRECTORY ${YAP_APP_DIR}/src/generated/java/pt/up/yap/lib ) -FILE( MAKE_DIRECTORY ${YAP_APP_DIR}/src/generated/assets) set(CMAKE_SWIG_OUTDIR ${YAP_APP_DIR}/src/generated/java/pt/up/yap/lib ) - set( SWIG_MODULE_NAME pt.up.yap.lib ) - set ( pllib ${YAP_APP_DIR}/src/generated/assets/Yap ) - set ( SWIG_SOURCES ${CMAKE_SOURCE_DIR}/packages/swig/yap.i ) - SET_SOURCE_FILES_PROPERTIES(${SWIG_SOURCES} PROPERTIES CPLUSPLUS ON) +FILE( MAKE_DIRECTORY ${YAP_APP_DIR}/src/generated/assets) +FILE( MAKE_DIRECTORY ${CMAKE_SWIG_OUTDIR}) + set(SWIG_OUTFILE_DIR ${CMAKE_CURRENT_BINARY_DIR} ) + set_property(SOURCE ../yap.i PROPERTY CPLUSPLUS ON) + SET_SOURCE_FILES_PROPERTIES(../yap.i PROPERTIES SWIG_FLAGS "-O;-package;pt.up.yap.lib;-D__ANDROID__=1") - include_directories ( - ${CMAKE_SOURCE_DIR}/CXX - ) - set( GMP_ROOT ${CMAKE_SOURCE_DIR}/../gmp/${ANDROID_ABI} ) - set (GMP_INCLUDE_DIRS ${GMP_ROOT}) - set (GMP_LIBRARIES ${GMP_ROOT}/libgmp.so) + set( SWIG_PACKAGE_NAME pt.up.yap.lib ) + +set (SWIG_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/../yap.i ) - add_custom_command (OUTPUT yap_swig.cpp - COMMAND ${CMAKE_COMMAND} -E make_directory ${pllib} - COMMAND ${CMAKE_COMMAND} -E make_directory ${pllib}/pl - COMMAND ${CMAKE_COMMAND} -E make_directory ${pllib}/os + add_custom_command( OUTPUT ${SWIG_OUTFILE_DIR}/yapJAVA.cxx + COMMAND ${SWIG_EXECUTABLE} -c++ -java -O -package "pt.up.yap.lib" -I${CMAKE_SOURCE_DIR}/H -I${CMAKE_SOURCE_DIR}/H/generated -I${CMAKE_SOURCE_DIR}/include + -I${CMAKE_SOURCE_DIR}/OPTYap -I${CMAKE_SOURCE_DIR}/os -I${CMAKE_SOURCE_DIR}/utf8proc -I.././.. -I${CMAKE_SOURCE_DIR}/CXX -I${CMAKE_SOURCE_DIR}/packages/python + -outdir ${CMAKE_SWIG_OUTDIR} -I${GMP_INCLUDE_DIRS} -D__ANDROID__=1 -DX_API="" -o ${SWIG_OUTFILE_DIR}/yapJAVA.cxx -oh ${SWIG_OUTFILE_DIR}/yapJAVA.hh ${CMAKE_CURRENT_SOURCE_DIR}/../yap.i + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + DEPENDS ${SWIG_SOURCES} + ) - COMMAND ${CMAKE_COMMAND} -E copy ${pl_library} ${pllib} - COMMAND ${CMAKE_COMMAND} -E copy ${pl_boot_library} ${pllib}/pl - COMMAND ${CMAKE_COMMAND} -E copy ${pl_os_library} ${pllib}/os - COMMAND ${SWIG_EXECUTABLE} -c++ -java -package ${SWIG_MODULE_NAME} -outdir ${CMAKE_SWIG_OUTDIR} -outcurrentdir -addextern -I${CMAKE_SOURCE_DIR}/CXX -I${CMAKE_SOURCE_DIR}/include -I${CMAKE_SOURCE_DIR}/H -I${CMAKE_SOURCE_DIR}/os -I${CMAKE_SOURCE_DIR}/OPTYap -I${CMAKE_BINARY_DIR} -I${GMP_INCLUDE_DIRS} -DX_API="" -o yap_swig.cpp ${SWIG_SOURCES} - DEPENDS ${SWIG_SOURCES} YAP++ - ) +ADD_LIBRARY(YAPJava + SHARED + ${SWIG_OUTFILE_DIR}/yapJAVA.cxx + ) - add_custom_command (OUTPUT swig_streamer.cpp - COMMAND ${SWIG_EXECUTABLE} -c++ -java -package ${SWIG_MODULE_NAME} -outdir ${CMAKE_SWIG_OUTDIR} -outcurrentdir -addextern -I${CMAKE_CURRENT_SOURCE_DIR} -o swig_streamer.cpp streamer.i - DEPENDS streamer.i - ) +target_link_libraries(YAPJava YAP++ libYap android log) + + set_property(SOURCE streamer.i PROPERTY CPLUSPLUS ON) + SET_SOURCE_FILES_PROPERTIES(streamer.i PROPERTIES SWIG_FLAGS "-O;-package;pt.up.yap.lib;-D__ANDROID__=1") - # GMP_FOUND - true if GMP/MPIR was found - # GMP_INCLUDE_DIRS - include search path - # GMP_LIBRARIES - libraries to link with - #config.h needs this (TODO: change in code latter) - include_directories( .;${GMP_INCLUDE_DIRS};${CMAKE_SOURCE_DIR}/include;${CMAKE_SOURCE_DIR}/H;${CMAKE_SOURCE_DIR}/H/generated;${CMAKE_SOURCE_DIR}/os;${CMAKE_SOURCE_DIR}/OPTYap;${CMAKE_BINARY_DIR};${CMAKE_CURRENT_SOURCE_DIR} ) +set (SWIG_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/streamer.i) + add_custom_command( OUTPUT ${SWIG_OUTFILE_DIR}/streamerJAVA.cxx + COMMAND ${SWIG_EXECUTABLE} -c++ -java -O -package "pt.up.yap.lib" -O -I${CMAKE_SOURCE_DIR}/H -I${CMAKE_SOURCE_DIR}/H/generated -I${CMAKE_SOURCE_DIR}/include + -I${CMAKE_SOURCE_DIR}/OPTYap -I${CMAKE_SOURCE_DIR}/os -I${CMAKE_SOURCE_DIR}/utf8proc -I.././.. -I${CMAKE_SOURCE_DIR}/CXX -I${CMAKE_SOURCE_DIR}/packages/python + -outdir ${CMAKE_SWIG_OUTDIR} -I${GMP_INCLUDE_DIRS} -D__ANDROID__=1 -DX_API="" -o ${SWIG_OUTFILE_DIR}/streamerJAVA.cxx -oh ${SWIG_OUTFILE_DIR}/streamerJAVA.hh ${CMAKE_CURRENT_SOURCE_DIR}/streamer.i + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + DEPENDS ${SWIG_SOURCES} + ) - add_lib(YAPJava - yap_swig.cpp swig_streamer.cpp streamer.cpp streamer.h - ) - target_link_libraries(YAPJava ${GMP_LIBRARIES} ) +ADD_LIBRARY(YAPStreamer + SHARED # [TYPE ] + ${CMAKE_CURRENT_SOURCE_DIR}/streamer.cpp ${SWIG_OUTFILE_DIR}/streamerJAVA.cxx + ) +target_link_libraries(YAPStreamer YAP++ libYap android log) - target_link_libraries( YAPJava YAP++ libYap android log) - - if (FALSE) - - set (SWIG_ADD_MODULE YAPJava SHARED CPLUPLUS ${SWIG_SOURCES} ) - # Define swig module with given name and specified language - - - set (SWIG_LINK_LIBRARIES YAPJava YAP++ libYAP ) - #- Link libraries to swig module - - - add_library (YAPJavaTop SHARED - main.cpp main.h - ) - - target_link_libraries( YAPJavaTop ${SWIG_MODULE_${YAPJava}_REAL_NAME} YAP++ libYap android) - - endif() diff --git a/packages/swig/yap.i b/packages/swig/yap.i index 3bd39b175..ca5af193a 100644 --- a/packages/swig/yap.i +++ b/packages/swig/yap.i @@ -285,346 +285,6 @@ class YAPEngine; #if THREADS #define Yap_regp regcache - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #endif // we cannot consult YapInterface.h, that conflicts with what we @@ -661,6 +321,7 @@ class YAPEngine; //%feature("novaluewrapper") vector; + }; %init %{ diff --git a/pl/CMakeLists.txt b/pl/CMakeLists.txt index c4fa9466f..484fd912d 100644 --- a/pl/CMakeLists.txt +++ b/pl/CMakeLists.txt @@ -58,7 +58,12 @@ set(PL_BOOT_SOURCES add_to_group(PL_BOOT_SOURCES pl_boot_library) -if (CMAKE_CROSSCOMPILING) +if (ANDROID) + add_custom_target(STARTUP + DEPENDS ${PL_BOOT_SOURCES} + ) + file (INSTALL ${PL_BOOT_SOURCES} DESTINATION ${libpl}/pl) +elseif(CMAKE_CROSSCOMPILING) add_custom_target(STARTUP ALL SOURCES DEPENDS ${PL_BOOT_SOURCES} ) @@ -67,7 +72,6 @@ else () DEPENDS ${CMAKE_TOP_BINARY_DIR}/${YAP_STARTUP} ) add_custom_command(OUTPUT ${CMAKE_TOP_BINARY_DIR}/${YAP_STARTUP} - COMMAND ldd yap COMMAND ./yap -B VERBATIM WORKING_DIRECTORY ${CMAKE_TOP_BINARY_DIR} @@ -79,7 +83,7 @@ install(FILES ${CMAKE_TOP_BINARY_DIR}/${YAP_STARTUP} ) endif() + install(FILES ${PL_SOURCES} DESTINATION ${libpl}/pl ) -