Skip to content

Build system proposal #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 CoderRC

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
80 changes: 80 additions & 0 deletions Makefile.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
srcdir=@srcdir@
VPATH=$(srcdir):bin

prefix=@prefix@

CC=@CC@
DEFS=@DEFS@
DEFAULT_INCLUDES=-I@srcdir@/include
INCLUDES=$(notdir null/)
CPPFLAGS=@CPPFLAGS@
CFLAGS=@CFLAGS@
LDFLAGS=@LDFLAGS@
AR=@AR@
ARFLAGS=r
OBJEXT=@OBJEXT@
SOURCES=@SOURCES@
OBJECTS=$(patsubst $(srcdir)/source/%.cpp, obj/%.$(OBJEXT), $(SOURCES))
INCLUDE_DIRECTORIES=@INCLUDE_DIRECTORIES@
INCLUDE_FILES=@INCLUDE_FILES@

# New variables for enhanced functionality
LIB_NAME = msg-sdk-cpp

# Platform-specific library names
ifeq ($(OS),Windows_NT)
LIB_SHARED = lib/lib$(LIB_NAME).dll
LIB_IMPORT = lib/lib$(LIB_NAME).lib
else
LIB_SHARED = lib/lib$(LIB_NAME).so
endif

.PHONY: all clean static shared install

all: compile_objects compile_library compile_include shared

compile_objects: obj $(OBJECTS)

obj/%.$(OBJEXT): $(srcdir)/source/%.c
@mkdir -p $(@D)
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) -c $< -o $@

obj/%.$(OBJEXT): $(srcdir)/source/%.cpp
@mkdir -p $(@D)
$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) -c $< -o $@

obj:
mkdir -p obj

compile_library: lib lib/lib$(LIB_NAME).a

lib/lib$(LIB_NAME).a: $(OBJECTS)
$(AR) $(ARFLAGS) $@ $?

lib:
mkdir -p lib

compile_include: $(addprefix $(CURDIR)/, $(INCLUDE_DIRECTORIES)) $(addprefix $(CURDIR)/, $(INCLUDE_FILES))

$(addprefix $(CURDIR)/, $(INCLUDE_DIRECTORIES)):
mkdir -p $@

$(addprefix $(CURDIR)/, $(INCLUDE_FILES)): $(CURDIR)/%: %
cp -R $< $(@:$(CURDIR)/%=%)

# Shared library target
shared: $(LIB_SHARED)

$(LIB_SHARED): $(OBJECTS)
ifeq ($(OS),Windows_NT)
$(CC) -shared -o $@ $^ $(LDFLAGS) -Wl,--out-implib,$(LIB_IMPORT)
else
$(CC) -shared -o $@ $^ $(LDFLAGS)
endif

