pancake wrote:
> i plan to release 0.8.6 soon, i dont plan to change the makefiles for 
> this release. maybe for 0.9

I think I've been trying to change too much at once with this - I
realised that with all the different ways of building the parts, the
only way that made sense was to recompile in a new subdirectory for each
arrangement of options, and suddenly I was trying to copy how
autoconf+libtool did it while also building new nests of Makefile
includes.

Trying a different approach - here's a relatively small change that
switches some of the .mk files to use absolute paths, moves (most of)
the LDFLAGS setting out of binr/*/Makefile, and trims those unwieldy
replacement commands down to simple seds.

I've only tested on linux x86_64, confirmed it doesn't break the default
(PIC) build or --with-nonpic...  except with debug.bf + io.bfdbg, which
was broken already.  They can't both be in the Static plugins list when
compiling with-nonpic without-pic, because they both include
debug/p/bfvm.c, so there's a symbol clash when linking any binary with
libr_io.a and libr_debug.a.

I've also not moved the android-specific LDFLAGS out of each
binr/*/Makefile, as I don't have any way of testing which r_* are
responsible for the -ldl and -lm dependencies there.

Glyn
diff -r 606d36e5054e binr/binr.mk
--- a/binr/binr.mk      Tue Oct 11 02:13:15 2011 +0200
+++ b/binr/binr.mk      Tue Oct 11 18:06:09 2011 +0100
@@ -1,26 +1,11 @@
-include ../../libr/config.mk
-
 .PHONY: all clean
 
-CFLAGS+=-I../../libr/include
 CFLAGS+=-DLIBDIR=\"${LIBDIR}\"
 
-ifeq ($(WITHPIC),1)
-LIBS=$(subst r_,-lr_,$(BINDEPS))
-LIBS+=$(subst r_,-L../../libr/,$(BINDEPS))
-else
-PFXDLIBS=$(addsuffix .a,${BINDEPS})
-XXXLIBS+=$(subst r_,../../libr/XXX/libr_,$(PFXDLIBS))
-LIBS+=$(shell echo ${XXXLIBS} | sed -e 's,XXX/libr_\([^\. ]*\),\1/libr_\1,g')
-endif
-
 all: ${BIN}${EXT_EXE}
 
-${BIN}${EXT_EXE}: ${BIN}.o ${OBJS}
-       ${CC} -o ${BIN}${EXT_EXE} ${OBJS} ${BIN}.o ${LIBS} ${LDFLAGS}
 
-clean: ${MYCLEAN}
-       -rm -f ${BIN} ${BIN}.o ${OBJS}
+OBJS+=${BIN}.o
 
-mrproper: clean
-       -rm -f ${BIN}.d
+include ../../libr/rules.mk
+${BIN}${EXT_EXE}: ${OBJS}
diff -r 606d36e5054e binr/rabin2/Makefile
--- a/binr/rabin2/Makefile      Tue Oct 11 02:13:15 2011 +0200
+++ b/binr/rabin2/Makefile      Tue Oct 11 18:06:09 2011 +0100
@@ -2,17 +2,3 @@
 BINDEPS=r_bin r_cons r_lib r_flags r_util r_db
 
 include ../binr.mk
-
-ifeq ($(WITHNONPIC),1)
-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 606d36e5054e binr/radare2/Makefile
--- a/binr/radare2/Makefile     Tue Oct 11 02:13:15 2011 +0200
+++ b/binr/radare2/Makefile     Tue Oct 11 18:06:09 2011 +0100
@@ -1,7 +1,7 @@
 BIN=radare2
-BINDEPS=r_core r_parse r_search r_cons r_lib r_config r_diff
-BINDEPS+=r_bin r_debug r_anal r_reg r_bp r_io r_cmd r_fs r_db
-BINDEPS+=r_sign r_print r_lang r_asm r_syscall r_hash r_line
+BINDEPS=r_core r_parse r_search r_cons r_lib r_config
+BINDEPS+=r_bin r_debug r_anal r_diff r_reg r_bp r_io r_cmd r_fs
+BINDEPS+=r_sign r_print r_lang r_asm r_syscall r_db r_hash r_line
 BINDEPS+=r_magic r_socket r_flags r_util r_th r_egg
 
 include ../binr.mk
@@ -18,23 +18,3 @@
 ifeq ($(OSTYPE),android)
 LDFLAGS+=${DL_LIBS} -lm
 endif
-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)
-LDFLAGS+=-pthread
-endif
-
-ifeq (${HAVE_LIB_SSL},1)
-CFLAGS+=${SSL_CFLAGS}
-LDFLAGS+=${SSL_LDFLAGS}
-endif
diff -r 606d36e5054e binr/radiff2/Makefile
--- a/binr/radiff2/Makefile     Tue Oct 11 02:13:15 2011 +0200
+++ b/binr/radiff2/Makefile     Tue Oct 11 18:06:09 2011 +0100
@@ -1,27 +1,11 @@
 BIN=radiff2
 BINDEPS=r_core r_diff r_config r_lib r_cons r_search r_anal
