Skip to content

Commit

Permalink
Improvements in the configure step for r2api integration
Browse files Browse the repository at this point in the history
  • Loading branch information
radare committed Jun 16, 2020
1 parent a6e397f commit d785b45
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ include config.mk
PWD=$(shell pwd)
PREFIX?=/usr
BINDIR=${DESTDIR}${PREFIX}/bin
OBJ=spp.o main.o r_api.o
OBJ=spp.o main.o
# r_api.o
ODF=$(subst .o,.d,$(OBJ))
BIN=spp

Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ spp
===

Author: pancake (pancake@nopcode.org)
History: 2009-2020
License: MIT

Description
Expand Down Expand Up @@ -54,12 +55,18 @@ There are no embedding issues with the MIT license and the
amount if code is pretty low (~400 LOC), and use the apis:

```c
$ cat test.c
#include "spp.c"

int main() {
char *p = spp_eval_str (&spp_proc, "Hello <{system uname}>");
printf ("%s\n", p);
free (p);
}

$ gcc test.c
$ ./a.out
Hello Darwin
```

Commandline
Expand Down Expand Up @@ -125,3 +132,5 @@ ASM
.include t/syscalls.asm
int3
```

...
49 changes: 46 additions & 3 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ control_c() {
}
trap control_c 2
HAVE_FORK=1
USE_R2=0
WANT_R2=0
split_host() {
S="$"
while : ; do
Expand Down Expand Up @@ -192,6 +192,7 @@ case $flag in
-r|--r|--report)
echo "PKGNAME: spp"
echo "VERSION: 1.1.0"
echo "PKG-CONFIG: r_util"
echo "FLAGS: --without-fork --enable-r2"
exit 0
;;
Expand Down Expand Up @@ -239,7 +240,7 @@ echo "FLAGS: --without-fork --enable-r2"
MANDIR="$value"; ;;

"--without-fork") HAVE_FORK="0"; ;;
"--enable-r2") USE_R2="1"; ;;
"--enable-r2") WANT_R2="1"; ;;
*) if [ "$value" ]; then eval "`echo $flag2=$value`" ;
else echo ; echo "WARNING: Unknown flag '$flag'." >&2 ; echo ; fi ;;
esac
Expand All @@ -257,7 +258,7 @@ parse_options "$1"
shift
done

ENVWORDS="MANDIR INFODIR LIBDIR INCLUDEDIR LOCALSTATEDIR SYSCONFDIR DATADIR DOCDIR LIBEXECDIR SBINDIR BINDIR EPREFIX PREFIX SPREFIX TARGET HOST BUILD INSTALL INSTALL_LIB INSTALL_MAN INSTALL_PROGRAM INSTALL_PROGRAM_STRIP INSTALL_DIR INSTALL_SCRIPT INSTALL_DATA HOST_OS HOST_CPU BUILD_OS BUILD_CPU TARGET_OS TARGET_CPU VERSION VERSION_MAJOR VERSION_MINOR VERSION_PATCH VERSION_NUMBER PKGNAME VPATH CONTACT CONTACT_NAME CONTACT_MAIL HAVE_FORK USE_R2"
ENVWORDS="MANDIR INFODIR LIBDIR INCLUDEDIR LOCALSTATEDIR SYSCONFDIR DATADIR DOCDIR LIBEXECDIR SBINDIR BINDIR EPREFIX PREFIX SPREFIX TARGET HOST BUILD INSTALL INSTALL_LIB INSTALL_MAN INSTALL_PROGRAM INSTALL_PROGRAM_STRIP INSTALL_DIR INSTALL_SCRIPT INSTALL_DATA HOST_OS HOST_CPU BUILD_OS BUILD_CPU TARGET_OS TARGET_CPU VERSION VERSION_MAJOR VERSION_MINOR VERSION_PATCH VERSION_NUMBER PKGNAME VPATH CONTACT CONTACT_NAME CONTACT_MAIL HAVE_FORK WANT_R2 HAVE_PKGCONFIG PKGCONFIG R2_CFLAGS R2_LDFLAGS HAVE_PKGCFG_R_UTIL USE_R2"

create_environ

Expand All @@ -272,6 +273,48 @@ echo "checking for working directories... ${WODIS}"
echo "using prefix '${PREFIX}'"
ACR_RMFILES=""


printf "checking for pkg-config... "
if [ -x "${PKGCONFIG}" ]; then
FIND=${PKGCONFIG}
else
FIND=""
IFS=:
for A in ${PATH} ; do
if [ -x "${A}/pkg-config" ]; then
FIND="${A}/pkg-config"
break;
fi
done
unset IFS
fi
if [ -n "${FIND}" ]; then
echo ${FIND};
HAVE_PKGCONFIG=1
PKGCONFIG=${FIND}
else
HAVE_PKGCONFIG=0
PKGCONFIG=pkg-config
echo no ; fi
[ -z "${PKGCONFIG}" ] && PKGCONFIG=pkg-config
type ${PKGCONFIG} > /dev/null 2>&1 || echo "ERROR: Cannot find PKGCONFIG ${PKGCONFIG}"
echo 'Using PKGCONFIG: '${PKGCONFIG}
printf 'checking pkg-config flags for r_util... '
tmp=`${PKGCONFIG} --cflags r_util 2>/dev/null`
if [ $? != 0 ]; then echo no ; HAVE_PKGCFG_R_UTIL=0;
R2_CFLAGS='';R2_LDFLAGS='';
else
R2_CFLAGS=$tmp;
tmp=`${PKGCONFIG} --libs r_util 2>/dev/null`
if [ $? = 0 ]; then
echo yes; HAVE_PKGCFG_R_UTIL=1;
R2_LDFLAGS=$tmp; fi; fi
USE_R2="0"
if [ "$WANT_R2" = "1" ]; then
if [ ! "$R2_CFLAGS" = "" ]; then
USE_R2="1"
else
case "$undefined_variable" in 0|"") echo ; echo "ERROR: Cannot find -lr_util using pkg-config" >&2 ; echo ; exit 1 ;; esac; fi; fi
SEDFLAGS=" -e '"
COUNT=0
for A in ${ENVWORDS} ; do
Expand Down
16 changes: 15 additions & 1 deletion configure.acr
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,21 @@ VERSION 1.1.0
CONTACT pancake ; pancake@nopcode.org

ARG_WITHOUT HAVE_FORK fork build without depending on fork syscall ;
ARG_ENABLE USE_R2 r2 compile against r2 r_util ;
ARG_ENABLE WANT_R2 r2 compile against r2 r_util ;

CHKPRG PKGCONFIG pkg-config

PKGCFG R2_CFLAGS R2_LDFLAGS r_util

USE_R2 = 0 ;

IF WANT_R2 {
IFNOTNULL R2_CFLAGS {
USE_R2 = 1 ;
}{
DIENOW Cannot find -lr_util using pkg-config ;
}
}

SUBDIRS ./config.mk ;

Expand Down
4 changes: 4 additions & 0 deletions spp.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
#include "r_api.h"
#include "config.h"

#if !USE_R2
#include "r_api.c"
#endif

S_API int spp_run(char *buf, Output *out) {
size_t i;
int ret = 0;
Expand Down

0 comments on commit d785b45

Please sign in to comment.