Skip to content

Commit b1a75d1

Browse files
chore: fleshed out **FAQ.md** and **INSTALL.md**
1 parent 632d15b commit b1a75d1

2 files changed

Lines changed: 199 additions & 8 deletions

File tree

FAQ.md

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,23 @@ it will be used to create one.
1616

1717
## Q1: "How do I build b64?"
1818

19-
T.B.C.
19+
See [INSTALL.md](./INSTALL.md) for the recommended **CMake** flow
20+
(**prepare_cmake.sh**, then **build_cmake.sh**).
21+
22+
For a minimal **C API**-only build with no external dependencies:
23+
24+
```bash
25+
$ ./prepare_cmake.sh --no-cpp --disable-testing -m
26+
```
27+
28+
For a full build (including the **C++ API** and tests), install **STLSoft**
29+
1.11 and **xTests** first, then:
30+
31+
```bash
32+
$ ./prepare_cmake.sh -m
33+
```
34+
35+
Execute `$ ./prepare_cmake.sh --help` for the full set of options.
2036

2137

2238
## Q2: "How do I install b64?"
@@ -26,8 +42,35 @@ See [INSTALL.md](./INSTALL.md) for details of how to install **b64**.
2642

2743
## Q3: "How do I use b64?"
2844

29-
T.B.C.
45+
Include **b64/b64.h** and link against **libb64** (the **CMake** target is
46+
`b64::core`). Encode and decode with `b64_encode()` / `b64_decode()` (or the
47+
`2`-suffixed variants for flags and status codes).
3048

49+
A minimal sketch:
3150

