Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 62 additions & 14 deletions config.m4
Original file line number Diff line number Diff line change
@@ -1,20 +1,68 @@
PHP_ARG_WITH(phplpsolve55,[lpsolve 5.5]
[ with-phplpsolve55=[Insert path to lp_solve here] Include lpsolve Support])
PHP_ARG_WITH(phplpsolve55, for liblpsolve55,
[ --with-phplpsolve55=DIR Installation prefix of liblpsolve55.
If DIR is not specified, use the system library.])

if test $PHP_PHPLPSOLVE55 != "no"; then
if test -f "$PHP_PHPLPSOLVE55/lp_lib.h"; then
PHP_CHECK_LIBRARY(lpsolve55, make_lp,,[AC_MSG_ERROR([Invalid phplpsolve55 library, make_lp() not found])],-L/usr/lib)
else
dnl This will cancel configuration if the required headers aren't found
AC_MSG_ERROR([lp_lib.h not found])
EXTRA_LIBS="-lm"
AC_CHECK_LIB(dl, dlopen, [
EXTRA_LIBS="$EXTRA_LIBS -ldl"
PHP_ADD_LIBRARY(dl, 1, PHPLPSOLVE55_SHARED_LIBADD)
])
AC_CHECK_LIB(colamd, colamd, [
EXTRA_LIBS="$EXTRA_LIBS -lcolamd"
])
dnl Find the header file:
AC_MSG_CHECKING([for lp_lib.h])
for i in $PHP_PHPLPSOLVE55 /usr/include/lpsolve /usr/local/include/lpsolve; do
if test -r "$i/lp_lib.h"; then
LIBLPSOLVE_INCDIR="$i"
AC_MSG_RESULT($i)
break
fi
done

if test -z "$LIBLPSOLVE_INCDIR"; then
AC_MSG_RESULT([not found])
AC_MSG_ERROR([Could not find lp_lib.h])
fi

PHP_ADD_LIBRARY_WITH_PATH(lpsolve55, /usr/local/lib, PHPLPSOLVE55_SHARED_LIBADD)
PHP_ADD_INCLUDE($PHP_PHPLPSOLVE55)
AC_MSG_RESULT([lpsolve in $PHP_PHPLPSOLVE55])
AC_DEFINE(PHP,1,[liblpsolve55 found and included])
dnl Find the shared library:
LDFLAGS="-Wl,--no-as-needed"
for i in /usr/local/lib /usr/lib /lib; do
for j in lpsolve55_pic lpsolve55; do
if test -r "$i/lib$j.so"; then
PHP_CHECK_LIBRARY($j, make_lp,[
PHP_ADD_LIBRARY_WITH_PATH($j, $i, PHPLPSOLVE55_SHARED_LIBADD)
PHP_ADD_INCLUDE($LIBLPSOLVE_INCDIR)
LIBLPSOLVE_LIBDIR="$i"
break 2
],[
continue
],[
-L$i $EXTRA_LIBS
]
)
fi
done
done

for i in lpsolve55_pic lpsolve55; do
if test -z "$LIBLPSOLVE_LIBDIR"; then
PHP_CHECK_LIBRARY($i, make_lp,[
PHP_ADD_LIBRARY($i, 1, PHPLPSOLVE55_SHARED_LIBADD)
PHP_ADD_INCLUDE($LIBLPSOLVE_INCDIR)
LIBLPSOLVE_LIBDIR="$i"
],[
AC_MSG_ERROR([Could not find liblpsolve55.so or symbol make_lp. Check version and config.log for more information.])
],[
$EXTRA_LIBS
]
)
fi
done
LDFLAGS=""
AC_DEFINE(DEMO,1,[DEMO code in lpsolve])
PHP_NEW_EXTENSION(phplpsolve55, PHPmod.c hash.c lpsolve.c, $ext_shared)
AC_DEFINE(PHP,1,[liblpsolve55 found and included])
PHP_SUBST(PHPLPSOLVE55_SHARED_LIBADD)
fi

PHP_NEW_EXTENSION(phplpsolve55, PHPmod.c hash.c lpsolve.c, $ext_shared)
fi
1 change: 0 additions & 1 deletion hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include <sys/types.h>
#include <stdlib.h>
#include <malloc.h>
#include <string.h>

#include "hash.h"
Expand Down
15 changes: 8 additions & 7 deletions hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ typedef struct _hashtable
extern "C" {
#endif

hashtable *create_hash_table(int size, int base);
void free_hash_table(hashtable *ht);
hashelem *findhash(const char *name, hashtable *ht);
hashelem *puthash(const char *name, int index, hashelem **list, hashtable *ht);
void drophash(const char *name, hashelem **list, hashtable *ht);
void free_hash_item(hashelem **hp);
hashtable *copy_hash_table(hashtable *ht, hashelem **list, int newsize);
static inline hashtable *create_hash_table(int size, int base);
static inline void free_hash_table(hashtable *ht);
static inline hashelem *findhash(const char *name, hashtable *ht);
static inline hashelem *puthash(const char *name, int index, hashelem **list, hashtable *ht);
static inline void drophash(const char *name, hashelem **list, hashtable *ht);
static inline void free_hash_item(hashelem **hp);
static inline hashtable *copy_hash_table(hashtable *ht, hashelem **list, int newsize);
static inline int hashval(const char *string, int size);

#ifdef __cplusplus
}
Expand Down
12 changes: 12 additions & 0 deletions tests/01-empty.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--TEST--
Empty test
--SKIPIF--
<?php
if(!extension_loaded("lpsolve")) echo 'skip';
?>
--FILE--
<?php
var_dump(lpsolve('make_lp', 0, 0));
?>
--EXPECT--
int(0)