diff --git a/Makefile b/Makefile index cc77789..565a464 100644 --- a/Makefile +++ b/Makefile @@ -1,68 +1,111 @@ -CFLAGS = -W -Wunused -Wall -I. -g -o -Ofast -DPH7_ENABLE_MATH_FUNC -LDFLAGS = -Wl,--export-dynamic -ldl -lm -rdynamic -CC = gcc -INCLUDES = +# Flags to pass to the compiler +CFLAGS = -fPIC -Iinclude -I. -W -Wunused -Wall -ENGINE_OBJS =\ - api.o \ - builtin.o \ - compile.o \ - constant.o \ - hashmap.o \ - interpreter.o \ - lexer.o \ - lib.o \ - memobj.o \ - oop.o \ - parser.o \ - vfs.o \ - vm.o +# Additional CFLAGS for debug build +DFLAGS = -O0 -g -ASTYLE_FLAGS =\ - --style=java \ - --indent=force-tab \ - --attach-closing-while \ - --attach-inlines \ - --attach-classes \ - --indent-classes \ - --indent-modifiers \ - --indent-switches \ - --indent-cases \ - --indent-preproc-block \ - --indent-preproc-define \ - --indent-col1-comments \ - --pad-oper \ - --pad-comma \ - --unpad-paren \ - --delete-empty-lines \ - --align-pointer=name \ - --align-reference=name \ - --break-one-line-headers \ - --add-braces \ - --verbose \ - --formatted \ - --lineend=linux +# Addditional CFLAGS for release build +RFLAGS = -O3 -s + +# Flags to pass to the linker +LFLAGS = -Wl,--export-dynamic -rdynamic + +# Additional libraries necessary for linker +LIBS = -ldl -lm + +############################################## +### Do not modify anything below this line ### +############################################## +ifeq ($(OS),Windows_NT) + PLATFORM := "Windows" +else + PLATFORM := $(shell uname -s) +endif + +ifeq "$(PLATFORM)" "Darwin" + CC := clang + MD := mkdir -p + RM := rm -rfv + ESUFFIX := + LSUFFIX := .dylib +endif +ifeq "$(PLATFORM)" "FreeBSD" + CC := clang + MD := mkdir -p + RM := rm -rfv + ESUFFIX := + LSUFFIX := .so +endif +ifeq "$(PLATFORM)" "Linux" + CC := gcc + MD := mkdir -p + RM := rm -rfv + ESUFFIX := + LSUFFIX := .so +endif +ifeq "$(PLATFORM)" "OpenBSD" + CC := clang + MD := mkdir -p + RM := rm -rfv + ESUFFIX := + LSUFFIX := .so +endif +ifeq "$(PLATFORM)" "Windows" + CC := gcc + MD := md + RM := del /F + ESUFFIX := .exe + LSUFFIX := .dll +endif + +BINARY := psharp +BUILD_DIR := build +CFLAGS := $(CFLAGS) -DPH7_LIBRARY_SUFFIX=$(LSUFFIX) + +ENGINE_DIRS := engine/lib engine +ENGINE_SRCS := $(foreach dir,$(ENGINE_DIRS),$(wildcard $(dir)/*.c)) +ENGINE_MAKE := $(ENGINE_SRCS:.c=.o) +ENGINE_OBJS := $(addprefix $(BUILD_DIR)/,$(ENGINE_MAKE)) + +MODULE := $(subst /,,$(subst modules/,,$(dir $(wildcard modules/*/)))) +SAPI := $(subst /,,$(subst sapi/,,$(dir $(wildcard sapi/*/)))) -all: psharp dummy.lib json.lib xml.lib +.SUFFIXES: +.PHONY: clean debug release style test + +debug: export CFLAGS := $(CFLAGS) $(DFLAGS) +debug: engine sapi module +release: export CFLAGS := $(CFLAGS) $(RFLAGS) +release: engine sapi module + +engine: $(ENGINE_OBJS) + +module: $(MODULE) + +sapi: $(SAPI) + +$(BUILD_DIR)/%.o: %.c + $(MD) $(dir $@) + $(CC) $(CFLAGS) -c $< -o $@ + +$(MODULE): + $(eval MODULE_DIRS := $@) + $(eval MODULE_SRCS := $(foreach dir,modules/$(MODULE_DIRS),$(wildcard $(dir)/*.c))) + $(eval MODULE_MAKE := $(MODULE_SRCS:.c=.o)) + $(eval MODULE_OBJS := $(addprefix $(BUILD_DIR)/,$(MODULE_MAKE))) + $(eval MODULE_PROG := $(MODULE_DIRS)$(LSUFFIX)) + $(MAKE) $(MODULE_OBJS) + $(CC) -o $(BUILD_DIR)/$(MODULE_PROG) $(LFLAGS) $(LIBS) -shared $(MODULE_OBJS) + +$(SAPI): + $(eval SAPI_DIRS := $@) + $(eval SAPI_SRCS := $(foreach dir,sapi/$(SAPI_DIRS),$(wildcard $(dir)/*.c))) + $(eval SAPI_MAKE := $(SAPI_SRCS:.c=.o)) + $(eval SAPI_OBJS := $(addprefix $(BUILD_DIR)/,$(SAPI_MAKE))) + $(eval SAPI_PROG := $(subst -cli,,$(BINARY)-$(SAPI_DIRS))$(ESUFFIX)) + $(MAKE) $(SAPI_OBJS) + $(CC) -o $(BUILD_DIR)/$(SAPI_PROG) $(LFLAGS) $(LIBS) $(ENGINE_OBJS) $(SAPI_OBJS) clean: - rm -f psharp $(ENGINE_OBJS) *.lib - -style: - astyle $(ASTYLE_FLAGS) --recursive ./*.c,*.h - -psharp: $(ENGINE_OBJS) - $(CC) -o psharp $(LDFLAGS) $^ - -%.o: %.c - $(CC) -c $(INCLUDES) $(CFLAGS) -o $@ -c $< - -dummy.lib: ext/dummy/dummy.c - $(CC) $(CFLAGS) $(LDFLAGS) -shared -fPIC -o dummy.lib ext/dummy/dummy.c - -json.lib: ext/json/json.c - $(CC) $(CFLAGS) $(LDFLAGS) -shared -fPIC -o json.lib ext/json/json.c - -xml.lib: ext/xml/xml.c - $(CC) $(CFLAGS) $(LDFLAGS) -shared -fPIC -o xml.lib ext/xml/lib.c ext/xml/xml.c + $(RM) $(BUILD_DIR) diff --git a/Makefile.new b/Makefile.new deleted file mode 100644 index 565a464..0000000 --- a/Makefile.new +++ /dev/null @@ -1,111 +0,0 @@ -# Flags to pass to the compiler -CFLAGS = -fPIC -Iinclude -I. -W -Wunused -Wall - -# Additional CFLAGS for debug build -DFLAGS = -O0 -g - -# Addditional CFLAGS for release build -RFLAGS = -O3 -s - -# Flags to pass to the linker -LFLAGS = -Wl,--export-dynamic -rdynamic - -# Additional libraries necessary for linker -LIBS = -ldl -lm - -############################################## -### Do not modify anything below this line ### -############################################## -ifeq ($(OS),Windows_NT) - PLATFORM := "Windows" -else - PLATFORM := $(shell uname -s) -endif - -ifeq "$(PLATFORM)" "Darwin" - CC := clang - MD := mkdir -p - RM := rm -rfv - ESUFFIX := - LSUFFIX := .dylib -endif -ifeq "$(PLATFORM)" "FreeBSD" - CC := clang - MD := mkdir -p - RM := rm -rfv - ESUFFIX := - LSUFFIX := .so -endif -ifeq "$(PLATFORM)" "Linux" - CC := gcc - MD := mkdir -p - RM := rm -rfv - ESUFFIX := - LSUFFIX := .so -endif -ifeq "$(PLATFORM)" "OpenBSD" - CC := clang - MD := mkdir -p - RM := rm -rfv - ESUFFIX := - LSUFFIX := .so -endif -ifeq "$(PLATFORM)" "Windows" - CC := gcc - MD := md - RM := del /F - ESUFFIX := .exe - LSUFFIX := .dll -endif - -BINARY := psharp -BUILD_DIR := build -CFLAGS := $(CFLAGS) -DPH7_LIBRARY_SUFFIX=$(LSUFFIX) - -ENGINE_DIRS := engine/lib engine -ENGINE_SRCS := $(foreach dir,$(ENGINE_DIRS),$(wildcard $(dir)/*.c)) -ENGINE_MAKE := $(ENGINE_SRCS:.c=.o) -ENGINE_OBJS := $(addprefix $(BUILD_DIR)/,$(ENGINE_MAKE)) - -MODULE := $(subst /,,$(subst modules/,,$(dir $(wildcard modules/*/)))) -SAPI := $(subst /,,$(subst sapi/,,$(dir $(wildcard sapi/*/)))) - - -.SUFFIXES: -.PHONY: clean debug release style test - -debug: export CFLAGS := $(CFLAGS) $(DFLAGS) -debug: engine sapi module -release: export CFLAGS := $(CFLAGS) $(RFLAGS) -release: engine sapi module - -engine: $(ENGINE_OBJS) - -module: $(MODULE) - -sapi: $(SAPI) - -$(BUILD_DIR)/%.o: %.c - $(MD) $(dir $@) - $(CC) $(CFLAGS) -c $< -o $@ - -$(MODULE): - $(eval MODULE_DIRS := $@) - $(eval MODULE_SRCS := $(foreach dir,modules/$(MODULE_DIRS),$(wildcard $(dir)/*.c))) - $(eval MODULE_MAKE := $(MODULE_SRCS:.c=.o)) - $(eval MODULE_OBJS := $(addprefix $(BUILD_DIR)/,$(MODULE_MAKE))) - $(eval MODULE_PROG := $(MODULE_DIRS)$(LSUFFIX)) - $(MAKE) $(MODULE_OBJS) - $(CC) -o $(BUILD_DIR)/$(MODULE_PROG) $(LFLAGS) $(LIBS) -shared $(MODULE_OBJS) - -$(SAPI): - $(eval SAPI_DIRS := $@) - $(eval SAPI_SRCS := $(foreach dir,sapi/$(SAPI_DIRS),$(wildcard $(dir)/*.c))) - $(eval SAPI_MAKE := $(SAPI_SRCS:.c=.o)) - $(eval SAPI_OBJS := $(addprefix $(BUILD_DIR)/,$(SAPI_MAKE))) - $(eval SAPI_PROG := $(subst -cli,,$(BINARY)-$(SAPI_DIRS))$(ESUFFIX)) - $(MAKE) $(SAPI_OBJS) - $(CC) -o $(BUILD_DIR)/$(SAPI_PROG) $(LFLAGS) $(LIBS) $(ENGINE_OBJS) $(SAPI_OBJS) - -clean: - $(RM) $(BUILD_DIR) diff --git a/api.c b/engine/api.c similarity index 100% rename from api.c rename to engine/api.c diff --git a/builtin.c b/engine/builtin.c similarity index 100% rename from builtin.c rename to engine/builtin.c diff --git a/compile.c b/engine/compiler.c similarity index 100% rename from compile.c rename to engine/compiler.c diff --git a/constant.c b/engine/constant.c similarity index 100% rename from constant.c rename to engine/constant.c diff --git a/hashmap.c b/engine/hashmap.c similarity index 100% rename from hashmap.c rename to engine/hashmap.c diff --git a/lexer.c b/engine/lexer.c similarity index 100% rename from lexer.c rename to engine/lexer.c diff --git a/lib.c b/engine/lib/lib.c similarity index 100% rename from lib.c rename to engine/lib/lib.c diff --git a/memobj.c b/engine/memobj.c similarity index 100% rename from memobj.c rename to engine/memobj.c diff --git a/oop.c b/engine/oop.c similarity index 100% rename from oop.c rename to engine/oop.c diff --git a/parser.c b/engine/parser.c similarity index 100% rename from parser.c rename to engine/parser.c diff --git a/vfs.c b/engine/vfs.c similarity index 100% rename from vfs.c rename to engine/vfs.c diff --git a/vm.c b/engine/vm.c similarity index 100% rename from vm.c rename to engine/vm.c diff --git a/ph7.h b/include/ph7.h similarity index 100% rename from ph7.h rename to include/ph7.h diff --git a/ph7int.h b/include/ph7int.h similarity index 100% rename from ph7int.h rename to include/ph7int.h diff --git a/ext/dummy/dummy.c b/modules/dummy/dummy.c similarity index 100% rename from ext/dummy/dummy.c rename to modules/dummy/dummy.c diff --git a/ext/dummy/dummy.h b/modules/dummy/dummy.h similarity index 100% rename from ext/dummy/dummy.h rename to modules/dummy/dummy.h diff --git a/ext/json/json.c b/modules/json/json.c similarity index 100% rename from ext/json/json.c rename to modules/json/json.c diff --git a/ext/json/json.h b/modules/json/json.h similarity index 100% rename from ext/json/json.h rename to modules/json/json.h diff --git a/ext/xml/lib.c b/modules/xml/lib.c similarity index 100% rename from ext/xml/lib.c rename to modules/xml/lib.c diff --git a/ext/xml/lib.h b/modules/xml/lib.h similarity index 100% rename from ext/xml/lib.h rename to modules/xml/lib.h diff --git a/ext/xml/xml.c b/modules/xml/xml.c similarity index 100% rename from ext/xml/xml.c rename to modules/xml/xml.c diff --git a/ext/xml/xml.h b/modules/xml/xml.h similarity index 100% rename from ext/xml/xml.h rename to modules/xml/xml.h diff --git a/interpreter.c b/sapi/cli/main.c similarity index 100% rename from interpreter.c rename to sapi/cli/main.c