Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kala13x committed Jun 22, 2022
0 parents commit c095d7d
Show file tree
Hide file tree
Showing 91 changed files with 24,217 additions and 0 deletions.
52 changes: 52 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Prerequisites
*.d

# Object files
*.o
*.ko
*.obj
*.elf

# Linker output
*.ilk
*.map
*.exp

# Precompiled Headers
*.gch
*.pch

# Libraries
*.lib
*.a
*.la
*.lo

# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib

# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex

# Debug files
*.dSYM/
*.su
*.idb
*.pdb

# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf
20 changes: 20 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
os:
- linux
- osx
language: c
compiler:
- clang
- gcc
sudo: required
dist: trusty
script:
- mkdir build
- cd build
- cmake ..
- make
addons:
coverity_scan:
project:
name: "kala13x/libxutils"
notification_email: [email protected]
branch_pattern: coverity_scan
71 changes: 71 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
cmake_minimum_required(VERSION 3.2.0 FATAL_ERROR)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake)
project(libxutils LANGUAGES C)

IF (WIN32)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Od /W3")
ELSE()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O2 -Wall")
ENDIF()

set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)

find_package(OpenSSL)
IF(OpenSSL_FOUND)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_XUTILS_USE_SSL")
ENDIF()

IF (APPLE)
find_package(RT REQUIRED)
ENDIF()

SET(HEADER_DST "include/xutils")
SET(SOURCE_DIR "./src")
SET(MEDIA_DIR "./media")
include_directories(${SOURCE_DIR} ${MEDIA_DIR})

add_library(xutils STATIC
${SOURCE_DIR}/addr.c
${SOURCE_DIR}/array.c
${SOURCE_DIR}/crypt.c
${SOURCE_DIR}/xtime.c
${SOURCE_DIR}/event.c
${SOURCE_DIR}/list.c
${SOURCE_DIR}/hash.c
${SOURCE_DIR}/xlog.c
${SOURCE_DIR}/xmap.c
${SOURCE_DIR}/xstr.c
${SOURCE_DIR}/xtype.c
${SOURCE_DIR}/xver.c
${SOURCE_DIR}/xbuf.c
${SOURCE_DIR}/xtop.c
${SOURCE_DIR}/xcli.c
${SOURCE_DIR}/errex.c
${SOURCE_DIR}/http.c
${SOURCE_DIR}/sock.c
${SOURCE_DIR}/sync.c
${SOURCE_DIR}/xcpu.c
${SOURCE_DIR}/thread.c
${SOURCE_DIR}/xjson.c
${SOURCE_DIR}/xfs.c
${MEDIA_DIR}/mdtp.c
${MEDIA_DIR}/ntp.c
${MEDIA_DIR}/rtp.c
${MEDIA_DIR}/ts.c
)

install(TARGETS xutils DESTINATION lib)

install(DIRECTORY "${SOURCE_DIR}/"
DESTINATION "${HEADER_DST}"
FILES_MATCHING
PATTERN "*.h"
)

install(DIRECTORY "${MEDIA_DIR}/"
DESTINATION "${HEADER_DST}"
FILES_MATCHING
PATTERN "*.h"
)
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

The MIT License (MIT)

Copyright (c) 2015-2021 Sun Dro <[email protected]>

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.
64 changes: 64 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
####################################
# Automatically generated by SMake #
# https://github.com/kala13x/smake #
####################################

CFLAGS = -g -O2 -Wall -D_XUTILS_USE_SSL -I./src -I./media
LIBS = -lpthread -lssl -lcrypto
NAME = libxutils.a
ODIR = ./obj
OBJ = o

OBJS = errex.$(OBJ) \
event.$(OBJ) \
hash.$(OBJ) \
http.$(OBJ) \
list.$(OBJ) \
sync.$(OBJ) \
thread.$(OBJ) \
xcpu.$(OBJ) \
xlog.$(OBJ) \
xmap.$(OBJ) \
xtime.$(OBJ) \
xtype.$(OBJ) \
xver.$(OBJ) \
sock.$(OBJ) \
xtop.$(OBJ) \
xcli.$(OBJ) \
addr.$(OBJ) \
xfs.$(OBJ) \
xjson.$(OBJ) \
xaes.$(OBJ) \
array.$(OBJ) \
crypt.$(OBJ) \
xbuf.$(OBJ) \
xstr.$(OBJ) \
mdtp.$(OBJ) \
ntp.$(OBJ) \
rtp.$(OBJ) \
ts.$(OBJ) \
xapi.$(OBJ)

OBJECTS = $(patsubst %,$(ODIR)/%,$(OBJS))
INSTALL_INC = /usr/local/include/xutils
INSTALL_BIN = /usr/local/lib
VPATH = ./src:./media

.c.$(OBJ):
@test -d $(ODIR) || mkdir -p $(ODIR)
$(CC) $(CFLAGS) -c -o $(ODIR)/$@ $< $(LIBS)

$(NAME):$(OBJS)
$(AR) rcs -o $(ODIR)/$(NAME) $(OBJECTS)

.PHONY: install
install:
@test -d $(INSTALL_BIN) || mkdir -p $(INSTALL_BIN)
@install -m 0755 $(ODIR)/$(NAME) $(INSTALL_BIN)/
@test -d $(INSTALL_INC) || mkdir -p $(INSTALL_INC)
@cp -r ./src/*.h $(INSTALL_INC)/
@cp -r ./media/*.h $(INSTALL_INC)/

.PHONY: clean
clean:
$(RM) $(ODIR)/$(NAME) $(OBJECTS)
13 changes: 13 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
xUtils C Library release 2.x (c) Sun Dro <[email protected]>

This directory contains the sources of the xUtils C Library. See
the file "src/xver.h" to check out what release version you have.

The xUtils C Library is the general purpose, cross-platform library for all
Linux / Unix and Windows operating systems. It provides the implementations
of various functionality to make some routines easier for all the programs
written in C and C-compatible languages such as C++, Rust, and Objective C.

The xUtils C Library is free software. you can redistribute it and / or
modify it under the terms of The MIT License (See LICENSE file for more
information).
41 changes: 41 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

LIB_CRYPTO=/usr/lib64/libcrypto.so
LIB_SSL=/usr/lib64/libssl.so

if [ -f "LIB_CRYPTO" ] && [ -f "LIB_SSL" ]; then
export XUTILS_USE_SSL=y
fi

./clean.sh

CPU_COUNT=`cat /proc/cpuinfo | grep processor -c`
MAKE_TOOL=0

if [ ! -z "$1" ]; then
MAKE_TOOL=$1
fi

if [ $MAKE_TOOL == 0 ]; then
echo "Specify build tool (cmake / smake)"
echo "example: $0 smake"
exit 1
fi

# Generate Makefile and build library
$MAKE_TOOL . && make -j $CPU_COUNT

if [ ! -z "$2" ]; then
if [ $2 == "--examples" ]; then
cd examples
make -j $CPU_COUNT
cd ..
elif [ $2 == "--install" ]; then
sudo make install
cd examples
make -j $CPU_COUNT
sudo make install
fi
fi

exit 0
31 changes: 31 additions & 0 deletions clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

cd examples
make clean
cd ..

make clean

if [ -d ./obj ]; then
rm -rf ./obj
fi

if [ -d ./build ]; then
rm -rf ./build
fi

if [ -d ./CMakeFiles ]; then
rm -rf ./CMakeFiles
fi

if [ -f ./CMakeCache.txt ]; then
rm -f ./CMakeCache.txt
fi

if [ -f ./cmake_install.cmake ]; then
rm -f ./cmake_install.cmake
fi

if [ -f ./install_manifest.txt ]; then
rm -f ./install_manifest.txt
fi
39 changes: 39 additions & 0 deletions cmake/FindRT.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# FindRT.cmake - Try to find the RT library
# Once done this will define
#
# RT_FOUND - System has rt
# RT_INCLUDE_DIR - The rt include directory
# RT_LIBRARIES - The libraries needed to use rt
# RT_DEFINITIONS - Compiler switches required for using rt
#
# Also creates an import target called RT::RT

find_path (RT_INCLUDE_DIR NAMES time.h
PATHS
/usr
/usr/local
/opt
PATH_SUFFIXES
)

find_library(RT_LIBRARIES NAMES rt
PATHS
/usr
/usr/local
/opt
)

include(FindPackageHandleStandardArgs)

FIND_PACKAGE_HANDLE_STANDARD_ARGS(rt DEFAULT_MSG RT_LIBRARIES RT_INCLUDE_DIR)

mark_as_advanced(RT_INCLUDE_DIR RT_LIBRARIES)

if (NOT TARGET RT::RT)
add_library(RT::RT INTERFACE IMPORTED)

set_target_properties(RT::RT PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${RT_INCLUDE_DIR}
INTERFACE_LINK_LIBRARIES ${RT_LIBRARIES}
)
endif()
Loading

0 comments on commit c095d7d

Please sign in to comment.