-BINDEPS+=r_bin r_debug r_io r_print r_asm r_hash r_util r_fs
+BINDEPS+=r_bin r_debug r_io r_print r_asm r_hash r_fs
 BINDEPS+=r_socket r_flags r_lang r_reg r_bp r_cmd r_sign r_parse
-BINDEPS+=r_line r_syscall r_db r_magic r_parse r_egg
+BINDEPS+=r_line r_syscall r_db r_magic r_util r_parse r_egg
 
 include ../binr.mk
 
 ifeq ($(OSTYPE),android)
 LDFLAGS+=${DL_LIBS} -lm
 endif
-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)
-CFLAGS+=${SSL_CFLAGS}
-LDFLAGS+=${SSL_LDFLAGS}
-endif
diff -r 606d36e5054e binr/rafind2/Makefile
--- a/binr/rafind2/Makefile     Tue Oct 11 02:13:15 2011 +0200
+++ b/binr/rafind2/Makefile     Tue Oct 11 18:06:09 2011 +0100
@@ -3,16 +3,3 @@
 BINDEPS+=r_socket r_db r_parse
 
 include ../binr.mk
-
-ifeq ($(WITHNONPIC),1)
-LDFLAGS+=${DL_LIBS} -lm
-LDFLAGS+=../../libr/fs/p/grub/libgrubfs.a
-ifeq ($(HAVE_LIB_GMP),1)
-LDFLAGS+=-lgmp
-endif
-
-endif
-ifeq (${HAVE_LIB_SSL},1)
-CFLAGS+=${SSL_CFLAGS}
-LDFLAGS+=${SSL_LDFLAGS}
-endif
diff -r 606d36e5054e binr/ragg2/Makefile
--- a/binr/ragg2/Makefile       Tue Oct 11 02:13:15 2011 +0200
+++ b/binr/ragg2/Makefile       Tue Oct 11 18:06:09 2011 +0100
@@ -1,13 +1,8 @@
 BIN=ragg2
-BINDEPS=r_egg r_bin r_syscall r_asm r_util r_db r_parse
+BINDEPS=r_egg r_bin r_syscall r_asm r_db r_util r_parse
 
 include ../binr.mk
 
-ifeq ($(WITHNONPIC),1)
-LDFLAGS+=${DL_LIBS}
-LDFLAGS+=../../libr/db/sdb/src/libsdb.a
-endif
-
 t test:
        cd t ; ${MAKE}
 
diff -r 606d36e5054e binr/rahash2/Makefile
--- a/binr/rahash2/Makefile     Tue Oct 11 02:13:15 2011 +0200
+++ b/binr/rahash2/Makefile     Tue Oct 11 18:06:09 2011 +0100
@@ -3,9 +3,6 @@
 
 include ../binr.mk
 
-ifeq ($(WITHNONPIC),1)
-LDFLAGS+=-lm
-endif
 ifeq ($(OSTYPE),android)
 LDFLAGS+=-lm
 endif
diff -r 606d36e5054e binr/ranal2/Makefile
--- a/binr/ranal2/Makefile      Tue Oct 11 02:13:15 2011 +0200
+++ b/binr/ranal2/Makefile      Tue Oct 11 18:06:09 2011 +0100
@@ -1,16 +1,10 @@
 BIN=ranal2
-BINDEPS=r_anal r_lib r_reg r_util r_syscall r_diff r_db
+BINDEPS=r_anal r_lib r_reg r_syscall r_diff r_db r_util
 
 include ../binr.mk
 
 ifeq ($(WITHNONPIC),1)
 ifeq ($(OSTYPE),android)
 LDFLAGS+=${DL_LIBS} -lm
-else
-LDFLAGS+=${DL_LIBS} -lm -lpthread
 endif
-LDFLAGS+=../../libr/db/sdb/src/libsdb.a
-ifeq ($(HAVE_LIB_GMP),1)
-LDFLAGS+=-lgmp
 endif
-endif
diff -r 606d36e5054e binr/rarun2/Makefile
--- a/binr/rarun2/Makefile      Tue Oct 11 02:13:15 2011 +0200
+++ b/binr/rarun2/Makefile      Tue Oct 11 18:06:09 2011 +0100
@@ -1,5 +1,4 @@
 BIN=rarun2
 BINDEPS=r_util
-OBJ=main.o
 
 include ../binr.mk
