From 11cc8d666d3092a1474a848eae1397c5a49c156f Mon Sep 17 00:00:00 2001 From: Avril Date: Fri, 19 Mar 2021 20:18:50 +0000 Subject: [PATCH] added make install and uninstall targets C linkage for state and generator mutation --- Makefile | 24 +++++++++++++++++++++++- include/state.h | 6 ++++-- src/dev.h | 4 ++++ src/gen.cpp | 3 +-- src/state.cpp | 4 ++-- 5 files changed, 34 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index def55cd..ebe10dc 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,10 @@ PROJECT=sm AUTHOR=Avril (Flanchan) +VERSION=1.0.0 + +ifeq ($(PREFIX),) + PREFIX := /usr/local +endif SRC_C = $(wildcard src/*.c) SRC_CXX = $(wildcard src/*.cpp) @@ -9,7 +14,9 @@ TEST_SRC_CXX = $(wildcard src/test/*.cpp) INCLUDE=include -COMMON_FLAGS= -W -Wall -pedantic -fno-strict-aliasing $(addprefix -I,$(INCLUDE)) +HEADERS=$(INCLUDE)/*.h + +COMMON_FLAGS= -D_VERSION=$(VERSION) -W -Wall -pedantic -fno-strict-aliasing $(addprefix -I,$(INCLUDE)) OPT_FLAGS?= -march=native -fgraphite -fopenmp -floop-parallelize-all -ftree-parallelize-loops=4 \ -floop-interchange -ftree-loop-distribution -floop-strip-mine -floop-block \ @@ -52,6 +59,9 @@ debug: | dirs lib$(PROJECT)-debug.so lib$(PROJECT)-debug.a .PHONY: test test: | dirs $(PROJECT)-test +.PHONY: install +.PHONY: uninstall + # Targets dirs: @@ -102,3 +112,15 @@ clean-rebuild: clean: clean-rebuild rm -f lib$(PROJECT){-debug,}.{so,a} rm -f $(PROJECT)-test + +install: | dirs lib$(PROJECT).a lib$(PROJECT).so + install -d $(DESTDIR)$(PREFIX)/lib/ + install -m 644 lib$(PROJECT).a $(DESTDIR)$(PREFIX)/lib/ + install -m 755 lib$(PROJECT).so $(DESTDIR)$(PREFIX)/lib/ + install -d $(DESTDIR)$(PREFIX)/include/$(PROJECT)/ + install -m 644 $(HEADERS) $(DESTDIR)$(PREFIX)/include/$(PROJECT)/ + +uninstall: + rm $(DESTDIR)$(PREFIX)/lib/lib$(PROJECT).{a,so} + ls $(HEADERS) | xargs -I {} basename {} | xargs -I {} rm "$(DESTDIR)$(PREFIX)/include/$(PROJECT)/{}" + rmdir $(DESTDIR)$(PREFIX)/include/$(PROJECT) diff --git a/include/state.h b/include/state.h index ac43c76..d3db4d3 100644 --- a/include/state.h +++ b/include/state.h @@ -112,5 +112,7 @@ inline sm_yield sm_continue() { return (sm_yield)_sm_noop; } // --- -sm_state* sm_new_state(); -void sm_free_state(sm_state* state); +extern "C" { + sm_state* sm_new_state(); + void sm_free_state(sm_state* state); +} diff --git a/src/dev.h b/src/dev.h index 47f0ff3..f4f63a1 100644 --- a/src/dev.h +++ b/src/dev.h @@ -3,11 +3,15 @@ #ifdef __cplusplus +#define EX_C extern "C" + #include #define restrict __restrict__ [[noreturn]] #else +#define EX_C + #include __attribute__((noreturn)) diff --git a/src/gen.cpp b/src/gen.cpp index 61b5f8e..3d3ec71 100644 --- a/src/gen.cpp +++ b/src/gen.cpp @@ -1,6 +1,5 @@ #include - -#define EX_C extern "C" +#include "dev.h" struct sm_generator { diff --git a/src/state.cpp b/src/state.cpp index a8797d4..5e63fee 100644 --- a/src/state.cpp +++ b/src/state.cpp @@ -13,7 +13,7 @@ sm_yield _sm_noop(sm_state*) return (sm_yield)nullptr; } -sm_state* sm_new_state() +EX_C sm_state* sm_new_state() { auto state = box(); state->current = box<_sm_frame, true>(); @@ -54,7 +54,7 @@ inline static void _sm_free_all_pages(_sm_user_page* page) } } -void sm_free_state(sm_state* state) +EX_C void sm_free_state(sm_state* state) { _sm_frame* frame = unbox(state).current;