Compiling REN-C and making some changes

So downloading the source from the repository page

https://github.com/metaeducation/ren-c

And follow the instructions (we are all on Linux now right!?) in the readme.md file. If this is your first time you should add a mkdir build before doing the cd to build.

export R3_MAKE="$(pwd)/prebuilt/r3-linux-x64-8994d23"
cd build
"$R3_MAKE" ../make.r config: ../configs/default-config.r

We now change some files. In rebmake.r before the first line with “Running:” we add the lines

if not null? find cmd "mod-view" [replace cmd "gcc -c " "gcc -c `pkg-config --cflags gtk+-3.0` "]
if not null? find cmd "gcc -o" [replace cmd "objs/main.o" "objs/main.o `pkg-config --libs gtk+-3.0`"]

In extensions/view/make-spec.r we delete some stuff and keep

libraries: _
options: []

in extensions/view/ext-view-init.reb we make everything a comment by putting a semicolon before every line.

And we experiment with the code in mod-view.r and add some GTK things in there.

Because of compilation times we extract our compilation strings from the log so we can develop a lot faster:

gcc -c `pkg-config --cflags gtk+-3.0` -Iprep/extensions/view -I../src/include -Iprep/include -DREB_API -DNDEBUG -DOS_STACK_GROWS_DOWN -DENDIAN_LITTLE -DHAS_LL_CONSTS -D_FILE_OFFSET_BITS=64 -DUSE_PIPE2_NOT_PIPE -D__LP64__ -DTO_LINUX -DTO_LINUX_X64 -O2 -fvisibility=hidden -o objs/view/mod-view.o ../extensions/view/mod-view.c

and

gcc -o r3 -fvisibility=hidden -rdynamic objs/a-constants.o objs/a-globals.o objs/a-lib.o objs/b-init.o objs/c-bind.o objs/c-do.o objs/c-context.o objs/c-error.o objs/c-eval.o objs/c-function.o objs/c-path.o objs/c-port.o objs/c-signal.o objs/c-specialize.o objs/c-value.o objs/c-word.o objs/d-crash.o objs/d-dump.o objs/d-eval.o objs/d-gc.o objs/d-print.o objs/d-stack.o objs/d-stats.o objs/d-test.o objs/d-trace.o objs/f-blocks.o objs/f-deci.o objs/f-device.o objs/f-dtoa.o objs/f-enbase.o objs/f-extension.o objs/f-int.o objs/f-math.o objs/f-modify.o objs/f-qsort.o objs/f-random.o objs/f-round.o objs/f-series.o objs/f-stubs.o objs/l-scan.o objs/l-types.o objs/m-gc.o objs/m-pools.o objs/m-series.o objs/m-stacks.o objs/n-control.o objs/n-data.o objs/n-do.o objs/n-error.o objs/n-function.o objs/n-io.o objs/n-loop.o objs/n-math.o objs/n-protect.o objs/n-reduce.o objs/n-sets.o objs/n-strings.o objs/n-system.o objs/s-cases.o objs/s-crc.o objs/s-find.o objs/s-make.o objs/s-mold.o objs/s-ops.o objs/t-binary.o objs/t-bitset.o objs/t-blank.o objs/t-block.o objs/t-char.o objs/t-datatype.o objs/t-date.o objs/t-decimal.o objs/t-function.o objs/t-integer.o objs/t-logic.o objs/t-map.o objs/t-money.o objs/t-object.o objs/t-pair.o objs/t-port.o objs/t-quoted.o objs/t-string.o objs/t-time.o objs/t-tuple.o objs/t-typeset.o objs/t-varargs.o objs/t-word.o objs/u-compress.o objs/u-parse.o objs/u-zlib.o objs/tmp-boot-block.o objs/tmp-type-hooks.o objs/gob/mod-gob.o objs/gob/t-gob.o objs/tmp-mod-gob-init.o objs/uuid/mod-uuid.o objs/uuid/libuuid/gen_uuid.o objs/uuid/libuuid/unpack.o objs/uuid/libuuid/pack.o objs/uuid/libuuid/randutils.o objs/tmp-mod-uuid-init.o objs/event/mod-event.o objs/event/t-event.o objs/event/p-event.o objs/event/event-posix.o objs/tmp-mod-event-init.o objs/bmp/mod-bmp.o objs/tmp-mod-bmp-init.o objs/time/mod-time.o objs/time/time-posix.o objs/tmp-mod-time-init.o objs/console/mod-console.o objs/tmp-mod-console-init.o objs/stdio/mod-stdio.o objs/stdio/p-stdio.o objs/stdio/stdio-posix.o objs/stdio/readline-posix.o objs/tmp-mod-stdio-init.o objs/library/mod-library.o objs/library/library-posix.o objs/tmp-mod-library-init.o objs/serial/mod-serial.o objs/serial/serial-posix.o objs/tmp-mod-serial-init.o objs/dns/mod-dns.o objs/tmp-mod-dns-init.o objs/crypt/mod-crypt.o objs/crypt/aes/aes.o objs/crypt/bigint/bigint.o objs/crypt/dh/dh.o objs/crypt/rc4/rc4.o objs/crypt/rsa/rsa.o objs/crypt/sha256/sha256.o objs/crypt/md5/u-md5.o objs/crypt/sha1/u-sha1.o objs/tmp-mod-crypt-init.o objs/image/mod-image.o objs/image/t-image.o objs/tmp-mod-image-init.o objs/gif/mod-gif.o objs/tmp-mod-gif-init.o objs/utf/mod-utf.o objs/tmp-mod-utf-init.o objs/network/mod-network.o objs/network/dev-net.o objs/tmp-mod-network-init.o objs/png/mod-png.o objs/png/lodepng.o objs/tmp-mod-png-init.o objs/debugger/mod-debugger.o objs/tmp-mod-debugger-init.o objs/secure/mod-secure.o objs/tmp-mod-secure-init.o objs/process/mod-process.o objs/process/call-posix.o objs/tmp-mod-process-init.o objs/vector/mod-vector.o objs/vector/t-vector.o objs/tmp-mod-vector-init.o objs/locale/mod-locale.o objs/tmp-mod-locale-init.o objs/jpg/mod-jpg.o objs/jpg/u-jpg.o objs/tmp-mod-jpg-init.o objs/filesystem/mod-filesystem.o objs/filesystem/p-file.o objs/filesystem/p-dir.o objs/filesystem/file-posix.o objs/tmp-mod-filesystem-init.o objs/view/mod-view.o objs/tmp-mod-view-init.o -lm -ldl objs/main.o `pkg-config --libs gtk+-3.0`