install:
cp -R lib/* $(prefix)/lib
cp -R include/* $(prefix)/include

clean:
rm -rf obj lib
77 changes: 77 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# msg-sdk-cpp
An end-to-end encrypted cli messaging sdk based on the Noise Protocol, using sockets and tcp transports.

## Build

#### 1. Clone Source
git clone https://github.com/codehubbers/msg-sdk-cpp.git
cd msg-sdk-cpp

#### 2. Build
mkdir build
cd build
../configure
make

## Install
make install

## Requirements

Download a bash command line environment to run configure.

Download git to use the git command for cloning the source.

Download gcc to compile the source and configure it.

Download make to compile the library.

Download noiseprotocol library to use the Noise Protocol offered by efecan0 if can not find download then compile it from source can be found and analysed here

If the bash command line environment supports the pacman command do

pacman -S git
pacman -S mingw-w64-x86_64-gcc
pacman -S mingw-w64-x86_64-g++
pacman -S make
pacman -S mingw-w64-x86_64-autotools
pacman -S bison
pacman -S flex
git clone https://github.com/CoderRC/libmingw32_extended.git
cd libmingw32_extended
mkdir build
cd build
../configure
make
make install
cd ../..
git clone https://github.com/CoderRC/noise-c.git
cd noise-c
./autogen.sh
mkdir build
cd build
../configure LDFLAGS=-lmingw32_extended
make
make install
cd ../..
git clone https://github.com/codehubbers/msg-sdk-cpp.git
cd msg-sdk-cpp
mkdir build
cd build
../configure LDFLAGS=-lmingw32_extended
make

## Tests

Go to the tests branch to create tests for this repository.

## Contributing to the source

To properly add new sources to the repository, the sources must be added to the source directory in the repository and in the configure file add paths to the SOURCES.

To properly add new include directories to the repository, the include directories must be added to the include directory in the repository and in the configure file add include paths to the INCLUDE_DIRECTORIES.

To properly add new headers to the repository, the headers must be added to the include directory in the repository and in the configure file add paths to the INCLUDE_FILES.

## Functions Completed and Can Be Used In Your Projects:
none for now just connect_to_host made to be an example
133 changes: 133 additions & 0 deletions build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# ========= CONFIGURABLE =========
$SourceDir = "source"
$BuildDir = "build"
$InstallDir = "install"

# ========= TOOL DETECTION & INSTALL =========
function Install-Packages {
Write-Host "Installing required packages..."

$REQUIRED_PACKAGES = @("git", "gcc", "g++", "make", "autotools", "bison", "flex")

if ($env:MSYSTEM -and $env:MSYSTEM -match "MINGW") {
Write-Host "Detected MSYS2"
foreach ($pkg in $REQUIRED_PACKAGES) {
$mingwPkg = "mingw-w64-x86_64-$pkg"
pacman -Sy --noconfirm $mingwPkg 2>$null
if ($LASTEXITCODE -ne 0) {
pacman -Sy --noconfirm $pkg 2>$null
}
}
}
elseif (Get-Command apt -ErrorAction SilentlyContinue) {
Write-Host "Detected Debian/Ubuntu"
sudo apt update
sudo apt install -y $REQUIRED_PACKAGES
}
elseif (Get-Command dnf -ErrorAction SilentlyContinue) {
Write-Host "Detected Fedora"
sudo dnf install -y $REQUIRED_PACKAGES
}
elseif (Get-Command yum -ErrorAction SilentlyContinue) {
Write-Host "Detected RHEL/CentOS"
sudo yum install -y $REQUIRED_PACKAGES
}
elseif (Get-Command zypper -ErrorAction SilentlyContinue) {
Write-Host "Detected openSUSE"
sudo zypper install -y $REQUIRED_PACKAGES
}
elseif (Get-Command a-g -ErrorAction SilentlyContinue) {
Write-Host "Detected a-g"
foreach ($pkg in $REQUIRED_PACKAGES) {
echo y | a-g install "a-g-install-${pkg}-using-source"
echo y | a-g-install-${pkg}-using-source
}
}
else {
Write-Host "Could not detect package manager. Please install manually: $($REQUIRED_PACKAGES -join ', ')"
exit 1
}
}

function Check-And-Install {
$tools = @("git", "gcc", "g++", "make", "autoconf", "automake", "bison", "flex")
$missing = @()

foreach ($tool in $tools) {
if (-not (Get-Command $tool -ErrorAction SilentlyContinue)) {
$missing += $tool
}
}

if ($missing.Count -gt 0) {
Write-Host "Missing tools: $($missing -join ', ')"
Install-Packages
}
}

# ========= BUILD FUNCTIONS =========
function Create-BuildDir {
if (-not (Test-Path -Path $BuildDir)) {
New-Item -ItemType Directory -Path $BuildDir | Out-Null
}
}

function Compile-Sources {
Write-Host "Compiling sources..."

Push-Location $BuildDir
try {
# Run configure with LDFLAGS
& sh -c "../configure LDFLAGS=-lmingw32_extended"

if ($LASTEXITCODE -ne 0) {
Write-Error "configure script failed"
exit 2
}

# Run make
& "make"

if ($LASTEXITCODE -ne 0) {
Write-Error "Build failed"
exit 3
}
}
finally {
Pop-Location
}
}

function Run-Tests {
Write-Host "Running compiled tests..."
Push-Location $BuildDir
try {
& "make" "test"
if ($LASTEXITCODE -ne 0) {
Write-Error "Tests failed"
exit 4
}
}
finally {
Pop-Location
}
}

function Print-Info {
Write-Host "=============================="
Write-Host " msg-sdk-cpp PowerShell Build"
Write-Host "=============================="
Write-Host "Source Directory: $SourceDir"
Write-Host "Build Directory: $BuildDir"
Write-Host "Install Directory: $InstallDir"
Write-Host ""
}

# ========= MAIN =========
Print-Info
Check-And-Install
Create-BuildDir
Compile-Sources
Run-Tests

Write-Host "Build and test complete!"
Loading