diff -r 606d36e5054e binr/rasm2/Makefile
--- a/binr/rasm2/Makefile       Tue Oct 11 02:13:15 2011 +0200
+++ b/binr/rasm2/Makefile       Tue Oct 11 18:06:09 2011 +0100
@@ -2,7 +2,3 @@
 BINDEPS=r_asm r_util r_lib r_parse
 
 include ../binr.mk
-
-ifeq ($(WITHNONPIC),1)
-LDFLAGS+=${DL_LIBS}
-endif
diff -r 606d36e5054e binr/rsc2/Makefile
--- a/binr/rsc2/Makefile        Tue Oct 11 02:13:15 2011 +0200
+++ b/binr/rsc2/Makefile        Tue Oct 11 18:06:09 2011 +0100
@@ -1,4 +1,4 @@
 BIN=rsc2
-DEPS=
+BINDEPS=r_util
 
 include ../binr.mk
diff -r 606d36e5054e libr/anal/t/Makefile
--- a/libr/anal/t/Makefile      Tue Oct 11 02:13:15 2011 +0200
+++ b/libr/anal/t/Makefile      Tue Oct 11 18:06:09 2011 +0100
@@ -1,17 +1,6 @@
-include ../../config.mk
+BINDEPS=r_util
+BIN=test_x86im
+OBJ=test_x86im.o ../arch/x86/x86im/x86im.o
+CFLAGS+=-I ../arch -D__UNIX__=1
 
-CFLAGS+=-I ../arch -I../../include -D__UNIX__=1
-LDFLAGS=-L../../util -lr_util -L../../anal -lr_anal -L../../reg -lr_reg 
-L../../syscall -lr_syscall
-LDFLAGS+=-L../../diff -lr_diff -L../../db -lr_db
-
-all: test_x86im${EXT_EXE}
-
-test_x86im${EXT_EXE}: test_x86im.o ../arch/x86/x86im/x86im.o
-       ${CC} ${CFLAGS} ${LDFLAGS} -o test_x86im${EXT_EXE} \
-               ../arch/x86/x86im/x86im.o test_x86im.o
-
-clean:
-       rm -f test_x86im${EXT_EXE} test_x86im.o
-
-mrproper: clean
-       rm -f test_x86im.d
+include ../../rules.mk
diff -r 606d36e5054e libr/bin/t/Makefile
--- a/libr/bin/t/Makefile       Tue Oct 11 02:13:15 2011 +0200
+++ b/libr/bin/t/Makefile       Tue Oct 11 18:06:09 2011 +0100
@@ -2,22 +2,9 @@
 
 BINDEPS=r_lib r_bin r_flags r_util r_cons
 CFLAGS+=-DLIBDIR=\"${LIBDIR}\"
-LIBS+=${DL_LIBS}
-
-LDPATH=-L.. -L../../util
-LDPATH+=-lr_util
 
 all: test_meta${EXT_EXE} rpathdel${EXT_EXE} test_create${EXT_EXE}
 
-test_meta${EXT_EXE}: test_meta.o
-       ${CC} test_meta.o ${LDPATH} ${LDFLAGS} -o test_meta${EXT_EXE} 
-
-rpathdel${EXT_EXE}: rpathdel.o
-       ${CC} rpathdel.o ${LDPATH} ${LDFLAGS} -o rpathdel${EXT_EXE} 
-
-test_create${EXT_EXE}: test_create.o
-       ${CC} test_create.o ${LDPATH} ${LDFLAGS} -o test_create${EXT_EXE} 
-
 myclean:
        rm -f test_meta${EXT_EXE} test_meta.o rpathdel${EXT_EXE} rpathdel.o
 
diff -r 606d36e5054e libr/config.mk.tail
--- a/libr/config.mk.tail       Tue Oct 11 02:13:15 2011 +0200
+++ b/libr/config.mk.tail       Tue Oct 11 18:06:09 2011 +0100
@@ -1,42 +1,58 @@
 # config.mk.tail
 
-# libr/*
--include ../../config-user.mk
--include ../../global.mk
--include ../../mk/${COMPILER}.mk
+LIBR:=$(abspath $(dir $(lastword $(MAKEFILE_LIST))))
 
-# libr/*/p
--include ../../../config-user.mk
--include ../../../global.mk
--include ../../../mk/${COMPILER}.mk
-
-# libr/fs/p/grub
--include ../../../../config-user.mk
--include ../../../../global.mk
--include ../../../../mk/${COMPILER}.mk
+include $(LIBR)/../config-user.mk
+include $(LIBR)/../global.mk
+include $(LIBR)/../mk/${COMPILER}.mk
 
 CFLAGS+=-DUSE_RIO=${USE_RIO}
 CFLAGS+=${CFLAGS_APPEND}
 
 ifeq ($(WITHPIC),1)
 LDFLAGS+=$(subst r_,-lr_,$(DEPS))
