Hi,

While trying to build stuff in binr/ in non-PIC mode, I kept getting
linking errors.  This led me to that painful oneliner in libr/config.mk:

-------
LDFLAGS+=$(shell echo "${BINDEPS} " | if [ -d ../../libr ]; then echo $BINDEPS 
| awk '{gsub(/r_([^ ]*)/,"../../libr/&/lib&.a");gsub(/\/r_/,"\/");print}' ; 
else awk '{gsub(/r_([^ ]*)/,"../../&/lib&.a");gsub(/\/r_/,"\/");print}'; fi)
-------

This has three problems:

* $BINDEPS isn't recognised by make: the $B is expanded (to nothing), 
and we're left trying to link with "INDEPS"

* The second "echo $BINDEPS" looks unnecessary anyway.  Without it, what
we've got is

 echo ${BINDEPS} | 
        if [ -d ../../libr ] ; then
                awk ...
        else
                awk ...
 fi

so whichever awk is used, it reads from the first echo - like in the
old perl implementation.

* Wouldn't it be neater to use absolute paths, to avoid having to find where
libr/ is relative to the current directory?

Removing the redundant "echo $BINDEPS", I then get assorted linking errors
due to not finding dependencies of the various libr_ components.  I
copied some chunks between the different Makefiles, and swapped the
order of one BINDEPS line, to fix all these.  Patch attached.

Using some advanced (read: probably GNU Make-specific) Makefile magic
and adding support for absolute paths, I think I could move most of the
above dependencies into libr/config.mk.  Ideally, they'd go into their
own subdirectories in libr/ and be automated by a load more Makefile
includes, but then I have to start thinking about recursion...

So before I start hacking on this - what versions and variants of "make"
is r2 targeting?  And has anyone else already started work on this?

Also, a second patch - a fix for another entropy multiplication bug :-)

Glyn
diff -r fced763c0e41 binr/rabin2/Makefile
--- a/binr/rabin2/Makefile      Wed Sep 07 12:42:53 2011 +0200
+++ b/binr/rabin2/Makefile      Wed Sep 07 23:20:32 2011 +0100
@@ -1,5 +1,5 @@
 BIN=rabin2
-BINDEPS=r_bin r_cons r_util r_lib r_flags r_db
+BINDEPS=r_bin r_cons r_lib r_flags r_util r_db
 # rapatch deps
 BINDEPS+=r_core r_parse r_search r_lib r_config r_diff
 BINDEPS+=r_debug r_anal r_reg r_bp r_io r_cmd r_fs r_line
@@ -8,5 +8,15 @@
 include ../binr.mk
 
 ifeq ($(WITHNONPIC),1)
-LDFLAGS+=${DL_LIBS}
+LDFLAGS+=${DL_LIBS} -lm
+LDFLAGS+=../../libr/fs/p/grub/libgrubfs.a
+LDFLAGS+=../../libr/db/sdb/src/libsdb.a
+ifeq ($(HAVE_LIB_MAGIC),1)
+LDFLAGS+=-lmagic
 endif
+endif
+
+ifeq (${HAVE_LIB_SSL},1)
+CFLAGS+=${SSL_CFLAGS}
+LDFLAGS+=${SSL_LDFLAGS}
+endif
diff -r fced763c0e41 binr/radare2/Makefile
--- a/binr/radare2/Makefile     Wed Sep 07 12:42:53 2011 +0200
+++ b/binr/radare2/Makefile     Wed Sep 07 23:20:32 2011 +0100
@@ -17,9 +17,13 @@
 ifeq ($(WITHNONPIC),1)
 LDFLAGS+=${DL_LIBS} -lm
 LDFLAGS+=../../libr/fs/p/grub/libgrubfs.a
+LDFLAGS+=../../libr/db/sdb/src/libsdb.a
 ifeq ($(HAVE_LIB_GMP),1)
 LDFLAGS+=-lgmp
 endif
+ifeq ($(HAVE_LIB_MAGIC),1)
+LDFLAGS+=-lmagic
+endif
 endif
 
 ifeq ($(uname),OpenBSD)
diff -r fced763c0e41 binr/radiff2/Makefile
--- a/binr/radiff2/Makefile     Wed Sep 07 12:42:53 2011 +0200
+++ b/binr/radiff2/Makefile     Wed Sep 07 23:20:32 2011 +0100
@@ -9,9 +9,13 @@
 ifeq ($(WITHNONPIC),1)
 LDFLAGS+=${DL_LIBS} -lm
 LDFLAGS+=../../libr/fs/p/grub/libgrubfs.a
+LDFLAGS+=../../libr/db/sdb/src/libsdb.a
 ifeq ($(HAVE_LIB_GMP),1)
 LDFLAGS+=-lgmp
 endif
+ifeq ($(HAVE_LIB_MAGIC),1)
+LDFLAGS+=-lmagic
+endif
 endif
 
 ifeq (${HAVE_LIB_SSL},1)