32-
<!-- ########################### end of file ########################### -->
51+
```c
52+
#include <b64/b64.h>
3353

54+
#include <stdlib.h>
55+
56+
void example(void)
57+
{
58+
unsigned char const bytes[] = { 1, 2, 3, 4 };
59+
size_t const cch = b64_encode(bytes, sizeof(bytes), NULL, 0);
60+
char* const enc = (char*)malloc(cch);
61+
62+
if (NULL != enc)
63+
{
64+
b64_encode(bytes, sizeof(bytes), enc, cch);
65+
/* ... use enc[0 .. cch) ... */
66+
free(enc);
67+
}
68+
}
69+
```
70+
71+
Worked examples live under **examples/c/** and **examples/cpp/**. The **C++
72+
API** (**b64/b64.hpp**) requires **STLSoft**; see [INSTALL.md](./INSTALL.md)
73+
and [README.md](./README.md).
74+
75+
76+
<!-- ########################### end of file ########################### -->

INSTALL.md

Lines changed: 153 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,162 @@
1-
# b64 - Install <!-- omit in toc -->
1+
# b64 - Installation and Use <!-- omit in toc -->
2+
3+
**b64** is a classic-form C/C++ library, insofar as it has implementation
4+
files in its **src** directory and header files in its **include/b64**
5+
directory. Thus, once "installed", one must simply include **b64/b64.h**
6+
(C API) or **b64/b64.hpp** (C++ API), and compile-in or link-in the
7+
implementation.
8+
9+
The **C API** has no non-standard dependencies. The **C++ API** depends on
10+
**STLSoft**. Building the project's tests additionally requires **xTests**
11+
(and optionally recognises **shwild**).
12+
213

314
## Table of Contents <!-- omit in toc -->
415

5-
- [Installing](#installing)
16+
- [CMake](#cmake)
17+
- [Bundled](#bundled)
618

719

8-
## Installing
20+
## CMake
921

10-
T.B.C.
22+
The primary choice for installation is by use of **CMake**.
1123

24+
1. Obtain the latest distribution of **b64**, from
25+
https://github.com/synesissoftware/b64/, e.g.
1226

13-
<!-- ########################### end of file ########################### -->
27+
```bash
28+
$ mkdir -p ~/open-source
29+
$ cd ~/open-source
30+
$ git clone https://github.com/synesissoftware/b64/
31+
```
32+
33+
2. Prepare the CMake configuration, via the **prepare_cmake.sh** script.
34+
35+
For a minimal **C API**-only install (no **STLSoft** / **xTests**
36+
required):
37+
38+
```bash
39+
$ cd ~/open-source/b64
40+
$ ./prepare_cmake.sh --no-cpp --disable-testing -v
41+
```
42+
43+
For a full build including the **C++ API**, examples, and tests, install
44+
**STLSoft** 1.11 (and **xTests** for tests) via their own **CMake**
45+
scripts first, then:
46+
47+
```bash
48+
$ cd ~/open-source/b64
49+
$ ./prepare_cmake.sh -v
50+
```
51+
52+
If **STLSoft** is available as a source tree rather than an installed
53+
**CMake** package, pass its root with `--stlsoft-root-dir` / `-s`.
54+
55+
(**Hint**: execute `$ ./prepare_cmake.sh --help` for more information.)
56+
57+
3. Run a build of the generated **CMake**-derived build files via the
58+
**build_cmake.sh** script, as in:
59+
60+
```bash
61+
$ ./build_cmake.sh
62+
```
63+
64+
(**NOTE**: if you provide the flag `--run-make` (=== `-m`) in step 2 then
65+
you do not need this step.)
66+
67+
4. As a check (when testing was not disabled), execute the built unit-test
68+
programs via **run_all_unit_tests.sh**, as in:
69+
70+
```bash
71+
$ ./run_all_unit_tests.sh
72+
```
73+
74+
5. Install the library on the host, via `cmake`, as in:
75+
76+
```bash
77+
$ sudo cmake --install ${SIS_CMAKE_BUILD_DIR:-./_build} --config Release
78+
```
79+
80+
6. Then to use the library, it is a simple matter as follows:
81+
82+
1. Assuming a simplest possible program to verify the installation:
83+
84+
```c
85+
/* main.c */
86+
#include <b64/b64.h>
87+
88+
#include <stdio.h>
89+
#include <stdlib.h>
90+
#include <string.h>
91+
92+
int main(void)
93+
{
94+
unsigned char const bytes[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
95+
size_t const cch = b64_encode(bytes, sizeof(bytes), NULL, 0);
96+
char* const enc = (char*)malloc(cch);
1497

98+
if (NULL == enc)
99+
{
100+
return EXIT_FAILURE;
101+
}
102+
103+
b64_encode(bytes, sizeof(bytes), enc, cch);
104+
105+
printf("encoded: %.*s\n", (int)cch, enc);
106+
107+
free(enc);
108+
109+
return EXIT_SUCCESS;
110+
}
111+
```
112+
113+
2. Compile your project against **b64**:
114+
115+
Due to the installation step (step 5 above) there is no requirement
116+
for an explicit include directory for **b64**:
117+
118+
```bash
119+
$ cc -c main.c
120+
```
121+
122+
3. Link your project against **b64**:
123+
124+
Due to the installation step (step 5 above) there is no requirement
125+
for an explicit library directory for **b64**:
126+
127+
```bash
128+
$ cc main.o -lb64
129+
```
130+
131+
4. Test your project:
132+
133+
```bash
134+
$ ./a.out
135+
encoded: AQIDBAUGBwgJCg==
136+
$
137+
```
138+
139+
Consumers that use **CMake** may instead depend on the installed package:
140+
141+
```cmake
142+
find_package(b64 REQUIRED)
143+
target_link_libraries(your_target PRIVATE b64::core)
144+
```
145+
146+
Use of **b64/b64.hpp** additionally requires **STLSoft**
147+
(`find_package(STLSoft REQUIRED)`).
148+
149+
150+
## Bundled
151+
152+
**b64** is small enough that it is commonly bundled into other projects
153+
(for example **Pantheios**). In that case:
154+
155+
* add **b64**'s **include** directory to your project's include path;
156+
* compile **src/b64.c** into your build (or link a previously built
157+
**libb64**); and
158+
* `#include <b64/b64.h>` (or **b64/b64.hpp** if the **C++ API** and
159+
**STLSoft** are available).
160+
161+
162+
<!-- ########################### end of file ########################### -->

0 commit comments

Comments
 (0)