-LDFLAGS+=$(subst r_,-L../,$(DEPS))
+LDFLAGS+=$(subst r_,-L$(LIBR)/,$(DEPS))
 LDFLAGS+=$(subst r_,-lr_,$(BINDEPS))
-LDFLAGS+=$(subst r_,-L../../,$(BINDEPS))
+LDFLAGS+=$(subst r_,-L$(LIBR)/,$(BINDEPS))
 CFLAGS+=${PIC_CFLAGS}
 LDFLAGS+=${PIC_CFLAGS}
 else
-# TODO: is there somebody brave enought to replace this perl oneliner?
 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} | sed -e 's:r_\([^ ]\+\):$(LIBR)/\1/libr_\1.a:g')
 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 awk 
'{gsub(/r_([^ ]*)/,"../../libr/&/lib&.a");gsub(/\/r_/,"\/");print}' ; else awk 
'{gsub(/r_([^ ]*)/,"../../&/lib&.a");gsub(/\/r_/,"\/");print}'; fi)
+LDLIBS+=$(shell echo "${BINDEPS} " | sed -e 's:r_\([^ 
]\+\):$(LIBR)/\1/libr_\1.a:g')
 endif
+
+#link dependencies of individual r_ libs
+#TODO: move them inside libr/*/subdeps.mk
+ifneq (,$(findstring r_db,$(BINDEPS)))
+LDLIBS+=$(LIBR)/db/sdb/src/libsdb.a
+endif
+ifneq (,$(findstring r_fs,$(BINDEPS)))
+LDLIBS+=$(LIBR)/fs/p/grub/libgrubfs.a
+endif
+ifneq (,$(findstring r_hash,$(BINDEPS)))
+LDLIBS+=-lm
+endif
+ifneq (,$(findstring r_lib,$(BINDEPS)))
+LDLIBS+=${DL_LIBS}
+endif
+ifneq (,$(findstring r_socket,$(BINDEPS)))
+ifeq (${HAVE_LIB_SSL},1)
+LDLIBS+=${SSL_LDFLAGS}
+endif
+endif
+ifneq (,$(findstring r_th,$(BINDEPS)))
+LDLIBS+=${TH_LIBS}
+endif
+ifneq (,$(findstring r_util,$(BINDEPS)))
+ifeq (${HAVE_LIB_GMP},1)
+LDLIBS+=-lgmp
+endif
+endif
+
+
 endif
 
 # Compiler: see mk/gcc.mk
@@ -51,6 +67,13 @@
 BN_LIBS=-lgmp
 endif
 
+#both of these need ssl includes
+ifneq (,$(filter r_socket r_util,$(BINDEPS)))
+ifeq (${HAVE_LIB_SSL},1)
+CFLAGS+=${SSL_CFLAGS}
+endif
+endif
+
 # XXX do it in configure stage
 OSTYPE?=gnulinux
 # Output
diff -r 606d36e5054e libr/rules.mk
--- a/libr/rules.mk     Tue Oct 11 02:13:15 2011 +0200
+++ b/libr/rules.mk     Tue Oct 11 18:06:09 2011 +0100
@@ -1,12 +1,8 @@
-# TODO: use $VPATH here?
--include config.mk
--include ../config.mk
--include ../../config.mk
+LIBR:=$(abspath $(dir $(lastword $(MAKEFILE_LIST))))
+include $(LIBR)/config.mk
 
 #-------------------------------------#
 # Rules for libraries
-ifeq (${BINDEPS},)
-
 ifneq ($(NAME),)
 
 ALL?=
@@ -95,26 +91,16 @@
 
 else
 
-# somewhere else?
+#-------------------------------------#
+# Rules for programs (including test)
 
-endif
-
-else
-
-#-------------------------------------#
-# Rules for test programs
-
-# XXX can this be removed?
-#include ../../../config-user.mk
-#include ../../../mk/${COMPILER}.mk
-
-CFLAGS+=-I../../include -DVERSION=\"${VERSION}\"
+CFLAGS+=-I$(LIBR)/include -DVERSION=\"${VERSION}\"
 
 ifneq ($(BIN),)
 all: ${BIN}${EXT_EXE}
 
 ${BIN}${EXT_EXE}: ${OBJ}
-       ${CC} ${OBJ} -L.. ${LDFLAGS} ${LIBS} -o ${BIN}${EXT_EXE}
+       ${CC} $+ -L.. ${LDFLAGS} ${LDLIBS} -o ${BIN}${EXT_EXE}
 endif
 
 # Dummy myclean rule that can be overriden by the t/ Makefile
_______________________________________________
radare mailing list
[email protected]
http://lists.nopcode.org/listinfo.cgi/radare-nopcode.org

Reply via email to