#!/bin/sh
# test we are root
if [ "$(id -u)" != "0" ]; then
   exit 1
fi

export CFLAGS="-flto -mtune=generic -Os -pipe"
export CXXFLAGS="-flto -mtune=generic -Os -pipe -DNDEBUG -Wno-error=class-memaccess -Wno-error=implicit-fallthrough"

P=rapidjson-dev
SRC=git
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc git cmake "
for Z in $LIST
    do 
    su -c "tce-load -i $Z" $USER
done

cd /tmp 
git clone https://github.com/Tencent/rapidjson.git
mv rapidjson $SRC
cd $SRC
mkdir build && cd build
# IGNORED CMAKE_C_FLAGS_RELEASE....CMAKE_INSTALL_LIBDIR
cmake -LAH -DCMAKE_INSTALL_PREFIX=/usr/local -DCMAKE_BUILD_TYPE=Release -DCMAKE_VERBOSE_MAKEFILE=TRUE  ../
make -j5 # 10 seconds
make install DESTDIR=/tmp/$P # no strip
cd /tmp

# main
###### creates wrong dir for doc
rm -rf $P/usr/local/share/doc
mkdir -p $P/usr/local/share/doc/$P
cp $SRC/license.txt $P/usr/local/share/doc/$P

# adapt to debian
cd $P/usr/local/lib/cmake/RapidJSON
rm -rf RapidJSON-targets.cmake  # Juanito did not have it
# no change to RapidJSONConfigVersion.cmake
rm -rf RapidJSONConfig.cmake
echo 'get_filename_component(RAPIDJSON_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
set(RAPIDJSON_INCLUDE_DIRS "/usr/local/include")
message(STATUS "RapidJSON found. Headers: ${RAPIDJSON_INCLUDE_DIRS}") ' > RapidJSONConfig.cmake
cd /tmp

# TCZ them
###########
LIST2="$P "
for Z in $LIST2
do
	mksquashfs $Z $Z.tcz
	md5sum $Z.tcz > $Z.tcz.md5.txt
	cd $Z
	find . -not -type d | cut -c 2- | sort > /tmp/$Z.tcz.list
	cd /tmp
done

ls -hal

echo 'Title:          rapidjson-dev.tcz
Description:    json c++ parser
Version:        git-20250407
Author:         multiple see license.txt
Original-site:  https://github.com/Tencent/rapidjson
Copying-policy: multiple see license.txt
Size:           224K
Extension_by:   aus9 @linuxquestions.org
Tags:           json sax dom dev
Comments:       json parser/generator for c++ with both sax/dom
                
Change-log:     2021/07/16 v 1.1.0 on 12x (Juanito)
Current:        2025/04/08 v git-20250407 (patched) on 16x (aus9) ' > $P.tcz.info
# no deps 

submitqc --libs 
rm -rf *.zsync

