| | 1 | In this document, we'll port an existing app to MutekH. We'll choose a standard publicly available application: `bc`. |
| | 2 | |
| | 3 | bc is a command-line arbitrary precision calculator well known in the unix world. It uses standard APIs, makes reasonable use of I/O, and has a quite verifiable result. |
| | 4 | |
| | 5 | = Getting the source tree = |
| | 6 | |
| | 7 | Let's begin getting the source, and unpack it: |
| | 8 | {{{ |
| | 9 | $ wget http://ftp.gnu.org/pub/gnu/bc/bc-1.06.tar.gz |
| | 10 | $ tar xzvf bc-1.06.tar.gz |
| | 11 | }}} |
| | 12 | |
| | 13 | = Creating our source tree = |
| | 14 | |
| | 15 | Now create another directory, and extract the meaningful sources |
| | 16 | {{{ |
| | 17 | $ mkdir mutekh_port |
| | 18 | $ cd mutekh_port |
| | 19 | $ mkdir src lib h |
| | 20 | $ cp ../bc-1.06/bc/*.[ch] bc |
| | 21 | $ cp ../bc-1.06/lib/*.[ch] lib |
| | 22 | $ cp ../bc-1.06/h/*.h src |
| | 23 | }}} |
| | 24 | |
| | 25 | Let's create the Makefiles: |
| | 26 | |
| | 27 | * `bc/Makefile` |
| | 28 | {{{ |
| | 29 | objs = bc.o execute.o global.o load.o main.o scan.o storage.o util.o |
| | 30 | |
| | 31 | DIR_CFLAGS=-I$(srcdir)/../lib -I$(srcdir)/../h -I$(srcdir)/.. -U__MUTEK__ |
| | 32 | scan.o_CFLAGS=-DEINTR=-1024 |
| | 33 | }}} |
| | 34 | * `lib/Makefile` |
| | 35 | {{{ |
| | 36 | objs = getopt.o getopt1.o number.o getenv.o |
| | 37 | |
| | 38 | DIR_CFLAGS=-I$(srcdir)/../lib -I$(srcdir)/../h -I$(srcdir)/.. -U__MUTEK__ -DHAVE_CONFIG_H |
| | 39 | }}} |
| | 40 | * `Makefile` |
| | 41 | {{{ |
| | 42 | subdirs = bc lib |
| | 43 | }}} |
| | 44 | |
| | 45 | = Providing glue code = |
| | 46 | |
| | 47 | Now let's create some glue code: |
| | 48 | * As this is userland-specific, MutekH does not define |
| | 49 | * `getenv()` |
| | 50 | * `signal()` |
| | 51 | * `sys/types.h` |
| | 52 | We will have to provide them. |
| | 53 | |
| | 54 | Add a `lib/getenv.c` file: |
| | 55 | {{{ |
| | 56 | #include <hexo/types.h> |
| | 57 | |
| | 58 | char *getenv(const char *env) |
| | 59 | { |
| | 60 | return NULL; |
| | 61 | } |
| | 62 | }}} |
| | 63 | |
| | 64 | Add a `signal.h` file: |
| | 65 | {{{ |
| | 66 | #define SIGINT 0 |
| | 67 | |
| | 68 | static inline int signal(int sig, void *handler) |
| | 69 | { |
| | 70 | return -1; |
| | 71 | } |
| | 72 | }}} |
| | 73 | |
| | 74 | Create a `sys` directory, and a `sys/types.h` file containing: |
| | 75 | {{{ |
| | 76 | #define isatty(x) 1 |
| | 77 | #define fileno(x) 0 |
| | 78 | #define fopen(x,y) NULL |
| | 79 | |
| | 80 | #include <hexo/types.h> |
| | 81 | }}} |
| | 82 | |
| | 83 | = The MutekH configuration file = |
| | 84 | |
| | 85 | FInally, let's create a configuration file. For instance, with the mutekh_tutorial soclib platform, we may use the following config: |
| | 86 | {{{ |
| | 87 | # Application license |
| | 88 | CONFIG_LICENSE_APP_GPL |
| | 89 | |
| | 90 | # Platform types |
| | 91 | CONFIG_ARCH_SOCLIB |
| | 92 | |
| | 93 | # Processor types |
| | 94 | CONFIG_CPU_ARM |
| | 95 | CONFIG_CPU_ARM_SOCLIB |
| | 96 | |
| | 97 | # Mutek features |
| | 98 | CONFIG_PTHREAD |
| | 99 | CONFIG_MUTEK_CONSOLE |
| | 100 | |
| | 101 | CONFIG_LIBC_STREAM |
| | 102 | CONFIG_LIBC_STREAM_STD |
| | 103 | |
| | 104 | CONFIG_HEXO_INTTYPES_DEPRECATED undefined |
| | 105 | |
| | 106 | # Device drivers |
| | 107 | CONFIG_DRIVER_CHAR_SOCLIBTTY |
| | 108 | CONFIG_DRIVER_ICU_SOCLIB |
| | 109 | |
| | 110 | # Code compilation options |
| | 111 | CONFIG_COMPILE_DEBUG |
| | 112 | CONFIG_COMPILE_OPTIMIZE 2 |
| | 113 | |
| | 114 | # New source code module to be compiled |
| | 115 | CONFIG_MODULES bc:%CONFIGPATH |
| | 116 | }}} |
| | 117 | |
| | 118 | That's all, we finished porting our app ! |
| | 119 | |
| | 120 | = Compiling and running = |
| | 121 | |
| | 122 | {{{ |
| | 123 | user@host … caba-vgmn-mutekh_tutorial $ make CONFIG=config_soclib_arm APP=/path/to/mutek_port/src MUTEKH_DIR=path/to/mutekh |
| | 124 | … |
| | 125 | LD o .../caba-vgmn-mutekh_tutorial/mutekh/kernel-soclib-arm.o |
| | 126 | LD out .../caba-vgmn-mutekh_tutorial/mutekh/kernel-soclib-arm.out |
| | 127 | soclib-cc -P -p .../caba-vgmn-mutekh_tutorial/platform_desc -o system.x |
| | 128 | [-------------------------------------------------------------------------=] 0 left |
| | 129 | user@host … caba-vgmn-mutekh_tutorial $ ./simulation.x |
| | 130 | }}} |