| 1 | = Quick how to for adding program to HelenOS = |
| 2 | |
| 3 | Following steps are needed in order to add a program to HelenOS (i.e. executable that can be launched from HelenOS userspace shell). |
| 4 | |
| 5 | == Sources location == |
| 6 | Under one of `uspace/` directories. Use `app/` for standalone applications, `srv/` for system services or `drv/` for device drivers. |
| 7 | |
| 8 | Definitely put it inside its own subdirectory (e.g. `uspace/app/hello/`). |
| 9 | |
| 10 | The `main` uses standard signature `int main(int, char **)`. |
| 11 | |
| 12 | == `Makefile`s & co. == |
| 13 | Simplest way is to copy `Makefile` from other program and change two variables: |
| 14 | * `BINARY` to specify name of the compiled executable |
| 15 | * `SOURCES` to list C source files |
| 16 | |
| 17 | For a simple ''Hello World'' program, the `Makefile` would look like this (omitting the copyright notice): |
| 18 | {{{ |
| 19 | #!Makefile |
| 20 | USPACE_PREFIX = ../.. |
| 21 | BINARY = hello |
| 22 | SOURCES = hello.c |
| 23 | include $(USPACE_PREFIX)/Makefile.common |
| 24 | }}} |
| 25 | |
| 26 | == Compiling == |
| 27 | To compile the program, add the directory name (e.g. `app/hello`) to `DIRS` variable in `uspace/Makefile`. |
| 28 | |
| 29 | == Adding it to the image == |
| 30 | Last thing that needs to be done is to add the compiled executable to the image file (e.g. `image.iso` for IA-32). That is done by adding the executable filename to a variable in `boot/Makefile.common`. |
| 31 | For services use the `RD_SRVS_*` variable, for application use `RD_APPS_*`. The suffix is either `ESSENTIAL` or `NON_ESSENTIAL`. |
| 32 | |
| 33 | == Complete diff == |
| 34 | Below is a diff (with copyrights omitted) for a ''Hello World''. |
| 35 | {{{ |
| 36 | === modified file 'boot/Makefile.common' |
| 37 | --- boot/Makefile.common 2011-06-12 15:44:38 +0000 |
| 38 | +++ boot/Makefile.common 2011-06-12 20:45:19 +0000 |
| 39 | @@ -142,6 +142,7 @@ |
| 40 | $(USPACE_PATH)/app/dload/dload \ |
| 41 | $(USPACE_PATH)/app/edit/edit \ |
| 42 | $(USPACE_PATH)/app/ext2info/ext2info \ |
| 43 | + $(USPACE_PATH)/app/hello/hello \ |
| 44 | $(USPACE_PATH)/app/kill/kill \ |
| 45 | $(USPACE_PATH)/app/killall/killall \ |
| 46 | $(USPACE_PATH)/app/mkfat/mkfat \ |
| 47 | |
| 48 | === modified file 'uspace/Makefile' |
| 49 | --- uspace/Makefile 2011-06-12 15:44:38 +0000 |
| 50 | +++ uspace/Makefile 2011-06-12 20:44:44 +0000 |
| 51 | @@ -39,6 +39,7 @@ |
| 52 | app/edit \ |
| 53 | app/ext2info \ |
| 54 | app/getterm \ |
| 55 | + app/hello \ |
| 56 | app/init \ |
| 57 | app/kill \ |
| 58 | app/killall \ |
| 59 | |
| 60 | === added directory 'uspace/app/hello' |
| 61 | === added file 'uspace/app/hello/Makefile' |
| 62 | --- uspace/app/hello/Makefile 1970-01-01 00:00:00 +0000 |
| 63 | +++ uspace/app/hello/Makefile 2011-06-12 20:43:41 +0000 |
| 64 | @@ -0,0 +1,12 @@ |
| 65 | +# |
| 66 | +# Copyright omitted |
| 67 | +# |
| 68 | + |
| 69 | +USPACE_PREFIX = ../.. |
| 70 | + |
| 71 | +BINARY = hello |
| 72 | +SOURCES = \ |
| 73 | + hello.c |
| 74 | + |
| 75 | +include $(USPACE_PREFIX)/Makefile.common |
| 76 | + |
| 77 | |
| 78 | === added file 'uspace/app/hello/hello.c' |
| 79 | --- uspace/app/hello/hello.c 1970-01-01 00:00:00 +0000 |
| 80 | +++ uspace/app/hello/hello.c 2011-06-12 20:44:18 +0000 |
| 81 | @@ -0,0 +1,9 @@ |
| 82 | +/* Copyright omitted */ |
| 83 | + |
| 84 | +#include <stdio.h> |
| 85 | + |
| 86 | +int main(int argc, char * argv[]) { |
| 87 | + printf("Hello World!\n"); |
| 88 | + return 0; |
| 89 | +} |
| 90 | + |
| 91 | }}} |