android_samba icon indicating copy to clipboard operation
android_samba copied to clipboard

How to cross-compile samba source code?

Open dom-liu opened this issue 12 years ago • 5 comments

use CodeSourcery or Android NDK toolchain Is there Android.mk for android_samba?

dom-liu avatar Jan 25 '13 02:01 dom-liu

I'm sure the following isn't completely correct but this is how I got android_samba to build. Please leave me a comment and let me know if there's a better way to build android_samba. Either way I hope the following will help anyone else that needs to build the source.

I'm using an NDK generated standalone tool chain to cross compile the android_samba source.

To build I first had to change all of the permissions on the shell scripts to executable. find . -type f -name '*.sh' -exec chmod +x {} ;

I had to change the permissions on pidl to make it executable chmod +x pidl/pidl

I had to modify "berserker.h" as shown bellow. diff --git a/samba-3.6.8/source3/include/berserker.h b/samba-3.6.8/source3/include/berserker.h index 2c02f6b..546aee0 100644 --- a/samba-3.6.8/source3/include/berserker.h +++ b/samba-3.6.8/source3/include/berserker.h @@ -22,7 +22,8 @@ #define SMB_PASSWD_FILE PRIVATEDIR "/smbpasswd" #define LOCALEDIR SAMBADROID_ROOT "/share/locale"

-#include "bionic/libc/private/arpa_nameser.h" +#if 0 +#include "/home/sheldon/Projects/i.Mx6/Android/builds/bionic/libc/private/arpa_nameser.h" #define PWD_H /* disabilita l'inclusione del file pwd.h sotto android */

struct passwd @@ -44,6 +45,7 @@ struct passwd* getpwent(void); int setpwent(void);

void swab(const void *from, void *to, ssize_t n); +#endif

/* fix per defines mancanti di utmp.ut_type */ #ifndef DEAD_PROCESS

I had to hand modify the following files to include "berserker.h" ./examples/libsmbclient/smbwrapper/wrapper.c ./lib/util/util.c ./nsswitch/winbind_nss_aix.c ./nsswitch/winbind_struct_protocol.h ./source3/libnet/libnet_samsync_ldif.c ./source3/utils/net_idmap_check.c ./source3/lib/smbconf/testsuite.c ./source3/smbd/process.c ./source3/rpc_server/srv_pipe.c ./source4/ntvfs/nbench/vfs_nbench.c ./source4/heimdal/lib/krb5/krb5.h ./source4/heimdal/lib/krb5/expand_path.c ./source4/heimdal/lib/krb5/krb5-v4compat.h ./source4/lib/ldb/tools/ldbedit.c ./source4/param/tests/share.c ./testsuite/nsswitch/getgrent_r.c

I then ran the autogen script to generate the configure script cd source3 ./autogen.sh

Then I ran the configure script using the following configure settings: ./configure --host=i686 samba_cv_CC_NEGATIVE_ENUM_VALUES=yes ac_cv_file__proc_sys_kernel_core_pattern=yes --target=arm-none-linux-gnueabi --prefix=/home/sheldon/Projects/i.Mx6/HON/samba_3.6.8_install --with-utmp=no

Finally I built using the following command. make -j8

The last step was to install using the following command. make install

sheldonrucker avatar Dec 16 '15 00:12 sheldonrucker

So I pushed the generated binary files over to our system and I got the "not executable: magic 7F45" error. Turns out that I compiled for my host instead of the target (no cross compile). When I set my environment to cross compile as shown below,

CC_PATH=/home/sheldon/Projects/i.Mx6/Android/NDK/android-ndk-r10e/androideabi_4_9 export LD_LIBRARY_PATH=${CC_PATH}/lib export LDFLAGS=-L${CC_PATH}/lib export CPPFLAGS=-I${CC_PATH}/include export CC=${CC_PATH}/bin/arm-linux-androideabi-gcc

The build fails with a few undefined reference errors such as, ../lib/util/util_pw.o:util_pw.c:function sys_setpwent: error: undefined reference to 'setpwent' ../lib/util/util_pw.o:util_pw.c:function sys_getpwent: error: undefined reference to 'getpwent'

These function are defined in "include/berserker.c" however this file isn't included in the build. Does anyone know how to include berserker.c into the build? My guess is that I could modify the configure script. Has anyone done this? Is there an easier method?

sheldonrucker avatar Dec 16 '15 00:12 sheldonrucker

Okay, I finally got it to properly perform a cross compile. I had to modify Makefile.in to add include/berserker.c. Also, I had to modify Makefile.in to remove all occurrences of pthread since Android doesn't support it.

