Vaspi
Posts: 23
Joined: Sun Jul 03, 2016 10:07 am
Location: Wales

Porting code to raspberry pi from source code? (Non coder)

Tue Jul 19, 2016 10:20 pm

Please forgive me from the very start I am not sure how to describe my question properly. I would like to attempt to compile? Port? Somthing from source code as an exercise and to learn somthing with the pi.

It may already have been ported it's Charles McDonald's megadrive gx emulator http://www.techno-junk.org the source is avalible here.

i run it on my Nintendo wii and it's amazing pixel perfect and fast the wii version was done bye eke eke. here is his link
https://bitbucket.org/eke/genesis-plus-gx/src/

I am a total novice at this type of stuff hopefully it isn't a two year course :lol: but willing to put time and effort in to learn if nudged in right direction.

Any help I'll appreciate
Dougie Lawson Fan club

ejolson
Posts: 3580
Joined: Tue Mar 18, 2014 11:47 am

Re: Porting code to raspberry pi from source code? (Non code

Wed Jul 20, 2016 4:40 pm

Vaspi wrote:Please forgive me from the very start I am not sure how to describe my question properly. I would like to attempt to compile? Port? Somthing from source code as an exercise and to learn somthing with the pi.

It may already have been ported it's Charles McDonald's megadrive gx emulator http://www.techno-junk.org the source is avalible here.

i run it on my Nintendo wii and it's amazing pixel perfect and fast the wii version was done bye eke eke. here is his link
https://bitbucket.org/eke/genesis-plus-gx/src/

I am a total novice at this type of stuff hopefully it isn't a two year course :lol: but willing to put time and effort in to learn if nudged in right direction.

Any help I'll appreciate
It looks like libretro contains a gx emulator for Intel versions of Linux with nVidia and AMD graphics cards. Getting this emulator to run on a Pi with Video Core 4 is likely to be quite an advanced project as would be porting any emulator that wasn't already designed for ARM and in particular the Raspberry Pi graphics hardware. I would suggest looking at existing emulators that run on the Pi and possibly extending one of them for the megadrive gx instead.

ghans
Posts: 7873
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: Porting code to raspberry pi from source code? (Non code

Thu Jul 21, 2016 9:27 am

You could start by following generic "compiling from
source" instructions for "Linux" or "Unix".

Post error messages in

Code: Select all

 tags.

ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

Vaspi
Posts: 23
Joined: Sun Jul 03, 2016 10:07 am
Location: Wales

Re: Porting code to raspberry pi from source code? (Non code

Thu Jul 21, 2016 12:00 pm

Ahh ok the pi is my first Linux CPU , only code I have ever done was c# (c sharp) with unity 3d.

I always assumed if the source code was avalible it's much easier to port something to a diffrent platform. I just really like the interface of that emu's front end also it runs solar pier with cd audio.

I think I may contact eke eke as he has ported it to a Nintendo wii so the pi must be able to do it as the wii is weak as hell, hopefully he don't mind spending sometime to reply.

In the mean time I'll hit up Google and see if I can find a compiling from source Linux tutorial as you mentioned Ghan's.

Thanks both for replying
Dougie Lawson Fan club

swampdog
Posts: 239
Joined: Fri Dec 04, 2015 11:22 am

Re: Porting code to raspberry pi from source code? (Non code

Fri Jul 22, 2016 9:39 am

The sources for well supported code which make use the autotools or cmake will be a good reference point because they are supposed to work. When they don't there's a much greater chance you can assume you have done something wrong (typically a missing package). Over the years I've had to port or custom build a lot of code. The result is I tend to use a wrapper script which I modify as required and as such is self documenting. Here's a minimal version..

Code: Select all

$ sudo apt-get install wget
$ cd
$ mkdir -p usr/src/python
$ cd usr/src/python
$ touch go && chmod u+x go
Paste this into the "go" file..

Code: Select all

#!/bin/bash

NAM=`basename "$0"`

CWD=`pwd`
ARC="Python-3.5.2"
SRC="$ARC"
OBJ="obj-$SRC"

PFX=`echo "$SRC" | sed -e 's,-,/,' -e 's/\.//g' | awk '{print toupper($1);}'`
#PFX="/usr/local/""$PFX"
PFX="$HOME""/""$PFX"

CFGOPT="
--prefix=$PFX
"

for i in hlp.log cfg.log mak.log ins.log rem.log
do
    touch "$CWD/$i" || exit 1
done
MAKE="make"

fcp_usage ()
{
cat<<EOF
${NAM}: [ arc | gen | cfg | mak | ins | rem | del ]
${NAM}: arc [ -d | -z ]
${NAM}: obj [ obj | src | gen | all ]
EOF
}

fcp_jproc ()
{
 echo "$(cat /proc/cpuinfo | grep ^processor | wc -l) / 2 + 1" | bc
}

fcp_arc_d ()
{
 ( \
 tar xvJf "$ARC.tar.xz" \
 ) || exit 1
}

fcp_arc ()
{
 [[ $# -lt 1 ]] && {
    fcp_usage
    exit 1
 }

 case "$1" in
    -d)
    fcp_arc_d
    ;;

    *)
    fcp_usage
    exit 1
    ;;
 esac
}

fcp_cfg ()
{
 CC='ccache gcc'
 CXX='ccache g++'
# export CC CXX  

 ( \
 mkdir -p "$OBJ" && \
 cd "$OBJ" && \
 "../$SRC/configure" --help 2>&1 | tee "$CWD/hlp.log" && \
 "../$SRC/configure" $CFGOPT "$@" 2>&1 | tee "$CWD/cfg.log" \
 ) || exit 1
}

fcp_mak ()
{
 ( \
 cd "$OBJ" && \
 ${MAKE} "$@" 2>&1 | tee "$CWD/mak.log" \
 ) || exit 1
}

[[ $# -lt 1 ]] && {
    fcp_usage
    exit 1
}

fcp_ins ()
{
 ( \
 cd "$OBJ" && \
 ${MAKE} "$@" install 2>&1 | tee "$CWD/ins.log" \
 ) || exit 1
}

fcp_rem ()
{
 ( \
 cd "$OBJ" && \
 ${MAKE} "$@" uninstall 2>&1 | tee "$CWD/rem.log" \
 ) || exit 1
}

fcp_del ()
{
 case "$1" in
    obj)
    rm -rf "$OBJ" || exit 1
    ;;

    src)
    rm -rf "$SRC" || exit 1
    ;;

    all)
    fcp_del obj
    fcp_del src
    rm -f ???.log *~
    ;;

    *)
    fcp_usage
    exit 1
    ;;
 esac
}

