Skip to content

Commit 3f3df90

Browse files
author
Sun Dro
committed
Updated build script and changed email in headers
1 parent 2f14671 commit 3f3df90

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+280
-180
lines changed

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
The MIT License (MIT)
33

4-
Copyright (c) 2015-2021 Sun Dro <f4tb0y@protonmail.com>
4+
Copyright (c) 2015-2021 Sun Dro <s.kalatoz@gmail.com>
55

66
Permission is hereby granted, free of charge, to any person obtaining a copy
77
of this software and associated documentation files (the "Software"), to deal

README.md

+16-3
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,19 @@ smake && make
7878
sudo make install
7979
```
8080

81+
#### Using build script
82+
A relatively simple way to build and install a project is to use a build script.
83+
84+
```bash
85+
git clone https://github.com/kala13x/libxutils.git
86+
cd libxutils
87+
./build.sh cmake --install --cleanup
88+
```
89+
90+
You can either choose `cmake` or `smake` as the first argument, but `cmake` is recommended on platforms other than the Linux.
91+
8192
#### Using Makefile
82-
If you do not have any of the above tools installed on your operating system,\
83-
then you can try the build by using already generated `Makefile` for linux.
93+
If you do not have any of the above tools installed on your operating system, then you can try the build by using already generated `Makefile` for linux.
8494

8595
```bash
8696
git clone https://github.com/kala13x/libxutils.git
@@ -147,10 +157,13 @@ use `-lxutils` linker flag while compiling your project. See the example directo
147157
### Tools & Examples
148158

149159
The project includes several examples and tools in the `examples` directory.\
150-
Currently, the examples can be built only by using `Makefile` from that directory.
160+
The examples can be built by using the `CMake` tool or `Makefile` from that directory.
151161

152162
```bash
153163
cd examples
164+
mkdir build
165+
cd build
166+
cmake ..
154167
make
155168
```
156169

build.sh

+103-53
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,115 @@
11
#!/bin/bash
2-
./clean.sh
2+
# This source is part of "libxutils" project
3+
# 2015-2023 Sun Dro (s.kalatoz@gmail.com)
34

5+
PROJ_PATH=$(dirname $(readlink -f "$0"))
6+
TOOL_PATH=$PROJ_PATH/examples
7+
LIB_PATH=$PROJ_PATH
8+
9+
TOOLS_DONE=0
410
MAKE_TOOL=0
511
CPU_COUNT=1
612

713
if [ ! -z "$1" ]; then
814
MAKE_TOOL=$1
915
fi
1016

11-
# Check argument
1217
if [ $MAKE_TOOL == 0 ]; then
1318
echo "Specify build tool (cmake / smake)"
1419
echo "example: $0 smake"
1520
exit 1
1621
fi
1722

