From ee80c7abdfd0ab8b6491af6985928d536545fbf3 Mon Sep 17 00:00:00 2001 From: sandyx86 Date: Wed, 24 Jul 2024 02:28:34 -0500 Subject: [PATCH] fix makefile --- YSArray.h | 17 +++++++++++++++++ YSArray.m | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ YSObject.m | 4 ++++ makefile | 27 ++++++++++++++++++++++++-- 4 files changed, 102 insertions(+), 2 deletions(-) create mode 100644 YSArray.h create mode 100644 YSArray.m diff --git a/YSArray.h b/YSArray.h new file mode 100644 index 0000000..4b13992 --- /dev/null +++ b/YSArray.h @@ -0,0 +1,17 @@ +#ifndef YSARRAY_H +#define YSARRAY_H + +#import "YSObject.h" + +@interface YSArray : YSObject { + @public //public so you can index it directly + id *array; + int count; +} + +-(void) addObject: (id) theObject; +-(void) removeObject: (unsigned int) index; + +@end + +#endif \ No newline at end of file diff --git a/YSArray.m b/YSArray.m new file mode 100644 index 0000000..22b7fca --- /dev/null +++ b/YSArray.m @@ -0,0 +1,56 @@ +#import "YSArray.h" +#include +#include + +@implementation YSArray +-(id) init { + self = [super init]; + array = NULL; + return self; +} + +-(void) addObject: (id) theObject { + printf("%s\n", "YSArray: addObject"); + + if (array == NULL) { + printf("%s\n", "before malloc"); + array = malloc(sizeof(id)); + + if (array == NULL) { + printf("%s\n", "addObject: malloc failed."); + return; + } + + printf("%s\n", "after malloc"); + } else { + printf("%s\n", "before realloc"); + array = realloc(array, count * sizeof(id)); + + if (array == NULL) { + printf("%s\n", "addObject: realloc failed."); + return; + } + } + + array[count++] = theObject; + printf("%s\n", "YSArray: object added."); +} + +-(void) removeObject: (unsigned int) index { + if (count == 0 || count == 1) { + array[0] = NULL; + return; + } + + if (index >= count) { + return; + } + + if (index == count - 1) { + array[count - 1] = NULL; + } + + //hope count > index; + memcpy(&array[index], &array[index + 1], (count - index) * sizeof(id)); +} +@end \ No newline at end of file diff --git a/YSObject.m b/YSObject.m index 5be872d..dc5c425 100644 --- a/YSObject.m +++ b/YSObject.m @@ -6,6 +6,10 @@ #import "YSObject.h" #import "YSZone.h" +#ifdef __MINGW32__ +#define DLLSPEC __declspec(dllexport) +#endif + typedef struct obj_layout_unpadded { int32_t retained; } unp; diff --git a/makefile b/makefile index c208283..13ed922 100644 --- a/makefile +++ b/makefile @@ -1,7 +1,30 @@ SHELL=/bin/sh CC=gcc -yeslib.a: +LIB := -L +OS := +ifeq ($(OS),windows) +LIB += lib/win64 +CC=x86_64-w64-mingw32-gcc +endif + +ifeq ($(OS),linux) +LIB += lib/linux64 +endif + +LIB += -lobjc + +static: $(CC) YSObject.m -c $(CC) YSZone.m -c - ar rcs libyeslib.a YSObject.o YSZone.o \ No newline at end of file + $(CC) YSArray.m -c + ar rcs libyeslib.a YSObject.o YSZone.o YSArray.o + +shared: + $(CC) YSObject.m -c + $(CC) YSZone.m -c + $(CC) YSArray.m -c + $(CC) -shared -fPIC -o yeslib.dll YSObject.o YSZone.o YSArray.o $(LIB) + +clean: + rm *.o \ No newline at end of file