.DEFAULT_GOAL := all

define RAYLIB
(use-modules (system foreign))

(define lib (dynamic-link "libraylib.so"))

(define InitWindow
  (pointer->procedure void
    (dynamic-func "InitWindow" lib)
    (list int int '*)))

(define WindowShouldClose
  (pointer->procedure int
    (dynamic-func "WindowShouldClose" lib)
    '()))

(define BeginDrawing
  (pointer->procedure void
    (dynamic-func "BeginDrawing" lib)
    '()))

(define EndDrawing
  (pointer->procedure void
    (dynamic-func "EndDrawing" lib)
    '()))

(define ClearBackground
  (pointer->procedure void
    (dynamic-func "ClearBackground" lib)
    (list int)))

(define SetTargetFPS
  (pointer->procedure void
    (dynamic-func "SetTargetFPS" lib)
    (list int)))

(define CloseWindow
  (pointer->procedure void
    (dynamic-func "CloseWindow" lib)
    '()))

(display "[guile] raylib init\n")

(InitWindow 800 450 (string->pointer "makefile"))
(SetTargetFPS 60)

(let loop ()
  (if (= (WindowShouldClose) 0)
      (begin
        (BeginDrawing)
        (ClearBackground #x202020)
        (EndDrawing)
        (loop))
      (CloseWindow)))

#f
endef

$(guile $(RAYLIB))

all:
    @:
