Skip to content

Commit 9b39796

Browse files
author
Sandro Kalatozishvili
committed
Updated project tree
1 parent c23e91b commit 9b39796

37 files changed

+344
-266
lines changed

.github/workflows/script.yml

+16-6
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,29 @@ jobs:
3131
run: cd smake && ./build.sh --install
3232

3333
- name: Build with SMAKE (SSL)
34-
run: ./build.sh smake
34+
run: |
35+
./build.sh --tool=smake --tools --examples
36+
./build/xutils
3537
3638
- name: Build with SMAKE (no SSL)
37-
run: ./build.sh smake --ssl=no
39+
run: ./build.sh --tool=smake --tools --examples --ssl=no
3840

3941
- name: Build with CMAKE (SSL)
40-
run: ./build.sh cmake
42+
run: |
43+
./build.sh --tool=cmake --tools --examples
44+
./build/xutils
4145
4246
- name: Build with CMAKE (no SSL)
43-
run: ./build.sh cmake --ssl=no
47+
run: |
48+
./build.sh --tool=cmake --tools --examples --ssl=no
49+
./build/xutils
4450
4551
- name: Build with Makefile (SSL)
46-
run: ./build.sh make
52+
run: |
53+
./build.sh --tool=make --tools --examples
54+
./build/xutils
4755
4856
- name: Build with Makefile (no SSL)
49-
run: ./build.sh make --ssl=no
57+
run: |
58+
./build.sh --tool=make --tools --examples --ssl=no
59+
./build/xutils

.vscode/settings.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"tuple": "c",
4949
"type_traits": "c",
5050
"utility": "c",
51-
"xcli.h": "c"
51+
"xcli.h": "c",
52+
"xlog.h": "c"
5253
}
5354
}

CMakeLists.txt

+46-37
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ ELSE()
77
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O2 -Wall")
88
ENDIF()
99

10+
set(XUTILS_INSTALL_PREFIX "/usr/local")
11+
string(SUBSTRING "${XUTILS_INSTALL_PREFIX}" 0 2 PREFIX_START)
12+
13+
if("${PREFIX_START}" STREQUAL "./")
14+
get_filename_component(CURRENT_WORKING_DIR "${CMAKE_SOURCE_DIR}" REALPATH)
15+
string(SUBSTRING "${XUTILS_INSTALL_PREFIX}" 1 -1 RELATIVE_PATH)
16+
set(CMAKE_INSTALL_PREFIX "${CURRENT_WORKING_DIR}${RELATIVE_PATH}")
17+
endif()
18+
1019
set(THREADS_PREFER_PTHREAD_FLAG ON)
1120
find_package(Threads REQUIRED)
1221

@@ -31,43 +40,43 @@ include_directories(
3140
)
3241

3342
add_library(xutils STATIC
34-
${SOURCE_DIR}/xver.c
35-
${DATA_DIR}/array.c
36-
${DATA_DIR}/xjson.c
37-
${DATA_DIR}/xbuf.c
38-
${DATA_DIR}/hash.c
39-
${DATA_DIR}/list.c
40-
${DATA_DIR}/xstr.c
41-
${DATA_DIR}/map.c
42-
${DATA_DIR}/jwt.c
43-
${CRYPT_DIR}/crypt.c
44-
${CRYPT_DIR}/aes.c
45-
${CRYPT_DIR}/base64.c
46-
${CRYPT_DIR}/sha256.c
47-
${CRYPT_DIR}/sha1.c
48-
${CRYPT_DIR}/crc32.c
49-
${CRYPT_DIR}/hmac.c
50-
${CRYPT_DIR}/md5.c
51-
${CRYPT_DIR}/rsa.c
52-
${NET_DIR}/event.c
53-
${NET_DIR}/addr.c
54-
${NET_DIR}/http.c
55-
${NET_DIR}/mdtp.c
56-
${NET_DIR}/sock.c
57-
${NET_DIR}/api.c
58-
${NET_DIR}/ntp.c
59-
${NET_DIR}/rtp.c
60-
${NET_DIR}/ws.c
61-
${SYS_DIR}/thread.c
62-
${SYS_DIR}/xtype.c
63-
${SYS_DIR}/xtime.c
64-
${SYS_DIR}/sync.c
65-
${SYS_DIR}/xsig.c
66-
${SYS_DIR}/xcli.c
67-
${SYS_DIR}/xcpu.c
68-
${SYS_DIR}/xlog.c
69-
${SYS_DIR}/xtop.c
70-
${SYS_DIR}/xfs.c
43+
./src/xver.c
44+
./src/crypt/aes.c
45+
./src/crypt/base64.c
46+
./src/crypt/crc32.c
47+
./src/crypt/crypt.c
48+
./src/crypt/hmac.c
49+
./src/crypt/md5.c
50+
./src/crypt/rsa.c
51+
./src/crypt/sha256.c
52+
./src/crypt/sha1.c
53+
./src/data/array.c
54+
./src/data/hash.c
55+
./src/data/jwt.c
56+
./src/data/list.c
57+
./src/data/map.c
58+
./src/data/xbuf.c
59+
./src/data/xjson.c
60+
./src/data/xstr.c
61+
./src/net/addr.c
62+
./src/net/event.c
63+
./src/net/http.c
64+
./src/net/mdtp.c
65+
./src/net/ntp.c
66+
./src/net/rtp.c
67+
./src/net/sock.c
68+
./src/net/api.c
69+
./src/net/ws.c
70+
./src/sys/sync.c
71+
./src/sys/thread.c
72+
./src/sys/xcli.c
73+
./src/sys/xcpu.c
74+
./src/sys/xfs.c
75+
./src/sys/xlog.c
76+
./src/sys/xsig.c
77+
./src/sys/xtime.c
78+
./src/sys/xtop.c
79+
./src/sys/xtype.c
7180
)
7281

7382
install(TARGETS xutils DESTINATION lib)

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ use `-lxutils` linker flag while compiling your project. See the example directo
159159

160160
### Tools & Examples
161161

162-
The project includes several examples and tools in the `examples` directory.\
163-
The examples can be built by using the `CMake` tool or `Makefile` from that directory.
162+
The project includes samples and apps in the `examples` and `tools` directory.\
163+
These sources can be built by using the `CMake` tool or `Makefile` from that directory.
164164

165165
```bash
166166
cd examples
@@ -173,12 +173,12 @@ make
173173
#### XTOP and more
174174

175175
<p align="center">
176-
<img src="https://raw.githubusercontent.com/kala13x/libxutils/main/examples/xtop.png" alt="alternate text">
176+
<img src="https://raw.githubusercontent.com/kala13x/libxutils/main/misc/xtop.png" alt="alternate text">
177177
</p>
178178

179179
`XTOP` is `HTOP` like performance monitor that supports to monitor CPU, memory, and network traffic into a single window. In addition, it has powerful `REST API` client/server mode and much more.
180180

181-
After building the sources in example directory, run `sudo make install` command to install following tools in the system:
181+
After building the sources in `tools` directory, run `sudo make install` command to install following apps in the system:
182182

183183
- `xcrypt` - File and text encrypt/decrypt tool for CLI
184184
- `xpass` - Secure password manager tool for CLI

build.sh

+22-3
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
# 2015-2023 Sun Dro (s.kalatoz@gmail.com)
44

55
PROJ_PATH=$(dirname $(readlink -f "$0"))
6-
TOOL_PATH=$PROJ_PATH/examples
6+
TOOL_PATH=$PROJ_PATH/tools
77
LIB_PATH=$PROJ_PATH
88

99
INSTALL_PREFIX="/usr/local"
1010
MAKE_TOOL="make"
1111
USE_SSL="yes"
1212

13+
EXAMPLES_DONE=0
1314
TOOLS_DONE=0
1415
CPU_COUNT=1
1516

@@ -72,6 +73,7 @@ clean_dir() {
7273

7374
clean_project() {
7475
clean_dir $PROJ_PATH/examples
76+
clean_dir $PROJ_PATH/tools
7577
clean_dir $PROJ_PATH
7678
}
7779

@@ -83,18 +85,31 @@ update_cpu_count() {
8385

8486
build_tools() {
8587
[ "$TOOLS_DONE" -eq 1 ] && return
86-
cd $PROJ_PATH/examples
88+
cd $PROJ_PATH/tools
8789

8890
if [[ $MAKE_TOOL == "cmake" ]]; then
8991
mkdir -p build && cd build && cmake ..
90-
TOOL_PATH=$PROJ_PATH/examples/build
92+
TOOL_PATH=$PROJ_PATH/tools/build
9193
fi
9294

9395
make -j $CPU_COUNT
9496
cd $PROJ_PATH
9597
TOOLS_DONE=1
9698
}
9799

100+
build_examples() {
101+
[ "$EXAMPLES_DONE" -eq 1 ] && return
102+
cd $PROJ_PATH/examples
103+
104+
if [[ $MAKE_TOOL == "cmake" ]]; then
105+
mkdir -p build && cd build && cmake ..
106+
fi
107+
108+
make -j $CPU_COUNT
109+
cd $PROJ_PATH
110+
EXAMPLES_DONE=1
111+
}
112+
98113
build_library() {
99114
cd $PROJ_PATH/misc
100115
./generate.sh $MAKE_TOOL --prefix=$INSTALL_PREFIX --ssl=$USE_SSL
@@ -157,6 +172,10 @@ build_library
157172

158173
for arg in "$@"; do
159174
if [[ $arg == "--examples" ]]; then
175+
build_examples
176+
fi
177+
178+
if [[ $arg == "--tools" ]]; then
160179
build_tools
161180
fi
162181

clean.sh

+1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ clean_path() {
1414
}
1515

1616
clean_path $PROJ_PATH
17+
clean_path $PROJ_PATH/tools
1718
clean_path $PROJ_PATH/examples

examples/CMakeLists.txt

+12-14
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O2 -Wall")
66
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
77
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
88

9+
set(XUTILS_INCLUDE_DIRS
10+
../src/crypt
11+
../src/data
12+
../src/net
13+
../src/sys
14+
../src
15+
)
16+
17+
include_directories(${XUTILS_INCLUDE_DIRS})
918
find_package(Threads REQUIRED)
1019
list(APPEND EXTRA_LIBS xutils)
1120

@@ -23,20 +32,13 @@ set(SOURCE_FILES
2332
tcp-server.c
2433
ws-server.c
2534
ws-client.c
26-
events.c
27-
files.c
28-
thread.c
2935
statcov.c
3036
strings.c
37+
thread.c
38+
events.c
39+
files.c
3140
json.c
32-
xtop.c
3341
xlog.c
34-
xcrypt.c
35-
xutils.c
36-
xpass.c
37-
xhttp.c
38-
xjson.c
39-
xsrc.c
4042
list.c
4143
ntp.c
4244
jwt.c
@@ -48,7 +50,3 @@ foreach(sourcefile ${SOURCE_FILES})
4850
target_link_libraries(${execname} Threads::Threads ${EXTRA_LIBS})
4951
endforeach()
5052

51-
# install targets
52-
install(TARGETS xcrypt xutils xpass xjson xhttp xtop xsrc
53-
RUNTIME DESTINATION /usr/local/bin)
54-

examples/Makefile

+16-22
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,34 @@
1+
####################################
2+
# Automatically generated by SMake #
3+
# https://github.com/kala13x/smake #
4+
####################################
15

26
CFLAGS = -g -O2 -Wall
3-
LIBS = -lxutils -lpthread
7+
LIBS = -lpthread
8+
LD_LIBS = ../build/libxutils.a
49

510
ifeq ($(XUTILS_USE_SSL),y)
611
CFLAGS += -D_XUTILS_USE_SSL
712
LIBS += -lssl -lcrypto
813
endif
914

15+
CFLAGS += -I../src \
16+
-I../src/crypt \
17+
-I../src/data \
18+
-I../src/net \
19+
-I../src/sys
20+
1021
EXECS = array \
1122
http-server \
1223
tcp-server \
1324
ws-server \
1425
ws-client \
15-
events \
16-
files \
17-
thread \
1826
statcov \
1927
strings \
28+
events \
29+
thread \
30+
files \
2031
json \
21-
xutils \
22-
xcrypt \
23-
xhttp \
24-
xjson \
25-
xpass \
26-
xsrc \
27-
xtop \
2832
xlog \
2933
list \
3034
ntp \
@@ -34,17 +38,7 @@ EXECS = array \
3438
all: $(EXECS)
3539

3640
$(EXECS): %: %.c
37-
$(CC) $(CFLAGS) -o $@ $< $(LIBS)
38-
39-
.PHONY: install
40-
install:
41-
install -m 0755 xcrypt /usr/local/bin/
42-
install -m 0755 xutils /usr/local/bin/
43-
install -m 0755 xpass /usr/local/bin/
44-
install -m 0755 xjson /usr/local/bin/
45-
install -m 0755 xhttp /usr/local/bin/
46-
install -m 0755 xtop /usr/local/bin/
47-
install -m 0755 xsrc /usr/local/bin/
41+
$(CC) $(CFLAGS) -o $@ $< $(LD_LIBS) $(LIBS)
4842

4943
.PHONY: clean
5044
clean:

examples/array.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
* Test example source of working with arrays
77
*/
88

9-
#include <xutils/xstd.h>
10-
#include <xutils/array.h>
9+
#include "xstd.h"
10+
#include "array.h"
1111

1212
typedef struct {
1313
int key;

examples/check.sh

-25
This file was deleted.

0 commit comments

Comments
 (0)