Testing out a `makeheaders` build system.

parent a5e817c1
CC = gcc
CFLAGS = -fopenmp -I./lib/duktape -Os -pedantic -std=c99 -Wall -fstrict-aliasing -fomit-frame-pointer -D_GNU_SOURCE
ifeq ($(OS),Windows_NT)
BIN = dukboot.exe
else
BIN = dukboot
endif
SRC = $(wildcard src/*.c)
HEADERS = $(SRC:.c=.h)
OBJS = $(SRC:.c=.o)
DEPS = $(wildcard lib/duktape/*.o)
main: $(HEADERS) $(OBJS) $(DEPS)
$(CC) $(CFLAGS) -o $(BIN) $(OBJS) $(DEPS) $(LDFLAGS) -lm
%.h: $(SRC)
makeheaders src/*.c
%.o: %.c
$(CC) $< -c -o $@ $(CFLAGS)
clean:
$(foreach c, $(BINS), $(RM) $(c);)
$(RM) $(OBJS) $(HEADERS)
test:
@./test.sh
.PHONY: test all clean install uninstall
#include <duktape.h>
#include "app_assert_safe_path.h"
duk_int_t app_assert_safe_path (duk_context *ctx) {
// Safety check filename argument
duk_require_string(ctx, -1);
......
#include <duktape.h>
#include "app_push_argv.h"
int app_push_argv(duk_context *ctx, int argc, char *argv[]) {
// Construct argv array
duk_idx_t argv_idx = duk_push_array(ctx);
......
#include "duktape.h"
#include <dirent.h>
#include "app_push_dir.h"
int app_push_dir (duk_context *ctx) {
// Safety check filename argument
app_assert_safe_path(ctx);
......
#include "duktape.h"
#include "app_push_environ.h"
int app_push_environ(duk_context *ctx) {
int keylen = 0;
char *val;
......
#include "duktape.h"
#include "app_push_trusted_function.h"
int app_push_trusted_function (duk_context *ctx) {
// Safety check filename argument
app_assert_safe_path(ctx);
......
#include "duktape.h"
#include "app_stash_global_string.h"
void app_stash_global_string(duk_context *ctx, char *name) {
duk_push_global_stash(ctx); // summon the magic stash object
duk_get_global_string(ctx, name);
......
#include "duktape.h"
#include "app_unstash_global_string.h"
void app_unstash_global_string(duk_context *ctx, char *name) {
duk_push_global_stash(ctx); // summon the magic stash object
// TODO: Throw an error if property not found. (Right now just returns undefined)
......
// Autogenerated by the Queen of Hearts, who cut off everyone's head and added a semicolon.
#ifndef FILE_WONDERLAND
#define FILE_WONDERLAND
// Forward declare everything
duk_int_t app_assert_safe_path (duk_context *ctx);
int app_push_argv(duk_context *ctx, int argc, char *argv[]);
int app_push_dir (duk_context *ctx);
int app_push_environ(duk_context *ctx);
int app_push_trusted_function (duk_context *ctx);
void app_stash_global_string(duk_context *ctx, char *name);
void app_unstash_global_string(duk_context *ctx, char *name);
char* c_join_paths(const char *base, const char *filename);
int c_read_script_file (const char *joined_path, char **message, char **buffer, size_t *bytesRead);
int native_import (duk_context *ctx, const char *filename);
duk_ret_t native_print(duk_context *ctx);
int queue_create(duk_context *ctx, char *name);
int queue_push_queue(duk_context *ctx, char *name);
// Include everything
#include "app_assert_safe_path.c"
#include "app_push_argv.c"
#include "app_push_dir.c"
#include "app_push_environ.c"
#include "app_push_trusted_function.c"
#include "app_stash_global_string.c"
#include "app_unstash_global_string.c"
#include "c_join_paths.c"
#include "c_read_script_file.c"
#include "native_import.c"
#include "native_print.c"
#include "queue/queue_create.c"
#include "queue/queue_push_queue.c"
#endif /* !FILE_WONDERLAND */
#include "duktape.h"
#include <libgen.h>
#include "c_join_paths.h"
char* c_join_paths(const char *base, const char *filename) {
int base_len = strlen(base);
int filename_len = strlen(filename);
......
#include <stdio.h>
#include "duktape.h"
#include "c_read_script_file.h"
int c_read_script_file (const char *joined_path, char **message, char **buffer, size_t *bytesRead) {
// Open the file
FILE * pFile = fopen(joined_path, "rb");
......
......@@ -4,11 +4,6 @@
extern char **environ;
// Include dependencies
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <libgen.h>
#include <string.h>
#ifdef _WIN32
// @see [1]
......@@ -19,7 +14,7 @@ extern char **environ;
#include "duktape.h"
// Include all our functions
#include "autogenerated.h"
#include "main.h"
int main(int argc, char *argv[] /* char *environ[] */) {
// Re-open stdin and stdout in binary mode
......@@ -32,7 +27,7 @@ int main(int argc, char *argv[] /* char *environ[] */) {
#endif
if (argc < 2) {
printf("Usage: dukboots file-to-eval.js\n");
printf("Usage: dukboot file-to-eval.js\n");
printf("Yup. Pretty basic API at the moment.\n");
exit(0);
}
......
#include "duktape.h"
#include "native_import.h"
int native_import (duk_context *ctx, const char *filename) {
char *message = NULL;
char *buffer = NULL;
......
#include "duktape.h"
#include "native_print.h"
duk_ret_t native_print(duk_context *ctx) {
duk_push_string(ctx, " ");
duk_insert(ctx, 0);
......
#include "duktape.h"
#include "queue_create.h"
int queue_create(duk_context *ctx, char *name) {
// Create a top-level Array on the heap stash with the given name
duk_push_heap_stash(ctx);
......
#include "duktape.h"
#include "queue_push_queue.h"
int queue_push_queue(duk_context *ctx, char *name) {
duk_push_heap_stash(ctx);
duk_get_prop_string(ctx, -1, name);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment