Add Makefile for OpenBSD

This commit is contained in:
Evan Burkey 2023-10-30 14:22:11 -07:00
parent 0b5a11ce8c
commit 42bc366e01
4 changed files with 45 additions and 2 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@ cmake*
build
compile_commands.json
site
libflint.so

29
Makefile Normal file
View File

@ -0,0 +1,29 @@
.PHONY : clean
CFLAGS = -std=c99 -Iinclude -pedantic -Wall -Wextra
LDFLAGS = -fPIC -shared
TARGET = libflint.so
SRC != ls src/*.c
OBJ = $(SRC:./src/$.c=./obj/%.o)
PREFIX = $(DESTDIR)/usr/local
LIBDIR = $(PREFIX)/lib
all: $(TARGET)
$(TARGET): $(OBJ)
cc $(CFLAGS) $(LDFLAGS) -o $(TARGET) $(OBJ)
./obj/%.o: ./src/%.c
cc $(CFLAGS) -c $< -o $@
install: $(TARGET)
cp $(TARGET) $(LIBDIR)
uninstall:
rm -f $(LIBDIR)/$(TARGET)
clean:
rm -f $(TARGET)

View File

@ -75,4 +75,5 @@ Point *bresenham(int x0, int y0, int x1, int y1, size_t *sz) {
Point *bresenham_p(Point p1, Point p2, size_t *sz) {
return bresenham(p1.x, p1.y, p2.x, p2.y, sz);
}
}

View File

@ -31,7 +31,13 @@ int vec_init_with_capacity(Vector *vec, void (*destroy)(void *data), size_t capa
static int vec_grow(Vector *const vec) {
vec->capacity *= 2;
#ifdef __OpenBSD__
vec->elements = reallocarray(vec->elements, vec->capacity, sizeof(void *));
#else
vec->elements = reallocf(vec->elements, sizeof(void *) * vec->capacity);
#endif
if (vec->elements == NULL) {
return -1;
}
@ -106,7 +112,13 @@ int vec_shrink(Vector *vec) {
}
vec->capacity = vec_len(vec);
vec->elements = reallocf(vec, sizeof(void*) * vec_cap(vec));
#ifdef __OpenBSD__
vec->elements = reallocarray(vec->elements, vec->capacity, sizeof(void *));
#else
vec->elements = reallocf(vec->elements, sizeof(void *) * vec->capacity);
#endif
if (vec->elements == NULL) {
return -1;
}