18-
# Detect CPU count
19-
if [ $OSTYPE == linux-gnu ]; then
20-
CPU_COUNT=$(nproc)
21-
fi
22-
2323
# List of possible OpenSSL library locations
24-
LIB_CRYPTO_PATHS=(
25-
"/lib/libcrypto.so"
26-
"/lib64/libcrypto.so"
27-
"/usr/lib/libcrypto.so"
28-
"/usr/lib64/libcrypto.so"
29-
"/usr/local/lib/libcrypto.so"
30-
"/usr/local/lib64/libcrypto.so"
31-
"/usr/local/ssl/lib/libcrypto.so"
32-
"/usr/local/ssl/lib64/libcrypto.so"
33-
)
34-
35-
LIB_SSL_PATHS=(
36-
"/lib/libssl.so"
37-
"/lib64/libssl.so"
38-
"/usr/lib/libssl.so"
39-
"/usr/lib64/libssl.so"
40-
"/usr/local/lib/libssl.so"
41-
"/usr/local/lib64/libssl.so"
42-
"/usr/local/ssl/lib/libssl.so"
43-
"/usr/local/ssl/lib64/libssl.so"
24+
SSL_LD_PATH=(
25+
"/lib"
26+
"/lib64"
27+
"/usr/lib"
28+
"/usr/lib64"
29+
"/usr/local/lib"
30+
"/usr/local/lib64"
31+
"/usr/local/ssl/lib"
32+
"/usr/local/ssl/lib64"
4433
)
4534

46-
# Default values
47-
LIB_CRYPTO=""
48-
LIB_SSL=""
49-
50-
# Function to find the library file from a list of possible locations
5135
find_lib() {
52-
local paths=("$@")
53-
for path in "${paths[@]}"; do
54-
if [ -f "$path" ]; then
36+
for directory in "${SSL_LD_PATH[@]}"; do
37+
path=$(find "$directory" -name "$@")
38+
39+
if [ -n "$path" ]; then
5540
echo "$path"
5641
return
5742
fi
43+
5844
done
5945
echo ""
6046
}
6147

62-
# Detect the operating system
63-
echo "Checking OpenSSL libraries."
48+
clean_dir() {
49+
cd "$@"
50+
[ -f ./Makefile ] && make clean
51+
[ -d ./obj ] && rm -rf ./obj
52+
[ -d ./build ] && rm -rf ./build
53+
[ -d ./CMakeFiles ] && rm -rf ./CMakeFiles
54+
[ -f ./CMakeCache.txt ] && rm -rf ./CMakeCache.txt
55+
[ -f ./cmake_install.cmake ] && rm -rf ./cmake_install.cmake
56+
[ -f ./install_manifest.txt ] && rm -rf ./install_manifest.txt
57+
cd $PROJ_PATH
58+
}
59+
60+
clean_project() {
61+
clean_dir $PROJ_PATH/examples
62+
clean_dir $PROJ_PATH
63+
}
64+
65+
update_cpu_count() {
66+
if [ $OSTYPE == linux-gnu ]; then
67+
CPU_COUNT=$(nproc)
68+
fi
69+
}
70+
71+
build_tools() {
72+
[ "$TOOLS_DONE" -eq 1 ] && return
73+
cd $PROJ_PATH/examples
74+
75+
if [[ $MAKE_TOOL == "cmake" ]]; then
76+
mkdir -p build && cd build && cmake ..
77+
TOOL_PATH=$PROJ_PATH/examples/build
78+
fi
6479

65-
LIB_CRYPTO=$(find_lib "${LIB_CRYPTO_PATHS[@]}")
66-
LIB_SSL=$(find_lib "${LIB_SSL_PATHS[@]}")
80+
make -j $CPU_COUNT
81+
cd $PROJ_PATH
82+
TOOLS_DONE=1
83+
}
84+
85+
build_library() {
86+
cd $PROJ_PATH
87+
88+
if [[ $MAKE_TOOL == "cmake" ]]; then
89+
mkdir -p build && cd build && cmake ..
90+
LIB_PATH=$PROJ_PATH/build
91+
fi
92+
93+
make -j $CPU_COUNT
94+
cd $PROJ_PATH
95+
}
96+
97+
install_tools() {
98+
build_tools
99+
cd $TOOL_PATH
100+
sudo make install
101+
cd $PROJ_PATH
102+
}
103+
104+
install_library() {
105+
cd $LIB_PATH
106+
sudo make install
107+
cd $PROJ_PATH
108+
}
109+
110+
echo "Checking OpenSSL libraries."
111+
LIB_CRYPTO=$(find_lib "libcrypto.so")
112+
LIB_SSL=$(find_lib "libssl.so")
67113

68114
# If the OpenSSL libraries are found, set the environment variable
69115
if [ -n "$LIB_CRYPTO" ] && [ -n "$LIB_SSL" ]; then
@@ -75,20 +121,24 @@ else
75121
echo 'OpenSSL libraries not found!'
76122
fi
77123

78-
# Generate Makefile and build library
79-
$MAKE_TOOL . && make -j $CPU_COUNT
80-
81-
if [ ! -z "$2" ]; then
82-
if [ $2 == "--examples" ]; then
83-
cd examples
84-
make -j $CPU_COUNT
85-
cd ..
86-
elif [ $2 == "--install" ]; then
87-
sudo make install
88-
cd examples
89-
make -j $CPU_COUNT
90-
sudo make install
124+
# Build the library
125+
update_cpu_count
126+
clean_project
127+
build_library
128+
129+
for arg in "$@"; do
130+
if [[ $arg == "--examples" ]]; then
131+
build_tools
91132
fi
92-
fi
133+
134+
if [[ $arg == "--install" ]]; then
135+
install_library
136+
install_tools
137+
fi
138+
139+
if [[ $arg == "--cleanup" ]]; then
140+
clean_project
141+
fi
142+
done
93143

94144
exit 0

clean.sh

+16-32
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,17 @@
11
#!/bin/bash
2-
3-
cd examples
4-
make clean
5-
cd ..
6-
7-
if [ -f ./Makefile ]; then
8-
make clean
9-
fi
10-
11-
if [ -d ./obj ]; then
12-
rm -rf ./obj
13-
fi
14-
15-
if [ -d ./build ]; then
16-
rm -rf ./build
17-
fi
18-
19-
if [ -d ./CMakeFiles ]; then
20-
rm -rf ./CMakeFiles
21-
fi
22-
23-
if [ -f ./CMakeCache.txt ]; then
24-
rm -f ./CMakeCache.txt
25-
fi
26-
27-
if [ -f ./cmake_install.cmake ]; then
28-
rm -f ./cmake_install.cmake
29-
fi
30-
31-
if [ -f ./install_manifest.txt ]; then
32-
rm -f ./install_manifest.txt
33-
fi
2+
PROJ_PATH=$(dirname $(readlink -f "$0"))
3+
4+
clean_path() {
5+
cd "$@"
6+
[ -f ./Makefile ] && make clean
7+
[ -d ./obj ] && rm -rf ./obj
8+
[ -d ./build ] && rm -rf ./build
9+
[ -d ./CMakeFiles ] && rm -rf ./CMakeFiles
10+
[ -f ./CMakeCache.txt ] && rm -rf ./CMakeCache.txt
11+
[ -f ./cmake_install.cmake ] && rm -rf ./cmake_install.cmake
12+
[ -f ./install_manifest.txt ] && rm -rf ./install_manifest.txt
13+
cd $PROJ_PATH
14+
}
15+
16+
clean_path $PROJ_PATH
17+
clean_path $PROJ_PATH/examples

examples/CMakeLists.txt

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
cmake_minimum_required(VERSION 3.10)
2+
project(xutils)
3+
4+
set(CMAKE_C_STANDARD 11)
5+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O2 -Wall")
6+
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
7+
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
8+
9+
find_package(Threads REQUIRED)
10+
list(APPEND EXTRA_LIBS xutils)
11+
12+
# if OpenSSL is found, add the definitions and libraries
13+
find_package(OpenSSL)
14+
if(OpenSSL_FOUND)
15+
add_definitions(-D_XUTILS_USE_SSL)
16+
list(APPEND EXTRA_LIBS ${OPENSSL_LIBRARIES})
17+
endif()
18+
19+
# replace with your actual source files
20+
set(SOURCE_FILES
21+
array.c
22+
http-server.c
23+
tcp-server.c
24+
ws-server.c
25+
ws-client.c
26+
events.c
27+
files.c
28+
thread.c
29+
statcov.c
30+
strings.c
31+
json.c
32+
xtop.c
33+
xlog.c
34+
xcrypt.c
35+
xpass.c
36+
xhttp.c
37+
xjson.c
38+
xsrc.c
39+
list.c
40+
ntp.c
41+
jwt.c
42+
rsa.c)
43+
44+
foreach(sourcefile ${SOURCE_FILES})
45+
string(REPLACE ".c" "" execname ${sourcefile})
46+
add_executable(${execname} ${sourcefile})
47+
target_link_libraries(${execname} Threads::Threads ${EXTRA_LIBS})
48+
endforeach()
49+
50+
# install targets
51+
install(TARGETS xcrypt xpass xjson xhttp xtop xsrc
52+
RUNTIME DESTINATION /usr/local/bin)
53+

examples/events.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @file libxutils/examples/events.c
33
*
44
* This source is part of "libxutils" project
5-
* 2015-2020 Sun Dro (f4tb0y@protonmail.com)
5+
* 2015-2020 Sun Dro (s.kalatoz@gmail.com)
66
*
77
* @brief Implementation of high performance event based non-blocking HTTP server.
88
* The xUtils library will use poll() or epoll() depending on the operating system.

examples/http-server.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @file libxutils/examples/http-server.c
33
*
44
* This source is part of "libxutils" project
5-
* 2015-2020 Sun Dro (f4tb0y@protonmail.com)
5+
* 2015-2020 Sun Dro (s.kalatoz@gmail.com)
66
*
77
* @brief Implementation of high performance event based non-blocking HTTP/S server.
88
* The library will use poll(), epoll() or WSAPoll() depending on the operating system.

examples/jwt.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @file libxutils/examples/jwt.c
33
*
44
* This source is part of "libxutils" project
5-
* 2015-2023 Sun Dro (f4tb0y@protonmail.com)
5+
* 2015-2023 Sun Dro (s.kalatoz@gmail.com)
66
*
77
* @brief Example file of working with JSON Web Tokens
88
*/

examples/rsa.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @file libxutils/examples/rsa.c
33
*
44
* This source is part of "libxutils" project
5-
* 2015-2023 Sun Dro (f4tb0y@protonmail.com)
5+
* 2015-2023 Sun Dro (s.kalatoz@gmail.com)
66
*
77
* @brief Example file of working with RSA
88
*/

examples/statcov.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*!
22
* @file libxutils/examples/statcov.c
33
*
4-
* 2020-2021 Sun Dro (f4tb0y@protonmail.com)
4+
* 2020-2021 Sun Dro (s.kalatoz@gmail.com)
55
*
66
* @brief Parse and print COVID-19 case
77
* statistics from https://stopcov.ge/

examples/ws-client.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @file libxutils/examples/ws-client.c
33
*
44
* This source is part of "libxutils" project
5-
* 2015-2023 Sun Dro (f4tb0y@protonmail.com)
5+
* 2015-2023 Sun Dro (s.kalatoz@gmail.com)
66
*
77
* @brief Implementation of high performance event based non-blocking WebSocket/TLS client.
88
* The library will use poll(), WSAPoll(), or epoll() depending on the operating system.

0 commit comments

Comments
 (0)