PKGNAME rizin
VERSION 0.1.0
CONTACT Rizin Core Team ; team@rizin.re

LANG_C!

ARG_DISABLE DEBUGGER debugger disable native debugger features ;

(( -ldl -dynamic ... ))
USE_DL

CHKPRG! PATCH patch
CHKPRG GIT git
CHKLIB magic
ARG_WITH USE_MAGIC sysmagic force to use system's magic ;
IFAND HAVE_LIB_MAGIC USE_MAGIC {
	USE_LIB_MAGIC = 1 ;
	LIBMAGIC = -lmagic ;
}{
	USE_LIB_MAGIC = 0 ;
	LIBMAGIC = '' ;
}

ARG_WITH CSNEXT capstone5 build next branch of the capstone repository ;

(( useful for static builds . see sys/static.sh ))
ARG_DISABLE LOADLIBS loadlibs disable loading plugins ;

ARG_WITHOUT WANT_DYLINK dylink disable support for dynamic loading of plugins ;
ARG_WITHOUT HAVE_FORK fork disable fork ;
ARG_WITHOUT WANT_PTRACE_WRAP ptrace-wrap disable ptrace-wrap build ;

ARG_WITH WITH_LIBRZ librz build librz.a and librz.dylib ;

ARG_WITH WITH_CAPSTONE syscapstone force to use system-wide capstone ;
IF WITH_CAPSTONE {
	PKGCFG CAPSTONE_CFLAGS CAPSTONE_LDFLAGS capstone
}
IFAND WITH_CAPSTONE HAVE_PKGCFG_CAPSTONE {
	USE_CAPSTONE = 1 ;
}{
	USE_CAPSTONE = 0 ;
}

CHKLIB z
CHKLIB zip
ARG_WITH USE_ZIP syszip force to use system's libzip and zlib ;
IFAND HAVE_LIB_Z USE_ZIP {
	IF HAVE_LIB_ZIP {
		USE_LIB_ZIP = 1 ;
		LIBZIP = -lz -lzip ;
	}{
		USE_LIB_ZIP = 0 ;
		LIBZIP = '' ; (( static linking to shlr/zip ))
	}
}{
	USE_LIB_ZIP = 0 ;
	LIBZIP = '' ; (( static linking to shlr/zip ))
}

CHKLIB xxhash
ARG_WITH USE_XXHASH sysxxhash force to use system's xxhash ;
IFAND HAVE_LIB_XXHASH USE_XXHASH {
	USE_LIB_XXHASH = 1 ;
	LIBXXHASH = -lxxhash ;
}{
	USE_LIB_XXHASH = 0 ;
	LIBXXHASH = '' ;
}

ARG_WITHOUT WITH_GPL gpl do not build GPL code (cxx, ... ) ;

CHKDECL sys/personality.h ADDR_NO_RANDOMIZE
CHKDECL features.h __GLIBC__
CHKFNC c arc4random_uniform
CHKFNC c explicit_bzero
CHKFNC c explicit_memset
CHKFNC c clock_nanosleep
CHKFNC c sigaction
CHKFNC c clock_gettime
CHKFNC c pipe
CHKFNC c execv
CHKFNC c execve
CHKFNC c execvp
CHECK HAVE_EXECL <<EOF
echo "#include <unistd.h>" > temp.c \
echo "int main(int argc, char **argv) { void *x = (void *)execl; return 0;}" >> temp.c \
${CC} temp.c \
HAVE_EXECL=$? \
rm -f temp.c
<<EOF

CHKFNC c system
CHKFNC c pipe2

IFNOT HAVE_CLOCK_GETTIME {
	IF HAVE_DECL___GLIBC__ {
		CLOCK_LDFLAGS += '-lrt' ;
	}
}

CHKFLG SUPPORT_GNU99 -std=gnu99 ;

IF SUPPORT_GNU99 {
	CFLAGS += '-std=gnu99' ;
}{
	CHKFLG SUPPORT_C99 -std=c99 ;
	IF SUPPORT_C99 {
		CFLAGS += '-std=c99' ;
	}
}

(( TODO must deprecate
CHKLIB gmp
ARG_WITHOUT HAVE_GMP gmp disable GMP dependency ;
IFNOT HAVE_GMP { HAVE_LIB_GMP = 0 ; }
HAVE_GMP = 0 ;
))
HAVE_LIB_GMP = 0 ;

CHKLIB ssl
PKGCFG SSL_CFLAGS SSL_LDFLAGS openssl
IFNOTNULL SSL_LDFLAGS {
	HAVE_OPENSSL = 1 ;
}
(( ARG_WITHOUT HAVE_OPENSSL ssl disable openssl dependency ; ))
ARG_WITH WANT_OPENSSL openssl build with openssl if possible ;
IFAND WANT_OPENSSL HAVE_OPENSSL {
	HAVE_OPENSSL = 1 ;
}{
	HAVE_OPENSSL = 0 ;
}
IFNULL SSL_LDFLAGS {
	IFNOT HAVE_LIB_SSL {
		HAVE_OPENSSL = 0 ;
	}{
		SSL_LDFLAGS = -lssl ;
	}
}

CHKVER libuv 1.0.0
IF HAVE_LIBUV_VERSION_1_0_0 {
	PKGCFG LIBUV_CFLAGS LIBUV_LDFLAGS libuv
	IFNOTNULL LIBUV_LDFLAGS {
		HAVE_LIBUV = 1 ;
	}{
		HAVE_LIBUV = 0 ;
	}
	ARG_WITHOUT WANT_LIBUV libuv disable libuv dependency ;
	IFNOT WANT_LIBUV {
		HAVE_LIBUV = 0 ;
	}
}{
	HAVE_LIBUV = 0 ;
}

