mirror of
https://github.com/bkthomps/Containers.git
synced 2025-12-05 15:15:49 +00:00
Add Makefile (#59)
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,4 +1,5 @@
|
|||||||
.idea/*
|
.idea/*
|
||||||
cmake-build-debug/*
|
cmake-build-debug/*
|
||||||
docs/*
|
docs/*
|
||||||
|
containers.a
|
||||||
|
containers.so
|
||||||
|
|||||||
2
LICENSE
2
LICENSE
@@ -1,6 +1,6 @@
|
|||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2017-2019 Bailey Thompson
|
Copyright (c) 2017-2020 Bailey Thompson
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
24
Makefile
Normal file
24
Makefile
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
.DEFAULT_GOAL := unspecified
|
||||||
|
|
||||||
|
unspecified:
|
||||||
|
@echo "Error: use 'make static_clang' or 'make dynamic_clang' or 'make static_gcc' or 'make dynamic_gcc'"
|
||||||
|
|
||||||
|
static_clang:
|
||||||
|
clang src/*.c -c -O3 -fpic
|
||||||
|
ar rcs containers.a *.o
|
||||||
|
rm *.o
|
||||||
|
|
||||||
|
dynamic_clang:
|
||||||
|
clang -shared -o containers.so -O3 -fPIC src/*.c
|
||||||
|
|
||||||
|
static_gcc:
|
||||||
|
gcc src/*.c -c -O3 -fpic
|
||||||
|
ar rcs containers.a *.o
|
||||||
|
rm *.o
|
||||||
|
|
||||||
|
dynamic_gcc:
|
||||||
|
gcc -shared -o containers.so -O3 -fPIC src/*.c
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f containers.a
|
||||||
|
rm -f containers.so
|
||||||
13
README.md
13
README.md
@@ -11,16 +11,15 @@ This library provides various containers. Each container has utility functions t
|
|||||||
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.
|
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.
|
||||||
|
|
||||||
## Setup
|
## Setup
|
||||||
The `build.sh` script can be used to build either dynamic or static libraries. The script supports clang and gcc.
|
It is possible to compile this library as either static `.a` or dynamic `.so`:
|
||||||
|
1. A static library is slightly faster than a dynamic one, however, if the library is modified, the entire project codebase which uses it will need to be recompiled.
|
||||||
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.
|
2. A dynamic library can be changed without recompiling the codebase, assuming no function definitions have changed.
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
The installation process is as follows:
|
The installation process is as follows:
|
||||||
1. Clone this repository and navigate to it.
|
1. Clone this repository and navigate to it.
|
||||||
2. Run the `build.sh` build script.
|
2. Run `make static_clang`/`make static_gcc` or `make dynamic_clang`/`make dynamic_gcc` for either a static or dynamic library.
|
||||||
3. Follow the instructions that the script prints.
|
3. Then, you can copy-paste `containers.h` and `containers.a`/`containers.so` into your project to include the containers.
|
||||||
|
4. Finally, you remember to link the library by including `containers.a -ldl`/`containers.so -ldl` as an argument.
|
||||||
|
|
||||||
## Container Types
|
## Container Types
|
||||||
The container types that this library contains are described below.
|
The container types that this library contains are described below.
|
||||||
|
|||||||
36
build.sh
36
build.sh
@@ -1,36 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
if [[ $# -ne 2 ]];
|
|
||||||
then
|
|
||||||
echo "Usage: build-library <clang/gcc> <dynamic/static>"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ $1 != "clang" && $1 != "gcc" ]];
|
|
||||||
then
|
|
||||||
echo "Must either be clang or gcc"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ $2 == "dynamic" ]];
|
|
||||||
then
|
|
||||||
cd src
|
|
||||||
"$1" -shared -o containers.so -O3 -fPIC *.c
|
|
||||||
cd ..
|
|
||||||
mv src/containers.so containers.so
|
|
||||||
echo "Now, you can copy-paste containers.h and containers.so to any project that you would like to use the dynamic library with."
|
|
||||||
echo "Afterwards, your project can be compiled with: $1 test.c -o test containers.so -ldl"
|
|
||||||
elif [[ $2 == "static" ]];
|
|
||||||
then
|
|
||||||
cd src
|
|
||||||
"$1" *.c -c -O3 -fpic
|
|
||||||
ar rcs containers.a *.o
|
|
||||||
rm *.o
|
|
||||||
cd ..
|
|
||||||
mv src/containers.a containers.a
|
|
||||||
echo "Now, you can copy-paste containers.h and containers.a to any project that you would like to use the static library with."
|
|
||||||
echo "Afterwards, your project can be compiled with: $1 test.c -o test containers.a -ldl"
|
|
||||||
else
|
|
||||||
echo "Must either be dynamic or static"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
Reference in New Issue
Block a user