summaryrefslogtreecommitdiff
path: root/doc/note/setup/build-cJSON.txt
blob: 0e8d0dfac400d0f92f583ab52e4981317a6fe09f (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

### Debian native
true \
  && PKGS_TO_ADD="ca-certificates curl gcc libc6-dev" \
  && SUDO=sudo \
  && PKGINIT="$SUDO apt update" \
  && PKGADD="$SUDO apt install -y --no-install-recommends" \
  && PKGCLEAN="$SUDO apt clean" \
  && HOST= \
  && true


### Alpine mingw cross
true \
  && PKGS_TO_ADD="curl mingw-w64-gcc tar" \
  && SUDO="/home/$USER/.local/bin/sudo" \
  && PKGINIT=true \
  && PKGADD="$SUDO apk add" \
  && PKGCLEAN="$SUDO apk clean" \
  && HOST=x86_64-w64-mingw32 \
  && true


# Generic
true \
  && CJSON_VERSION="1.7.15" \
  && CACHE_DIR="/var/tmp" \
  && true


## Make
true \
  && CJSON_URL="https://github.com/DaveGamble/cJSON/archive/refs/tags/v${CJSON_VERSION:?}.tar.gz" \
  && CJSON_SRCTGZ="${CACHE_DIR:?}/cJSON-${CJSON_VERSION:?}.tgz" \
  && CJSON_BINTGZ="${CJSON_SRCTGZ%.*}-bin.tgz" \
  && ${PKGINIT:?} && ${PKGADD:?} ${PKGS_TO_ADD} \
  && if test -n "$HOST"; then HOST_="${HOST:?}-" ;fi \
  && if test ! -e "${CJSON_SRCTGZ:?}"; then (true \
     && echo "Download \"${CJSON_URL:?}\"" \
     && curl -sSLo "${CJSON_SRCTGZ:?}" "${CJSON_URL:?}" \
     );fi \
  && if test ! -e "${CJSON_BINTGZ:?}"; then (true \
     && printf '\n  Build cJSON\n\n' \
     && tar xzf "${CJSON_SRCTGZ:?}" \
     && cd "cJSON-${CJSON_VERSION:?}" \
     && mkdir build build/obj build/lib build/include \
     && CFLAGS="-Wall -pedantic -fPIC" \
     && ${HOST_}cc $CFLAGS -c -o build/obj/cJSON.o cJSON.c \
     && ${HOST_}cc $CFLAGS -shared -o build/lib/libcJSON.so.${CJSON_VERSION:?} build/obj/cJSON.o \
     && unset CFLAGS \
     && (cd build/lib \
        && MIN=${CJSON_VERSION%.*} && MAJ=${MIN%.*} \
        && ln -s libcJSON.so.${CJSON_VERSION:?} libcJSON.so.${MIN:?} \
        && ln -s libcJSON.so.${MIN:?} libcJSON.so.${MAJ} \
        ) \
     && ${HOST_}ar rcs build/lib/libcJSON.a build/obj/cJSON.o \
     && cp -t build/. LICENSE README.md \
     && cp -t build/include/. cJSON.h \
     && rm build/obj -rf \
     && (cd build \
        && find -type f -not -name MD5SUM -exec md5sum -b {} + > MD5SUM \
        && tar --owner=0 --group=0 -czf "${CJSON_BINTGZ:?}" * \
        && md5sum -b "${CJSON_BINTGZ:?}" > "${CJSON_BINTGZ:?}.md5" \
        ) \
     && cd .. && rm -rf "cJSON-${CJSON_VERSION:?}" \
     );fi \
  && printf '\n  DONE\n\n'


## Install
true \
  && $SUDO tar -C "${INSTALL_ROOT:?}" -xzf "${CJSON_BINTGZ:?}" \
  && true