From 83ef347dde9f218c358954fd4a3c0512cd0f189c Mon Sep 17 00:00:00 2001 From: nishi Date: Sun, 28 Apr 2024 12:52:45 +0000 Subject: [PATCH] add gnu make support git-svn-id: file:///raid/svn-main/nishi-serenade/trunk@78 0f02c867-ac3d-714e-8a88-971ba1f6efcf --- GNUmakefile | 47 ++++++++++++++++++++++++++++++++++++++++++ Serenade/interpreter.c | 15 +------------- 2 files changed, 48 insertions(+), 14 deletions(-) create mode 100644 GNUmakefile diff --git a/GNUmakefile b/GNUmakefile new file mode 100644 index 0000000..6067024 --- /dev/null +++ b/GNUmakefile @@ -0,0 +1,47 @@ +# $Id$ + +CPP = cpp +CC = cc +CFLAGS = -std=c99 -fPIC -g `$(CPP) -DCFLAGS cmdline | grep -vE "^\#" | tr '\\n' ' '` +LDFLAGS = +LIBS = `$(CPP) -DLIBS cmdline | grep -vE "^\#" | tr '\\n' ' '` +EXTRA_OBJS = `$(CPP) -DOBJS cmdline | grep -vE "^\#" | tr '\\n' ' '` +SUFFIX = +SUFFIX_SO = .so +PREFIX_SO = lib + +ifneq ("$(PLATFORM)", "") +include "platforms/${PLATFORM}.mk" +endif + +.PHONY: all ./Serenade ./Tool replace format + +all: ./Tool ./config.h ./Serenade + +./Tool:: + $(MAKE) -C ./Tool CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" LIBS="$(LIBS)" SUFFIX="$(SUFFIX)" + +./config.h: + if [ ! -e ./Tool/configgen ]; then $(MAKE) ./Tool ; fi + ./Tool/configgen $@ + +./Serenade:: + $(MAKE) -C ./Serenade CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" LIBS="$(LIBS)" SUFFIX="$(SUFFIX)" EXTRA_OBJS="$(EXTRA_OBJS)" SUFFIX_SO="$(SUFFIX_SO)" PREFIX_SO="$(PREFIX_SO)" + +clean: + $(MAKE) -C ./Tool clean + $(MAKE) -C ./Serenade clean SUFFIX_SO="$(SUFFIX_SO)" PREFIX_SO="$(PREFIX_SO)" + rm -f config.h + +FILES = `find . -name "*.c" -or -name "*.h"` + +replace: + for i in $(FILES); do \ + echo -n "$$i ... "; \ + perl replace.pl < $$i > $$i.new; \ + mv $$i.new $$i; \ + echo "done"; \ + done + +format: + clang-format -i $(FILES) diff --git a/Serenade/interpreter.c b/Serenade/interpreter.c index eca8225..3e1ae4c 100644 --- a/Serenade/interpreter.c +++ b/Serenade/interpreter.c @@ -180,33 +180,20 @@ struct sn_interpreter* sn_create_interpreter(void) { void sn_interpreter_free(struct sn_interpreter* sn) { int i; - for(i = 0; sn->variables[i] != NULL; i++); - void** ptrs = malloc(sizeof(void*) * (i + 1)); for(i = 0; sn->variables[i] != NULL; i++) { - ptrs[i] = sn->variables[i]->value; free(sn->variables[i]->key); if(sn->variables[i]->value != NULL) sn_generic_free(sn->variables[i]->value); free(sn->variables[i]); } - ptrs[i] = NULL; free(sn->variables); for(i = 0; sn->generics[i] != NULL; i++) { int j; for(j = 0; sn->generics[i][j] != NULL; j++){ - int k; - bool found = false; - for(k = 0; ptrs[k] != NULL; k++){ - if(ptrs[k] == sn->generics[i][j]){ - found = true; - break; - } - } - if(!found) sn_generic_free(sn->generics[i][j]); + sn_generic_free(sn->generics[i][j]); } free(sn->generics[i]); } free(sn->generics); - free(ptrs); free(sn); } -- 2.43.0