fcp_tst ()
{
 ( \
 cd "$OBJ" && \
 ${MAKE} test 2>&1 | tee "$CWD/tst.log" \
 ) || exit 1

}

fcp_run ()
{
 PATH="$PFX""/bin":"$PATH" \
 LD_LIBRARY_PATH="$PFX""/lib":"$LD_LIBARY_PATH" \
 python3 "$@"
}

ARG="$1"
shift

case "$ARG" in
    arc)
    fcp_arc "$@"
    ;;

    cfg)
    fcp_cfg "$@"
    ;;

    mak)
    fcp_mak "$@"
    ;;

    ins)
    fcp_ins "$@"
    ;;

    rem)
    fcp_rem "$@"
    ;;

    del)
    fcp_del "$@"
    ;;

    run)
    fcp_run ver.py
    ;;

    all)
    [ -f "$ARC".tar.xz ]  || {
        wget -c https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tar.xz
    }
    [ -d "$ARC" ] || fcp_arc -d
    fcp_cfg
    fcp_mak -j`fcp_jproc`
    ./go ins
#    fcp_del all
    ;;

    tst)
    fcp_tst
    ;;

    *)
    fcp_usage
    exit 1
    ;;
esac
I've preconfigured to build the latest stable python3 and tested it builds okay last night on an rpi2..

Code: Select all

$ ./go all
If something goes wrong it'll probably be in the "configure" phase and likely due to a missing package. You'll find that output mirrored into "cfg.log".

The autotools usually fall into three operations..
$ ./configure
$ make
$ make install

These equate to..
$ ./go cfg
$ ./go mak
$ ./go ins

I've set the script to install into "~/PYTHON/352/" thus this new python will not interfere with the official versions. A common mistake when learning is accidentally not setting "--prefix" to 'configure' to somewhere out of the way - you can end up stomping over system packages. The downside is it can often be tricky to run the thing. If all goes well above..

$ ./go run

..is a hint how to go about running it.

You will come to notice that this builds "outside the source tree". This is preferable because it leaves the unpacked sources untainted by the build. That is: "Python-3.5.2" is the untainted source and "obj-Python-3.5.2" is where all the compiled code ends up.

It'll take a while to build btw!

Vaspi
Posts: 23
Joined: Sun Jul 03, 2016 10:07 am
Location: Wales

Re: Porting code to raspberry pi from source code? (Non code

Fri Jul 22, 2016 9:24 pm

Cool, thanks that's a great start alough I do not understand most of the terms etc I am quite a quick learner.

Been messing with retro pi so I will have to get a another sd to start but thank you for the detailed post and example script. Thank you very much
Dougie Lawson Fan club

Return to “General programming discussion”