GameLib is a collection of libraries for creating applications in Cakelisp.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

117 lines
3.3 KiB

(import "Dependencies.cake" "CHelpers.cake")
(export-and-evaluate
(add-c-search-directory-module "Dependencies/TinyCC")
(c-import "libtcc.h"))
;;
;; Tests
;;
(comptime-cond
('auto-test
(c-import "<stdio.h>")
(defun tcc-handle-error-printf (userdata (* void) message (* (const char)))
(fprintf (type-cast userdata (* FILE)) "%s\n" message))
(defun test--tiny-c-compiler (&return int)
(var tcc-state (* TCCState) (tcc_new))
(unless tcc-state
(return 1))
(tcc_set_error_func tcc-state stderr tcc-handle-error-printf)
(tcc_add_include_path tcc-state "Dependencies/TinyCC")
(tcc_add_include_path tcc-state "Dependencies/TinyCC/include")
(tcc_set_lib_path tcc-state "cakelisp_cache/TinyCCBuildDir")
(tcc_set_output_type tcc-state TCC_OUTPUT_MEMORY)
(var test-program (* (const char)) #"#
#include <tcclib.h>
void test(void)
{
fprintf(stderr, "Hello from TCC!\n");
}
#"#)
(when (= -1 (tcc_compile_string tcc-state test-program))
(return 1))
(unless (>= 0 (tcc_relocate tcc-state TCC_RELOCATE_AUTO))
(return 1))
(def-function-signature test-func-signature ())
(var-cast-to test-func test-func-signature (tcc_get_symbol tcc-state "test"))
(unless test-func
(return 1))
(test-func)
(tcc_delete tcc-state)
(return 0))))
;;
;; Building
;;
(defun-comptime build-tiny-cc (manager (& ModuleManager) module (* Module) &return bool)
(comptime-cond
('Windows
(comptime-error "Need to add Windows support to TinyCC"))
('Unix
(var tinycc-build-dir (* (const char)) "cakelisp_cache/TinyCCBuildDir")
(var tinycc-expect-file ([] 1024 char) (array 0))
(SafeSnprintf tinycc-expect-file (array-size tinycc-expect-file) "%s/libtcc.a" tinycc-build-dir)
;; Add dependency
(call-on push_back (field manager environment additionalStaticLinkObjects) tinycc-expect-file)
;; Already built?
;; We could enhance this by checking for modifications, but that's pretty rare
(when (fileExists tinycc-expect-file)
(return true))
(Log "TinyCC: Building via Configure and Make\n")
(makeDirectory tinycc-build-dir)
(run-process-sequential-or
("sh" "../../Dependencies/TinyCC/configure" :in-directory tinycc-build-dir)
(Log
"failed at TinyCC configure step. This requires a sh/bash-style shell to execute.\n")
(return false))
(run-process-sequential-or
("make" :in-directory tinycc-build-dir)
(Log "failed at TinyCC make. This tool requires Makefile support.\n")
(return false))
;; One final to check to ensure everything's good to go
(unless (fileExists tinycc-expect-file)
(Log
"error: TinyCC build sequence completed, but files are not where expected. Is there an issue
with the configuration?\n")
(return false)))
(true
(comptime-error "need to define platform, e.g. (comptime-define-symbol 'Unix), or your platform
has not been implemented yet.")))
(Log "TinyCC: Successfully built\n")
(return true))
(add-compile-time-hook-module pre-build build-tiny-cc)
(add-c-search-directory-module "Dependencies/TinyCC")
(comptime-cond
('Unix
(add-library-dependency "dl")
(add-library-dependency "pthread")))
;; This is an unofficial mirror
(add-dependency-git-submodule
clone-tiny-cc
"git://repo.or.cz/tinycc.git"
;; "https://github.com/TinyCC/TinyCC" ;; unofficial mirror
"Dependencies/TinyCC")