So my basic steps are as follows.

  1. Build a android standalone tool chain using the instructions here: http://developer.android.com/ndk/guides/standalone_toolchain.html#wwc. For example I created my toolchain using the following command: ./build/tools/make-standalone-toolchain.sh --arch=arm --platform=android-21 --install-dir=./androideabi_4_9 --toolchain=arm-linux-androideabi-4.9
  2. Update your path to add the path to the generated tool chain. For example I updated my path as follows: export PATH=$PATH:/home/sheldon/Projects/i.Mx6/Android/NDK/android-ndk-r10e/androideabi_4_9/bin
  3. Add HAVE_PTHREADS to your C compiler flags. This is important as it allows libraries that link against pthreads to build without requiring a link to the pthreads library. For example: export CFLAGS=-DHAVE_PTHREADS
  4. Apply the attached diff file to the android_samba source code. This will update the config.guess and config.sub to the newest versions which allows for the arm-linux-androideabi host and include berserker.c/h into the build. git apply android_samba_updates.diff
  5. Go to the android_samba/samba-3.6.8/source3 directory and run the autogen.sh script to generate a configure script. cd android_samba/samba-3.6.8/source3 autogen.sh
  6. Run the configure script which will generate the Makefile used to build Samba. Note that the configure options must be correct for things to build. Below lists what I used for my build. ./configure --without-krb5 --without-ldap --without-ads --disable-cups --enable-swat=no --with-winbind=no --host=arm-linux-androideabi --prefix=/home/sheldon/Projects/i.Mx6/HON/samba_3.6.8_install --with-configdir=/etc samba_cv_CC_NEGATIVE_ENUM_VALUES=yes libreplace_cv_HAVE_GETADDRINFO=no ac_cv_file__proc_sys_kernel_core_pattern=yes --with-sysroot=/home/sheldon/Projects/i.Mx6/Android/NDK/android-ndk-r10e/androideabi_4_9/sysroot --with-sys-quotas=no
  7. Update the generated Make file to set this line "PTHREAD_LDFLAGS=-lpthread" to "PTHREAD_LDFLAGS=" to ensure that pthreads is not included.
  8. Run make make -j8
  9. Run install make install

Those are the steps I used to generate the binary files. I haven't tested them further than verifying that I can run one of them on my target. I hope this saves someone some time that needs to compile android_samba in the future. Also, if you find anything wrong please let me know.

android_samba_updates.diff.zip

sheldonrucker avatar Dec 16 '15 17:12 sheldonrucker

Nice job sheldonrucker! I managed to use the "standard" NDK to build the binaries provided within the app but, as you probably know, there is no official support for _FILE_OFFSET_BITS switch (that's why the 2gb file transfer limit). It would be great if you can cross compile with D_FILE_OFFSET_BITS=64 enabled and test then if large files are supported.

berserker avatar Dec 17 '15 08:12 berserker

./autogen.sh: running script/mkversion.sh ./script/mkversion.sh: 'include/version.h' created for Samba("3.6.8") ./autogen.sh: running autoheader -Im4 -I../m4 -I../lib/replace configure.in:1437: warning: AC_LANG_CONFTEST: no AC_LANG_SOURCE call detected in body ../../lib/autoconf/lang.m4:193: AC_LANG_CONFTEST is expanded from... ../../lib/autoconf/general.m4:2601: _AC_COMPILE_IFELSE is expanded from... ../../lib/autoconf/general.m4:2617: AC_COMPILE_IFELSE is expanded from... ../../lib/m4sugar/m4sh.m4:639: AS_IF is expanded from... ../../lib/autoconf/general.m4:2042: AC_CACHE_VAL is expanded from... ../../lib/autoconf/general.m4:2063: AC_CACHE_CHECK is expanded from... configure.in:1437: the top level configure.in:5786: warning: AC_LANG_CONFTEST: no AC_LANG_SOURCE call detected in body ../../lib/autoconf/lang.m4:193: AC_LANG_CONFTEST is expanded from... ../../lib/autoconf/general.m4:2672: _AC_LINK_IFELSE is expanded from... ../../lib/autoconf/general.m4:2689: AC_LINK_IFELSE is expanded from... ../../lib/m4sugar/m4sh.m4:639: AS_IF is expanded from... ../../lib/autoconf/general.m4:1492: AC_ARG_WITH is expanded from... configure.in:5786: the top level ./autogen.sh: running autoconf -Im4 -I../m4 -I../lib/replace configure.in:1437: warning: AC_LANG_CONFTEST: no AC_LANG_SOURCE call detected in body ../../lib/autoconf/lang.m4:193: AC_LANG_CONFTEST is expanded from... ../../lib/autoconf/general.m4:2601: _AC_COMPILE_IFELSE is expanded from... ../../lib/autoconf/general.m4:2617: AC_COMPILE_IFELSE is expanded from... ../../lib/m4sugar/m4sh.m4:639: AS_IF is expanded from... ../../lib/autoconf/general.m4:2042: AC_CACHE_VAL is expanded from... ../../lib/autoconf/general.m4:2063: AC_CACHE_CHECK is expanded from... configure.in:1437: the top level configure.in:5786: warning: AC_LANG_CONFTEST: no AC_LANG_SOURCE call detected in body ../../lib/autoconf/lang.m4:193: AC_LANG_CONFTEST is expanded from... ../../lib/autoconf/general.m4:2672: _AC_LINK_IFELSE is expanded from... ../../lib/autoconf/general.m4:2689: AC_LINK_IFELSE is expanded from... ../../lib/m4sugar/m4sh.m4:639: AS_IF is expanded from... ../../lib/autoconf/general.m4:1492: AC_ARG_WITH is expanded from... configure.in:5786: the top level ./autogen.sh: running autoheader in ../examples/VFS/ ./autogen.sh: running autoconf in ../examples/VFS/ Can't use 'defined(@array)' (Maybe you should just omit the defined()?) at /home /ubuntu/projects/android_samba/samba-3.6.8/pidl/lib/Parse/Pidl/ODL.pm line 73. Compilation failed in require at ../pidl/pidl line 412. BEGIN failed--compilation aborted at ../pidl/pidl line 412. Can't use 'defined(@array)' (Maybe you should just omit the defined()?) at /home /ubuntu/projects/android_samba/samba-3.6.8/pidl/lib/Parse/Pidl/ODL.pm line 73. Compilation failed in require at ../pidl/pidl line 412. BEGIN failed--compilation aborted at ../pidl/pidl line 412. Now run ./configure (or ./configure.developer) and then make.

I do what you describe, but not success! Can you tell why and how

chenlimingcn avatar Jul 20 '18 08:07 chenlimingcn