aboutsummaryrefslogtreecommitdiff
path: root/src/new_lib.sh
blob: a07947244ca36bd6c86f5b536691cc3d4a4cb9b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env bash

library="${1}"
library_capitals="$(echo ${library} | tr '[:lower:]' '[:upper:]')"
include_file="include/ak${library}.h"
test_file="tests/test_ak${library}.c"
implementation_file="ak${library}.c"
build_file="build_tree/ak_${library}_build.sh"

include_template(){
    cat > ${include_file} << EOF
#ifndef AK_${library_capitals}_H
#define AK_${library_capitals}_H

int ak_${library}();

#endif // AK_${library_capitals}_H
EOF

}

implementation_template(){
    cat > ${implementation_file} << EOF
#include <ak${library}.h>
#include <stdio.h>

int ak_${library}()
{
    printf("Testing: %s\n", __func__);
    return 0;
}
EOF
}

test_template(){
    cat > ${test_file} << EOF
#include <ak${library}.h>

int main()
{
    ak_${library}();
    return 0;
}
EOF
}

build_template(){
    cat > ${build_file} << EOF
echo "Building lib/ak${library}.so" && \
gcc -c -shared -Wextra -Wall -Werror -pedantic -ggdb -fPIC -I./include ak${library}.c -o lib/ak${library}.so && \
echo "Building tests/test_ak${library}" && \
gcc -Wextra -Wall -Werror -pedantic -ggdb -Wl,-rpath=lib -I./include tests/test_ak${library}.c lib/ak${library}.so -o tests/test_ak${library} && \
echo "Running test_ak${library}" && \
time ./tests/test_ak${library}
rm ./tests/test_ak${library}
EOF
    chmod +x ${build_file}
}

if [ ! -f ${include_file} ]
then
    include_template
else
    echo "ERROR: ${include_file} exists"
fi
if [ ! -f ${test_file} ]
then
    test_template
else
    echo "ERROR: ${test_file} exists"
fi
if [ ! -f ${implementation_file} ]
then
implementation_template
else
    echo "ERROR: ${implementation_file} exists"
fi
if [ ! -f ${build_file} ]
then
build_template
else
    echo "ERROR: ${build_file} exists"
fi