diff -r fced763c0e41 binr/ragg2/Makefile
--- a/binr/ragg2/Makefile       Wed Sep 07 12:42:53 2011 +0200
+++ b/binr/ragg2/Makefile       Wed Sep 07 23:20:32 2011 +0100
@@ -5,6 +5,7 @@
 
 ifeq ($(WITHNONPIC),1)
 LDFLAGS+=${DL_LIBS}
+LDFLAGS+=../../libr/db/sdb/src/libsdb.a
 endif
 
 t test:
diff -r fced763c0e41 binr/rahash2/Makefile
--- a/binr/rahash2/Makefile     Wed Sep 07 12:42:53 2011 +0200
+++ b/binr/rahash2/Makefile     Wed Sep 07 23:20:32 2011 +0100
@@ -2,3 +2,7 @@
 BINDEPS=r_hash r_util r_print r_asm r_cons r_anal r_lib r_syscall r_reg r_diff 
r_db
 
 include ../binr.mk
+
+ifeq ($(WITHNONPIC),1)
+LDFLAGS+=-lm
+endif
diff -r fced763c0e41 binr/ranal2/Makefile
--- a/binr/ranal2/Makefile      Wed Sep 07 12:42:53 2011 +0200
+++ b/binr/ranal2/Makefile      Wed Sep 07 23:20:32 2011 +0100
@@ -5,6 +5,7 @@
 
 ifeq ($(WITHNONPIC),1)
 LDFLAGS+=${DL_LIBS} -lm -lpthread
+LDFLAGS+=../../libr/db/sdb/src/libsdb.a
 ifeq ($(HAVE_LIB_GMP),1)
 LDFLAGS+=-lgmp
 endif
diff -r fced763c0e41 libr/config.mk.tail
--- a/libr/config.mk.tail       Wed Sep 07 12:42:53 2011 +0200
+++ b/libr/config.mk.tail       Wed Sep 07 23:20:32 2011 +0100
@@ -30,12 +30,12 @@
 ifneq ($(DEPS),)
 #LDFLAGS+=`echo "${DEPS} " | perl -ne 's,r_([^ ]*),../$$1/libr_$$1.a,g; print'`
 #OK#LDFLAGS+=`echo $DEPS | awk '{gsub(/r_([^ 
]*)/,"../&/lib&.a");gsub(/\/r_/,"\/");print}'`
-LDFLAGS+=$(shell echo $DEPS | awk '{gsub(/r_([^ 
]*)/,"../&/lib&.a");gsub(/\/r_/,"\/");print}')
+LDFLAGS+=$(shell echo ${DEPS} | awk '{gsub(/r_([^ 
]*)/,"../&/lib&.a");gsub(/\/r_/,"\/");print}')
 endif
 ifneq ($(BINDEPS),)
 #LDFLAGS+=`echo "${BINDEPS} " | if [ -d ../../libr ]; then perl -ne 's,r_([^ 
]*),../../libr/$$1/libr_$$1.a,g; print' ; else perl -ne 's,r_([^ 
]*),../../$$1/libr_$$1.a,g; print' ; fi `
 #OK#LDFLAGS+=`echo "${BINDEPS} " | if [ -d ../../libr ]; then echo $BINDEPS | 
awk '{gsub(/r_([^ ]*)/,"../../libr/&/lib&.a");gsub(/\/r_/,"\/");print}' ; else 
awk '{gsub(/r_([^ ]*)/,"../../&/lib&.a");gsub(/\/r_/,"\/");print}'; fi`
-LDFLAGS+=$(shell echo "${BINDEPS} " | if [ -d ../../libr ]; then echo $BINDEPS 
| awk '{gsub(/r_([^ ]*)/,"../../libr/&/lib&.a");gsub(/\/r_/,"\/");print}' ; 
else awk '{gsub(/r_([^ ]*)/,"../../&/lib&.a");gsub(/\/r_/,"\/");print}'; fi)
+LDFLAGS+=$(shell echo "${BINDEPS} " | if [ -d ../../libr ]; then awk 
'{gsub(/r_([^ ]*)/,"../../libr/&/lib&.a");gsub(/\/r_/,"\/");print}' ; else awk 
'{gsub(/r_([^ ]*)/,"../../&/lib&.a");gsub(/\/r_/,"\/");print}'; fi)
 endif
 endif
 
diff -r fced763c0e41 binr/rahash2/rahash2.c
--- a/binr/rahash2/rahash2.c    Wed Sep 07 12:42:53 2011 +0200
+++ b/binr/rahash2/rahash2.c    Wed Sep 07 23:21:09 2011 +0100
@@ -24,7 +24,7 @@
                        double e = r_hash_entropy (buf, len);
                        printf ("0x%08"PFMT64x"-0x%08"PFMT64x" %10f: ", 
                                from, from+len, e);
-                       r_print_progressbar (NULL, 17 * e, 60);
+                       r_print_progressbar (NULL, 12.5 * e, 60);
                        printf ("\n");
                } else {
                        printf ("0x%08"PFMT64x"-0x%08"PFMT64x" %s: ", 
_______________________________________________
radare mailing list
[email protected]
http://lists.nopcode.org/listinfo.cgi/radare-nopcode.org

Reply via email to