ARG_WITH USE_RPATH rpath use rpath to build ;

(( rules for the compiler ))
ARG_WITH USERCC=gcc compiler Define compiler to use (see mk/) ;
ARG_WITH USEROSTYPE=auto ostype Choose OS type ( gnulinux windows darwin haiku ) ;

(( TODO: throw error if unknown ostype ))
(( TODO: handle BSD os as different ostype? ))
IFEQ USEROSTYPE auto ; {
	IFEQ HOST_OS wsl ; {
		USEROSTYPE =  wsl ;
	}{
	IFEQ HOST_OS linux ; {
		USEROSTYPE = gnulinux ;
	}{
	IFEQ HOST_OS gnu ; {
		(( GNU / HURD ))
		USEROSTYPE = gnulinux ;
		HAVE_LIB_DL = 1 ;
		DL_LIBS = -ldl ;
	}{
	IFEQ HOST_OS sunos ; {
		USEROSTYPE = solaris ;
	}{
	IFEQ HOST_OS gnu/kfreebsd ; {
		USEROSTYPE = bsd ;
	}{
	IFEQ HOST_OS netbsd ; {
		USEROSTYPE = bsd ;
	}{
	IFEQ HOST_OS freebsd ; {
		USEROSTYPE = bsd ;
	}{
	IFEQ HOST_OS openbsd ; {
		USEROSTYPE = bsd ;
	}{
	IFEQ HOST_OS darwin ; {
		USEROSTYPE = darwin ;
        }{
	IFEQ HOST_OS haiku ; {
		USEROSTYPE = haiku ;
	} } } } } } } } } }
}

(( this hack is required for openbsd ports ))
ARG_WITH LIBVERSION=xxx libversion specify different libversion ;
ARG_WITHOUT HAVE_JEMALLOC jemalloc build without jemalloc ;

IFEQ LIBVERSION xxx ; {
	LIBVERSION = $VERSION ;
}

IFEQ USEROSTYPE gnulinux ; {
	HAVE_PTRACE = 1 ;
	USE_PTRACE_WRAP = 1 ;
}{
IFEQ USEROSTYPE wsl ; {
	BUILD = ${SPLIT_CPU}-unknown-linux-gnu ;
	HOST = $BUILD ;
	TARGET = $HOST ;
	USEROSTYPE = gnulinux ;
	HAVE_PTRACE = 1 ;
	USE_PTRACE_WRAP = 0 ;
}{
IFEQ USEROSTYPE android ; {
	HAVE_PTRACE = 1 ;
	USE_PTRACE_WRAP = 1 ;
}{
IFEQ USEROSTYPE solaris ; {
	HAVE_PTRACE = 0 ;
	USE_PTRACE_WRAP = 0 ;
}{
IFEQ USEROSTYPE haiku ; {
	HAVE_PTRACE = 0 ;
	USE_PTRACE_WRAP = 0 ;
}{
	HAVE_PTRACE = 1 ;
	USE_PTRACE_WRAP = 0 ;
} } } } }

IFNOT DEBUGGER {
	HAVE_PTRACE = 0 ;
}

IFEQ WANT_PTRACE_WRAP 0 ; {
	USE_PTRACE_WRAP = 0 ;
}

ARG_WITHOUT WANT_RZ_TEST rz-test build without rz-test for regression testing ;

ARG_WITH RZ_CHECKS_LEVEL=2 checks-level value between 0 and 3 to enable different level of assert (see RZ_CHECKS_LEVEL) ;

REPORT RZ_CHECKS_LEVEL WANT_RZ_TEST PREFIX HAVE_LIB_GMP HAVE_OPENSSL HAVE_LIBUV USE_CAPSTONE HAVE_PTRACE USE_PTRACE_WRAP HAVE_FORK
	VERSION USE_LIB_ZIP USE_LIB_MAGIC USE_LIB_XXHASH DEBUGGER CC USERCC HAVE_ARC4RANDOM_UNIFORM
	HAVE_EXPLICIT_BZERO HAVE_EXPLICIT_MEMSET WANT_DYLINK USEROSTYPE LIBVERSION BUILD HOST TARGET ;

(( TODO: Add the rest of .pc files here.. add a rule for acr? ))
SUBDIRS ./config-user.mk
	librz/include/rz_userconf.h
	pkgcfg/rz_io.pc
	pkgcfg/rz_magic.pc
	pkgcfg/rz_asm.pc
	pkgcfg/rz_bin.pc
	pkgcfg/rz_analysis.pc
	pkgcfg/rz_hash.pc
	pkgcfg/rz_cons.pc
	pkgcfg/rz_core.pc
	pkgcfg/rz_lang.pc
	pkgcfg/rz_socket.pc
	pkgcfg/rz_debug.pc
	pkgcfg/rz_reg.pc
	pkgcfg/rz_config.pc
	pkgcfg/rz_flag.pc
	pkgcfg/rz_syscall.pc
	pkgcfg/rz_util.pc
	pkgcfg/rz_search.pc
	pkgcfg/rz_bp.pc
	pkgcfg/rz_parse.pc
	pkgcfg/rz_egg.pc
	pkgcfg/rz_crypto.pc
;
