HCore targets are required to build applications, running under governing of some operating system, like Windows or Linux. Target itself is a collection of files, located at some directory in the CCORE_ROOT/Target directory. The name of the directory is the target name. CCore uses GNU-compatible make-based build system. To build an application for the particular target you specify the target name as one of the build variable in a makefile. There is a special target Vanilla-H. This target is a template for any host target. If you want to create a new HCore target, you may start from this "vanilla" target.
Here is the file layout for required HCore target files. You may add additional features to your target by adding extra source files.
TARGET_ROOT Makefile Makefile.tools CCore inc base PlatformBase.h Quick.h sys SysAbort.h SysAtomic.h SysCon.h SysError.h SysFile.h SysFileSystem.h SysMemPage.h SysNet.h SysPlanInit.h SysProp.h SysSem.h SysTask.h SysTime.h SysTlsSlot.h SysWait.h src base PlatformBase.cpp PlatformBase.s Quick.cpp Quick.s sys SysAbort.cpp SysAtomic.cpp SysAtomic.s SysCon.cpp SysError.cpp SysFile.cpp SysFileSystem.cpp SysMemPage.cpp SysNet.cpp SysPlanInit.cpp SysProp.cpp SysSem.cpp SysTask.cpp SysTime.cpp SysTlsSlot.cpp SysWait.cpp PlanInit_CCore.cpp test test6XXX.NNN.cpp obj empty test Makefile main.cpp test-obj empty
Target code from the directory sys enclosed in the namespace Sys (inside the namespace CCore).
Target code from the file Quick.h enclosed in the namespace Quick (inside the namespace CCore).
Makefile is used to build the CCore.a library. It's standard and looks like
CCORE_ROOT = ../.. CCORE_TARGET = TARGET_NAME SRC_PATH_LIST = $(CCORE_ROOT)/Simple/CCore/src \ $(CCORE_ROOT)/Fundamental/CCore/src \ $(CCORE_ROOT)/Applied/CCore/src \ $(CCORE_ROOT)/HCore/CCore/src \ $(CCORE_ROOT)/Target/$(CCORE_TARGET)/CCore/src \ GEN_PATH_LIST = include $(CCORE_ROOT)/Target/Makefile.core
Makefile.tools defines toolset to build CCore target applications. It looks like (WIN32 example)
CCOPT_EXTRA ?= LDOPT_EXTRA ?= # tools ECHO = /usr/bin/echo FIND = /bin/find MKDIR = /bin/mkdir CAT = /usr/bin/cat TOUCH = /usr/bin/touch CC_ = /opt/gcc-5.2.0/bin/g++-5.2.0.exe CC = @$(ECHO) CC $< ; $(CC_) LD = @$(ECHO) LD $@ ; $(CC_) AS_ = as AS = @$(ECHO) AS $< ; $(AS_) AR_ = ar AR = @$(ECHO) AR $@ ; $(AR_) RM_ = rm -f RM = @$(ECHO) RM ; $(RM_) # options NOWARN = -Wno-non-virtual-dtor \ -Wno-switch \ -Wno-type-limits \ -Wno-enum-compare \ -Wno-missing-field-initializers \ -Wno-delete-non-virtual-dtor \ CCINC = -I$(CCORE_ROOT)/Target/$(CCORE_TARGET) \ -I$(CCORE_ROOT)/HCore \ -I$(CCORE_ROOT)/Simple \ -I$(CCORE_ROOT)/Fundamental \ -I$(CCORE_ROOT)/Applied \ CCOPT = -c -std=c++14 -fwrapv -O3 -Wall -Wextra $(NOWARN) $(CCINC) $(CCOPT_EXTRA) ASOPT = CCORELIB = $(CCORE_ROOT)/Target/$(CCORE_TARGET)/CCore.a LDOPT = -Wl,-s $(LDOPT_EXTRA) $(CCORELIB) -lws2_32 -lgmp
You define here the following variables:
ECHO — the standard Unix echo.
FIND — the standard Unix find.
MKDIR — the standard Unix mkdir.
CAT — the standard Unix cat.
TOUCH — the standard Unix touch.
CC — C++ compiler.
LD — linker.
AS — assembler.
AR — librarian.
RM — file delete command.
CCOPT — options for the C++ compiler. Among other they must specify directories to search include files. The order of directories is: target include path, HCore include path, CCore include paths.
ASOPT — options for the assembler.
LDOPT — options for the linker. Linker options must specify the CCore.a library to be linked.
To give a path from the CCore file tree, you should use the variable CCORE_ROOT.
To compile a .cpp source file the following command is used:
$(CC) $(CCOPT) source-file -o object-file
To generate a dependency file the following command is used:
$(CC) $(CCOPT) -MM -MT object-file source-file -MF dep-file
To compile an .asm source file the following command is used:
$(AS) $(ASOPT) source-file -o object-file
To link an application the following command is used:
$(LD) object-file-list $(LDOPT) -o exe-file
To build a library the following commands are used:
$(RM) lib-file $(AR) r lib-file object-file-list
CCore/test is the directory for target-specific tests. The file names here must have the following form: test6XXX.NNN.cpp. 6XXX is a decimal test number, starts from 6001. NNN is some name of the test.
Makefile from the test directory is used to build the target test application. It has the following standard form
CCORE_ROOT = ../../.. CCORE_TARGET = TARGET_NAME SRC_PATH_LIST = . \ $(CCORE_ROOT)/Simple/CCore/test \ $(CCORE_ROOT)/Fundamental/CCore/test \ $(CCORE_ROOT)/Applied/CCore/test \ $(CCORE_ROOT)/HCore/CCore/test \ $(CCORE_ROOT)/Target/$(CCORE_TARGET)/CCore/test \ OBJ_PATH = ../test-obj TARGET = main.exe include $(CCORE_ROOT)/Target/Makefile.app run: main.exe ./main.exe
main.cpp from the test directory is the main file of the target test application. It looks like
#include <CCore/test/test.h> #include <CCore/inc/MemBase.h> #include <CCore/inc/PacketPool.h> namespace App { /* Testit<0> */ template<> const char *const Testit<0>::Name="Test0 empty"; template<> bool Testit<0>::Main() { return false; } } // namespace App /* main() */ using namespace App; int main() { MemScope mem_scope; Testit<2999>().run(); Printf(Con,"\nPeak memory usage #;\n\n",MemPeak()); DetachPacketBufs(); return 0; }
To run a particular test edit the test number.
There are three most desired extra features any well-designed target must provide: the fast and quality random number generator, the fast integer arithmetic and the fast cryptography. The modern CPU and SoC often has a hardware support for these tasks.
TARGET_ROOT CCore inc PlatformRandom.h math IntegerFastAlgo.h crypton PlatformAES.h PlatformMD5.h PlatformSHA.h src PlatformRandom.cpp PlatformRandom.s math IntegerFastAlgo.cpp IntegerFastAlgo.s crypton PlatformAES.cpp PlatformAES.s PlatformMD5.cpp PlatformMD5.s PlatformSHA.cpp PlatformSHA.s
If the correspondent files are absent, the default implementation will be used.