Check-in [40255f4a4f]
Overview
Comment:Example for compiling tcllibc -- very specific
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:40255f4a4f483f58c95d94f21b765a88f920a29c
User & Date: rkeene on 2019-06-05 00:34:17
Other Links: manifest | tags
Context
2019-06-05
00:38
Minor updates check-in: 6443047afb user: rkeene tags: trunk
00:34
Example for compiling tcllibc -- very specific check-in: 40255f4a4f user: rkeene tags: trunk
00:33
Added example script which converts Tcl script using Critcl to C files check-in: e5ddd6aaff user: rkeene tags: trunk
Changes

Added build/tcllibc.sh version [e69b1a60d2].

            1  +#! /usr/bin/env bash
            2  +
            3  +inFiles=(
            4  +	../tcllib-fossil/modules/tcllibc.tcl
            5  +	../tcllib-fossil/modules/md4/md4c.tcl
            6  +	../tcllib-fossil/modules/struct/graph_c.tcl
            7  +	../tcllib-fossil/modules/base32/base32_c.tcl
            8  +	../tcllib-fossil/modules/struct/sets_c.tcl
            9  +	../tcllib-fossil/modules/json/jsonc.tcl
           10  +	../tcllib-fossil/modules/pt/pt_rdengine_c.tcl
           11  +	../tcllib-fossil/modules/pt/pt_parse_peg_c.tcl
           12  +	../tcllib-fossil/modules/uuid/uuid.tcl
           13  +	../tcllib-fossil/modules/struct/tree_c.tcl
           14  +	../tcllib-fossil/modules/base32/base32hex_c.tcl
           15  +	../tcllib-fossil/modules/base64/base64c.tcl
           16  +	../tcllib-fossil/modules/base64/uuencode.tcl
           17  +	../tcllib-fossil/modules/base64/yencode.tcl
           18  +	../tcllib-fossil/modules/sha1/sha1c.tcl
           19  +	../tcllib-fossil/modules/md5/md5c.tcl
           20  +	../tcllib-fossil/modules/crc/crcc.tcl
           21  +	../tcllib-fossil/modules/crc/sum.tcl
           22  +	../tcllib-fossil/modules/crc/crc32.tcl
           23  +	../tcllib-fossil/modules/md5crypt/md5cryptc.tcl
           24  +	../tcllib-fossil/modules/struct/queue_c.tcl
           25  +	../tcllib-fossil/modules/rc4/rc4c.tcl
           26  +	../tcllib-fossil/modules/sha1/sha256c.tcl
           27  +	../tcllib-fossil/modules/struct/stack_c.tcl
           28  +	../tcllib-fossil/modules/dns/ipMoreC.tcl
           29  +)
           30  +
           31  +set -e
           32  +
           33  +outDir=''
           34  +function cleanup() {
           35  +	local localOutDir
           36  +
           37  +	localOutDir="${outDir}"
           38  +	outDir=''
           39  +
           40  +	if [ -n "${localOutDir}" ]; then
           41  +		rm -rf "${localOutDir}"
           42  +	fi
           43  +}
           44  +trap cleanup EXIT
           45  +
           46  +outDir="tmp-$(openssl rand 20 -hex)"
           47  +rm -rf "${outDir}"
           48  +mkdir "${outDir}"
           49  +
           50  +for input in "${inFiles[@]}"; do
           51  +	out="${outDir}/$(basename "${input}" .tcl)"
           52  +
           53  +	./tcc-critcl-to-c.tcl --mode direct "${input}" > "${out}.c"
           54  +	cflags=($(awk '/^CLI:/{ gsub(/^CLI:/, ""); print; }' < "${out}.c"))
           55  +
           56  +	"${CC:-cc}" -fPIC -Dinline= -o "${out}.o" "${cflags[@]}" -c "${out}.c" || continue
           57  +done
           58  +
           59  +(
           60  +	cd "${outDir}" || exit 1
           61  +
           62  +	cat << \_EOF_ > base.c
           63  +#include <tcl.h>
           64  +_EOF_
           65  +
           66  +	for input in *.c; do
           67  +		object="$(basename "${input}" .c).o"
           68  +		if [ ! -f "${object}" ]; then
           69  +			continue
           70  +		fi
           71  +
           72  +		grep '^/\* Immediate: ' "${input}"  | sed 's@^/\* Immediate: *@'$'\t''@;s@ *\*/$@@' | grep 'Tcl_CreateObjCommand' | cut -f 3 -d , | while IFS='' read -r symbol; do
           73  +			grep "${symbol}" "${input}" | grep -v '^/\* Immediate:' | sed 's@) {$@);@'
           74  +		done
           75  +	done >> base.c
           76  +
           77  +
           78  +	cat << \_EOF_ >> base.c
           79  +int Tcllibc_Init(Tcl_Interp *interp) {
           80  +#ifdef USE_TCL_STUBS
           81  +	if (Tcl_InitStubs(interp, TCL_PATCH_LEVEL, 0) == 0L) {
           82  +		return TCL_ERROR;
           83  +	}
           84  +#endif
           85  +_EOF_
           86  +
           87  +	for input in *.c; do
           88  +		object="$(basename "${input}" .c).o"
           89  +		if [ ! -f "${object}" ]; then
           90  +			continue
           91  +		fi
           92  +
           93  +		grep '^/\* Immediate: ' "${input}"  | sed 's@^/\* Immediate: *@'$'\t''@;s@ *\*/$@@' | sed 's@Tcc4tclDeleteClientData@NULL@g'
           94  +	done >> base.c
           95  +
           96  +	cat << \_EOF_ >> base.c
           97  +
           98  +	Tcl_PkgProvide(interp, "tcllibc", "0");
           99  +
          100  +	return(TCL_OK);
          101  +}
          102  +_EOF_
          103  +
          104  +	"${CC:-cc}" -fPIC -o base.o -c base.c
          105  +)
          106  +
          107  +"${CC:-cc}" -fPIC -shared -o tcllibc.so "${outDir}"/*.o
          108  +
          109  +exit 0