A quick overview of some code I have got now

// "warning: implicit declaration of function"

//
// export open-window: native [
// ]
//
REBNATIVE(open_window)
{
VIEW_INCLUDE_PARAMS_OF_OPEN_WINDOW;
REBINT n = 0;
n = open_my_window();
Init_Integer(D_OUT, n);
return D_OUT;
}

The empty line is important!

#include <gtk/gtk.h>

// Include the rebol core for the rebnative c-function
#include "sys-core.h"

#include "tmp-mod-view.h"

#define VIEW_LINUX_64_GTK

// Helper functions
static void
print_hello (GtkWidget *widget,
             gpointer   data)
{
  g_print ("Hello World\n");
}

static void
move_this_window (GtkWidget* widget,
                  gpointer   data)
{
   GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
   if (gtk_widget_is_toplevel (toplevel))
     {
       /* Perform action on toplevel. */
       const gchar *text_window = gtk_window_get_title (GTK_WINDOW (toplevel));
       g_print ("Hello again - %s \n", (char *) text_window);
       gtk_window_move (GTK_WINDOW (toplevel), 400, 600);
     }

}

static void
activate (GtkApplication* app,
          gpointer        user_data)
{
  GtkWidget *window;
  GtkWidget *grid;
  GtkWidget *button;

  window = gtk_application_window_new (app);
  gtk_window_set_title (GTK_WINDOW (window), "REN-C Window");
  gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER_ALWAYS);
  gtk_window_set_default_size (GTK_WINDOW (window), 500, 500);

  gtk_container_set_border_width (GTK_CONTAINER (window), 10);

  /* Here we construct the container that is going pack our buttons */
  grid = gtk_grid_new ();

  /* Pack the container in the window */
  gtk_container_add (GTK_CONTAINER (window), grid);

  button = gtk_button_new_with_label ("Move me!");
  g_signal_connect (button, "clicked", G_CALLBACK (move_this_window), NULL);

  /* Place the first button in the grid cell (0, 0), and make it fill
   * just 1 cell horizontally and vertically (ie no spanning)
   */
  gtk_grid_attach (GTK_GRID (grid), button, 0, 0, 1, 1);

  button = gtk_button_new_with_label ("Print Hello");
  g_signal_connect (button, "clicked", G_CALLBACK (print_hello), NULL);

  /* Place the second button in the grid cell (1, 0), and make it fill
   * just 1 cell horizontally and vertically (ie no spanning)
   */
  gtk_grid_attach (GTK_GRID (grid), button, 1, 0, 1, 1);

  button = gtk_button_new_with_label ("Quit");
  g_signal_connect_swapped (button, "clicked", G_CALLBACK (gtk_widget_destroy), window);

  /* Place the Quit button in the grid cell (0, 1), and make it
   * span 2 columns.
   */
  gtk_grid_attach (GTK_GRID (grid), button, 0, 1, 2, 1);

  /* Now that we are done packing our widgets, we show them all
   * in one go, by calling gtk_widget_show_all() on the window.
   * This call recursively calls gtk_widget_show() on all widgets
   * that are contained in the window, directly or indirectly.
   */
  gtk_widget_show_all (window);
}

int open_my_window ()
{
    GtkApplication *app;
    int status;
    int argc = 0;
    char **argv;
    app = gtk_application_new ("info.rebol.rencexample", G_APPLICATION_FLAGS_NONE);
    g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
    status = g_application_run (G_APPLICATION (app), argc, argv);

    g_object_unref (app);

    return status;
}

This works on my machine. It is a starting point of discovering more functionality and then gradually work forward to a real flexible solution. My take is do not just add everything at once, just what is essential.

Till next blog!

This entry was posted in Geen categorie. Bookmark the permalink.

Geef een reactie

Your email address will not be published. Required fields are marked *

Vul dit nog even in: * Time limit is exhausted. Please reload CAPTCHA.