Skip to content

Commit ee0bc1e

Browse files
authored
Create scripts (#55)
Create a header compilation script as well as a build script.
1 parent c62a486 commit ee0bc1e

File tree

5 files changed

+726
-75
lines changed

5 files changed

+726
-75
lines changed

README.md

Lines changed: 5 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -11,83 +11,16 @@ This library provides various containers. Each container has utility functions t
1111
Inspired by the C++ standard library; however, implemented using C with different function interfaces as the C++ standard library but with the same container names.
1212

1313
## Setup
14-
There are two types of library files which can be generated: dynamic and static. Both ways will be described below using clang. However, the steps are the same with gcc except `clang` is to be replaced with `gcc`.
14+
The `build.sh` script can be used to build either dynamic or static libraries. The script supports clang and gcc.
1515

1616
The benefit of a dynamic library is that changing the `containers.so` library can be done without needing to recompile the codebase which is using the library. Nevertheless, it is slower than a static library.
1717

1818
The benefit of a static library is that it is faster than a dynamic library. However, if the `containers.a` library is modified, the codebase which is using the library needs to be recompiled.
1919

20-
### Dynamic Library
21-
22-
1. Navigate to your C working directory
23-
24-
2. Run:
25-
```
26-
git clone ssh://git@github.com/bkthomps/Containers.git
27-
cd Containers/src
28-
```
29-
30-
3. To create a dynamic library, run:
31-
```
32-
clang -shared -o containers.so -O3 -fPIC *.c
33-
```
34-
35-
4. Now, you can copy and paste the `include` directory and `containers.so` to any project that you would like to use the dynamic library with.
36-
37-
5. Thus, for an example program, the directory would look like this:
38-
* containers.so
39-
* include/
40-
* array.h
41-
* deque.h
42-
* ...
43-
* test.c
44-
45-
6. The test.c file could then contain, for example:
46-
```
47-
#include "include/vector.h"
48-
```
49-
50-
7. And the project would be compiled with:
51-
```
52-
clang test.c -o test containers.so -ldl
53-
```
54-
55-
### Static Library
56-
57-
1. Navigate to your C working directory
58-
59-
2. Run:
60-
```
61-
git clone ssh://git@github.com/bkthomps/Containers.git
62-
cd Containers/src
63-
```
64-
65-
3. To create a static library, run:
66-
```
67-
clang *.c -c -O3 -fpic
68-
ar rcs containers.a *.o
69-
rm *.o
70-
```
71-
72-
4. Now, you can copy and paste the `include` directory and `containers.a` to any project that you would like to use the static library with.
73-
74-
5. Thus, for an example program, the directory would look like this:
75-
* containers.a
76-
* include/
77-
* array.h
78-
* deque.h
79-
* ...
80-
* test.c
81-
82-
6. The test.c file could then contain, for example:
83-
```
84-
#include "include/vector.h"
85-
```
86-
87-
7. And the project would be compiled with:
88-
```
89-
clang test.c -o test containers.a -ldl
90-
```
20+
The installation process is as follows:
21+
1. Clone this repository and navigate to it.
22+
2. Run the `build.sh` build script.
23+
3. Follow the instructions that the script prints.
9124

9225
## Container Types
9326
The container types that this library contains are described below.

build.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
if [[ $# -ne 2 ]];
4+
then
5+
echo "Usage: build-library <clang/gcc> <dynamic/static>"
6+
exit 1
7+
fi
8+
9+
if [[ $1 != "clang" && $1 != "gcc" ]];
10+
then
11+
echo "Must either be clang or gcc"
12+
exit 1
13+
fi
14+
15+
if [[ $2 == "dynamic" ]];
16+
then
17+
cd src
18+
"$1" -shared -o containers.so -O3 -fPIC *.c
19+
cd ..
20+
mv src/containers.so containers.so
21+
echo "Now, you can copy-paste containers.h and containers.so to any project that you would like to use the dynamic library with."
22+
echo "Afterwards, your project can be compiled with: $1 test.c -o test containers.so -ldl"
23+
elif [[ $2 == "static" ]];
24+
then
25+
cd src
26+
"$1" *.c -c -O3 -fpic
27+
ar rcs containers.a *.o
28+
rm *.o
29+
cd ..
30+
mv src/containers.a containers.a
31+
echo "Now, you can copy-paste containers.h and containers.a to any project that you would like to use the static library with."
32+
echo "Afterwards, your project can be compiled with: $1 test.c -o test containers.a -ldl"
33+
else
34+
echo "Must either be dynamic or static"
35+
exit 1
36+
fi

compile-headers.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
3+
header_name="./containers.h"
4+
IFS=''
5+
first="1"
6+
7+
find ./src -type f -name "*.h" | while read header;
8+
do
9+
ignore="1"
10+
if [[ $first == "1" ]];
11+
then
12+
first="0"
13+
cp "./src/include/VERSION" "$header_name"
14+
fi
15+
while read line;
16+
do
17+
if [[ $ignore == "0" ]];
18+
then
19+
echo "$line" >> "$header_name"
20+
elif [[ $line == *"*/"* ]];
21+
then
22+
ignore="0"
23+
echo "" >> "$header_name"
24+
fi
25+
done < "$header"
26+
done

0 commit comments

Comments
 (0)