Choose a more apt hash function for strings and fix build issues with cxstrings
This commit is contained in:
parent
d878589737
commit
cdf329065a
2
.gitignore
vendored
2
.gitignore
vendored
@ -9,3 +9,5 @@ obj
|
||||
test.cpp
|
||||
tester.cpp
|
||||
pc/librexy.pc
|
||||
makefile
|
||||
test
|
||||
|
||||
@ -19,6 +19,11 @@
|
||||
#ifndef REXY_CX_STRING_HPP
|
||||
#define REXY_CX_STRING_HPP
|
||||
|
||||
namespace rexy::cx{
|
||||
template<size_t N>
|
||||
class string;
|
||||
}
|
||||
|
||||
#include "../string_base.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
|
||||
@ -25,13 +25,19 @@
|
||||
|
||||
namespace rexy::cx{
|
||||
|
||||
//jenkns one at a time hash
|
||||
template<class Str>
|
||||
struct string_hash{
|
||||
constexpr size_t operator()(const Str& s, size_t salt = 0){
|
||||
size_t hash = 5381 + salt;
|
||||
size_t hash = salt;
|
||||
for(size_t i = 0;i < s.length();++i){
|
||||
hash = ((hash << 5) + hash) ^ s[i];
|
||||
hash += s[i];
|
||||
hash += (hash << 10);
|
||||
hash += (hash >> 6);
|
||||
}
|
||||
hash += (hash << 3);
|
||||
hash ^= (hash << 11);
|
||||
hash += (hash << 15);
|
||||
return hash;
|
||||
}
|
||||
};
|
||||
|
||||
227
makefile
227
makefile
@ -1,227 +0,0 @@
|
||||
#This program is free software: you can redistribute it and/or modify
|
||||
#it under the terms of the GNU General Public License as published by
|
||||
#the Free Software Foundation, either version 3 of the License, or
|
||||
#(at your option) any later version.
|
||||
|
||||
#This program is distributed in the hope that it will be useful,
|
||||
#but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
#GNU General Public License for more details.
|
||||
|
||||
#You should have received a copy of the GNU General Public License
|
||||
#along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#Copyright 2018-2020 rexy712
|
||||
|
||||
#Makefile to generate a single static or shared library from all the sources in SOURCE_DIRS ending in EXT
|
||||
|
||||
ifeq ($(OS),Windows_NT)
|
||||
WINDOWS::=1
|
||||
endif
|
||||
|
||||
SOURCE_DIRS::=rexy/src
|
||||
SOURCES::=
|
||||
OBJDIR::=obj
|
||||
DEPDIR::=$(OBJDIR)/dep
|
||||
LIBDIR::=lib
|
||||
INCLUDE_DIRS::=.
|
||||
CFLAGS::=-g -std=c18 -Wall -pedantic -Wextra
|
||||
CXXFLAGS::=-g -std=c++17 -Wall -pedantic -Wextra
|
||||
EXT::=cpp
|
||||
LANG::=$(EXT)
|
||||
MAIN_LIBRARY::=rexy
|
||||
PRE_TARGETS::=
|
||||
POST_TARGETS::=
|
||||
CLEAN_TARGETS::=clean_tester
|
||||
SHARED?=1
|
||||
STATIC?=0
|
||||
RELEASE?=0
|
||||
MEMCHK?=0
|
||||
|
||||
ifneq ($(WINDOWS),1)
|
||||
#*nix settings
|
||||
CC::=gcc
|
||||
CXX::=g++
|
||||
LDLIBS::=
|
||||
LDFLAGS::=
|
||||
STRIP::=strip
|
||||
RANLIB::=ranlib
|
||||
AR::=ar
|
||||
AS::=as
|
||||
else #windows
|
||||
#windows settings
|
||||
#windows is a fuckwit
|
||||
MINGW_PREFIX::=x86_64-w64-mingw32-
|
||||
CC::=$(MINGW_PREFIX)gcc
|
||||
CXX::=$(MINGW_PREFIX)g++
|
||||
LDLIBS::=
|
||||
LDFLAGS::=-static-libgcc -static-libstdc++
|
||||
STRIP::=$(MINGW_PREFIX)strip
|
||||
RANLIB::=$(MINGW_PREFIX)ranlib
|
||||
AR::=$(MINGW_PREFIX)ar
|
||||
AS::=$(MINGW_PREFIX)as
|
||||
endif #windows
|
||||
|
||||
#Put your custom targets for PRE_TARGETS and POST_TARGETS here:
|
||||
|
||||
tester: all
|
||||
$(CXX) tester.cpp -o tester $(CXXFLAGS) $(LDFLAGS) -L. -lrexy -I.
|
||||
|
||||
clean_tester:
|
||||
$(call rm,tester)
|
||||
|
||||
###########################################################################################################
|
||||
#Everything past this point is internal BS, probably best not to touch it unless you know what you're doing
|
||||
|
||||
#set the all target as the default target, otherwise the topmost target will run
|
||||
.DEFAULT_GOAL::=all
|
||||
|
||||
#setup the actual output library name depending on shared/static and windows/anything else
|
||||
ifeq ($(WINDOWS),1)
|
||||
INTERNAL_SHARED_LIBRARY::=lib$(MAIN_LIBRARY).a
|
||||
else
|
||||
INTERNAL_SHARED_LIBRARY::=lib$(MAIN_LIBRARY).so
|
||||
endif
|
||||
SHARED_LIBRARY_FLAGS=-fPIC
|
||||
DLLOUT::=$(MAIN_LIBRARY).dll
|
||||
INTERNAL_STATIC_LIBRARY::=lib$(MAIN_LIBRARY).a
|
||||
|
||||
|
||||
#system dependant bullshit
|
||||
ifeq ($(OS),Windows_NT)
|
||||
#windows' cmd commands
|
||||
mkdir=mkdir $(subst /,\,$(1)) > NUL 2>&1
|
||||
rm=del /F $(1) > NUL 2>&1
|
||||
rmdir=rd /S /Q $(1) > NUL 2>&1
|
||||
move=move /Y $(subst /,\,$(1)) $(subst /,\,$(2)) > NUL 2>&1
|
||||
copy=copy /Y /B $(subst /,\,$(1)) $(subst /,\,$(2)) > NUL 2>&1
|
||||
else
|
||||
#*nix terminal commands
|
||||
mkdir=mkdir -p $(1)
|
||||
rm=rm -f $(1)
|
||||
rmdir=rm -rf $(1)
|
||||
move=mv $(1) $(2)
|
||||
copy=cp $(1) $(2)
|
||||
endif
|
||||
|
||||
#setup compiler and flags based on language
|
||||
ifeq ($(LANG),cpp)
|
||||
COMPILER_FLAGS::=$(CXXFLAGS)
|
||||
COMPILER::=$(CXX)
|
||||
else ifeq ($(LANG),c)
|
||||
COMPILER_FLAGS::=$(CFLAGS)
|
||||
COMPILER::=$(CC)
|
||||
endif
|
||||
|
||||
ifeq ($(RELEASE),1)
|
||||
#a lot of false strict aliasing warnings from gcc 9
|
||||
COMPILER_FLAGS+=-O2 -Wno-strict-aliasing
|
||||
POST_TARGETS+= do_strip
|
||||
else ifeq ($(MEMCHK),1)
|
||||
#use asan to check memory leaks/invalid accesses
|
||||
LDFLAGS+=-fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls
|
||||
COMPILER_FLAGS+=-O0 -g3 -ggdb -fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls
|
||||
else
|
||||
#default target
|
||||
COMPILER_FLAGS+=-O0 -g3 -ggdb
|
||||
endif
|
||||
|
||||
#add dependency tracking and include directories
|
||||
INTERNAL_COMPILERFLAGS=-c $(foreach dir,$(INCLUDE_DIRS),-I"$(dir)") -MMD -MP -MF"$(DEPDIR)/$(notdir $(patsubst %.o,%.d,$@))"
|
||||
ifeq ($(SHARED),1)
|
||||
INTERNAL_COMPILERFLAGS+=$(SHARED_LIBRARY_FLAGS)
|
||||
endif
|
||||
THIS_MAKEFILE_NAME::=$(lastword $(MAKEFILE_LIST))
|
||||
INTERNAL_SOURCES::=$(SOURCES) $(foreach source,$(SOURCE_DIRS),$(foreach ext,$(EXT),$(wildcard $(source)/*.$(ext))))
|
||||
OBJECTS+=$(addprefix $(OBJDIR)/,$(subst \,.,$(subst /,.,$(addsuffix .o,$(INTERNAL_SOURCES)))))
|
||||
|
||||
#Arguments to make submake use this makefile without "Entering directory" stuff
|
||||
SUBMAKE_ARGUMENTS::=--no-print-directory -f "$(THIS_MAKEFILE_NAME)"
|
||||
#just a variable for a newline
|
||||
define \n
|
||||
|
||||
|
||||
endef
|
||||
|
||||
#default target: run targets in PRE_TARGETS, then build the main library, then POST_TARGETS
|
||||
.PHONY: all
|
||||
all:
|
||||
$(foreach target,$(PRE_TARGETS),@$(MAKE) $(SUBMAKE_ARGUMENTS) "$(target)"$(\n))
|
||||
ifeq ($(SHARED),1)
|
||||
ifeq ($(WINDOWS),1)
|
||||
@$(MAKE) $(SUBMAKE_ARGUMENTS) "$(DLLOUT)"
|
||||
else #windows
|
||||
@$(MAKE) $(SUBMAKE_ARGUMENTS) "$(INTERNAL_SHARED_LIBRARY)"
|
||||
endif #windows
|
||||
endif #shared
|
||||
ifeq ($(STATIC),1)
|
||||
ifeq ($(SHARED),1)
|
||||
@$(MAKE) $(SUBMAKE_ARGUMENTS) "object_clean"
|
||||
endif #shared
|
||||
@$(MAKE) $(SUBMAKE_ARGUMENTS) "$(INTERNAL_STATIC_LIBRARY)" SHARED=0
|
||||
endif #static
|
||||
$(foreach target,$(POST_TARGETS),@$(MAKE) $(SUBMAKE_ARGUMENTS) "$(target)"$(\n))
|
||||
|
||||
ifeq ($(WINDOWS),1)
|
||||
#target for windows shared library
|
||||
$(DLLOUT): $(OBJECTS)
|
||||
$(COMPILER) -shared -o "$(DLLOUT)" $^ -Wl,--out-implib,"lib$(MAIN_LIBRARY).a" $(SHARED_LIBRARY_FLAGS) $(LDLIBS) $(LDFLAGS)
|
||||
else #windows
|
||||
|
||||
#target for *nix shared library
|
||||
$(INTERNAL_SHARED_LIBRARY): $(OBJECTS)
|
||||
$(COMPILER) -shared -o "$@" $^ $(COMPILER_FLAGS) $(SHARED_LIBRARY_FLAGS) $(LDFLAGS) $(LDLIBS)
|
||||
endif #windows
|
||||
|
||||
#target for static library
|
||||
$(INTERNAL_STATIC_LIBRARY): $(OBJECTS)
|
||||
$(AR) rcs "$@" $^
|
||||
$(RANLIB) "$@"
|
||||
|
||||
|
||||
#Called in POST_TARGETS when RELEASE=1
|
||||
.PHONY: do_strip
|
||||
do_strip:
|
||||
ifeq ($(SHARED),1)
|
||||
$(STRIP) --strip-debug "$(INTERNAL_SHARED_LIBRARY)"
|
||||
endif
|
||||
ifeq ($(STATIC),1)
|
||||
$(STRIP) --strip-debug "$(INTERNAL_STATIC_LIBRARY)"
|
||||
endif
|
||||
|
||||
#Object target recipe
|
||||
define GENERATE_OBJECTS
|
||||
$$(OBJDIR)/$(subst \,.,$(subst /,.,$(1))).%.o: $(1)/%
|
||||
$$(COMPILER) $$(COMPILER_FLAGS) $$(INTERNAL_COMPILERFLAGS) "$$<" -o "$$@"
|
||||
endef
|
||||
define GENERATE_INDIVIDUAL_OBJECTS
|
||||
$$(OBJDIR)/$(subst \,.,$(subst /,.,$(1))).o: $(1)
|
||||
$$(COMPILER) $$(COMPILER_FLAGS) $$(INTERNAL_COMPILERFLAGS) "$$<" -o "$$@"
|
||||
endef
|
||||
|
||||
|
||||
#Create targets for object files
|
||||
$(foreach dir,$(SOURCE_DIRS),$(eval $(call GENERATE_OBJECTS,$(dir))))
|
||||
$(foreach src,$(SOURCES),$(eval $(call GENERATE_INDIVIDUAL_OBJECTS,$(src))))
|
||||
$(OBJECTS): | $(OBJDIR) $(DEPDIR)
|
||||
|
||||
$(OBJDIR):
|
||||
$(call mkdir,"$@")
|
||||
$(DEPDIR):
|
||||
$(call mkdir,"$@")
|
||||
|
||||
.PHONY: object_clean
|
||||
object_clean:
|
||||
$(call rmdir,"$(OBJDIR)")
|
||||
|
||||
.PHONY: clean
|
||||
clean: object_clean
|
||||
$(foreach target,$(CLEAN_TARGETS),@$(MAKE) $(SUBMAKE_ARGUMENTS) "$(target)"$(\n))
|
||||
$(call rmdir,"$(DEPDIR)")
|
||||
$(call rm,"lib$(MAIN_LIBRARY).so")
|
||||
$(call rm,"lib$(MAIN_LIBRARY).a")
|
||||
$(call rm,"$(DLLOUT)")
|
||||
|
||||
#header file dep tracking
|
||||
-include $(wildcard $(DEPDIR)/*.d)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user