Add Makefile (#59)

This commit is contained in:
Bailey Thompson
2020-07-02 16:42:00 -04:00
committed by GitHub
parent 8204df72e6
commit c22b4da660
5 changed files with 33 additions and 45 deletions

3
.gitignore vendored
View File

@@ -1,4 +1,5 @@
.idea/*
cmake-build-debug/*
docs/*
containers.a
containers.so

View File

@@ -1,6 +1,6 @@
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
of this software and associated documentation files (the "Software"), to deal

24
Makefile Normal file
View 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

View File

@@ -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.
## Setup
The `build.sh` script can be used to build either dynamic or static libraries. The script supports clang and gcc.
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.
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.
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.
2. A dynamic library can be changed without recompiling the codebase, assuming no function definitions have changed.
The installation process is as follows:
1. Clone this repository and navigate to it.
2. Run the `build.sh` build script.
3. Follow the instructions that the script prints.
2. Run `make static_clang`/`make static_gcc` or `make dynamic_clang`/`make dynamic_gcc` for either a static or dynamic library.
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
The container types that this library contains are described below.

View File

@@ -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