Skip to content

Commit

Permalink
Add Makefile (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkthomps authored Jul 2, 2020
1 parent 8204df7 commit c22b4da
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 45 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.idea/*
cmake-build-debug/*
docs/*

containers.a
containers.so
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
24 changes: 24 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
36 changes: 0 additions & 36 deletions build.sh

This file was deleted.

0 comments on commit c22b4da

Please sign in to comment.