Check-in [232fd3b1ce]
Overview
Comment:Added script to build static AppFS packages
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:232fd3b1ce53de1028daf859b7a520dacc3301ba
User & Date: rkeene on 2017-02-23 22:31:32
Other Links: manifest | tags
Context
2017-10-30
18:03
Added start of docker init code check-in: 2d83a6231c user: rkeene tags: trunk
2017-02-23
22:31
Added script to build static AppFS packages check-in: 232fd3b1ce user: rkeene tags: trunk
22:25
Updated to include TCL_LIBS when trying to link appfs, which may be needed if we are linking statically check-in: d8a575fad2 user: rkeene tags: trunk
Changes

Added build/make-static-package version [86421397e1].

            1  +#! /usr/bin/env bash
            2  +
            3  +###############################
            4  +## UPSTREAM ###################
            5  +###############################
            6  +fuse_version='2.9.7'
            7  +fuse_url="https://github.com/libfuse/libfuse/releases/download/fuse-${fuse_version}/fuse-${fuse_version}.tar.gz"
            8  +fuse_sha256='832432d1ad4f833c20e13b57cf40ce5277a9d33e483205fc63c78111b3358874'
            9  +
           10  +kitcreator_version='0.10.0'
           11  +kitcreator_url="http://rkeene.org/devel/kitcreator-${kitcreator_version}.tar.gz"
           12  +kitcreator_sha256='ac815b74709d27791021099418cf16c2ff7f5096d3fb7b17c50e6742f5a1a2bb'
           13  +
           14  +###############################
           15  +## USER SUPPLIED ##############
           16  +###############################
           17  +_setup_cc="${HOME}/root/cross-compilers/setup-cc"
           18  +_config_sub="$(ls -1 /usr/share/automake-*/config.sub 2>/dev/null | head -n 1)"
           19  +appfs_tarball="$1"
           20  +host_platform="$2"
           21  +if [ -z "${appfs_tarball}" ]; then
           22  +	echo "Usage: make-static-archive <tarball> [<host_platform>]" >&2
           23  +
           24  +	exit 1
           25  +fi
           26  +
           27  +appfs_tarball="$(readlink -f "${appfs_tarball}")"
           28  +if [ ! -e "${appfs_tarball}" ]; then
           29  +	echo "Archive (${appfs_tarball}) not found." >&2
           30  +
           31  +	exit 1
           32  +fi
           33  +
           34  +###############################
           35  +## HELPERS ####################
           36  +###############################
           37  +function download() {
           38  +	local archive url sha256
           39  +	local tmpfile tmpfile_sha256
           40  +
           41  +	archive="$1"
           42  +	url="$2"
           43  +	sha256="$3"
           44  +
           45  +	tmpfile="${archive}.tmp"
           46  +
           47  +	rm -f "${tmpfile}"
           48  +	curl -sS -L -o "${tmpfile}" "${url}" || return 1
           49  +
           50  +	tmpfile_sha256="$(openssl dgst -sha256 "${tmpfile}" | sed 's@^.*= *@@')"
           51  +	if [ "${tmpfile_sha256}" != "${sha256}" ]; then
           52  +		echo "SHA-256 mismatch.  Got: ${tmpfile_sha256}; Expected: ${sha256}" >&2
           53  +
           54  +		return 1
           55  +	fi
           56  +
           57  +	rm -f "${archive}"
           58  +	mv "${tmpfile}" "${archive}" || return 1
           59  +
           60  +	return 0
           61  +}
           62  +
           63  +function extract() {
           64  +	local archive directory
           65  +	local marker
           66  +
           67  +	marker="$(openssl rand 20 -hex)"
           68  +
           69  +	archive="$1"
           70  +	directory="$2"
           71  +
           72  +	mkdir -p "${directory}/.${marker}" || return 1
           73  +	cat "${archive}" | (
           74  +		cd "${directory}/.${marker}" || exit 1
           75  +		gzip -dc | tar -xf -
           76  +
           77  +		if [ -d "$(echo *)" ]; then
           78  +			mv * .TMP
           79  +			mv .TMP/* .
           80  +			rm -rf .TMP
           81  +		fi
           82  +
           83  +		find . -print0 | cpio -0 -ump .. || exit 1
           84  +
           85  +		exit 0
           86  +	) || return 1
           87  +
           88  +	rm -rf "${directory}/.${marker}"
           89  +
           90  +	return 0
           91  +}
           92  +
           93  +###############################
           94  +## MAIN #######################
           95  +###############################
           96  +
           97  +# 1. Create a workspace
           98  +workdir="$(mktemp -d)" || exit 1
           99  +startdir="$(pwd)" || exit 1
          100  +cd "${workdir}" || exit 1
          101  +
          102  +# 2. Configure cross-compiling environment
          103  +## 2.a. Set configure options to point to our fake root directory
          104  +configure_extra=(--prefix="${workdir}/root" --libdir="${workdir}/root/lib")
          105  +
          106  +## 2.b. Setup environment to match requested platform
          107  +if [ -n "${host_platform}" ]; then
          108  +	eval $("${_setup_cc}" "${host_platform}")
          109  +	unset PKG_CONFIG
          110  +
          111  +	configure_extra_common=("${configure_extra_common[@]}" --host="${host_platform}")
          112  +fi
          113  +configure_extra=("${configure_extra[@]}" "${configure_extra_common[@]}")
          114  +
          115  +# 3. Compile FUSE
          116  +## 3.a. Download FUSE
          117  +download fuse.tar.gz "${fuse_url}" "${fuse_sha256}" || exit 1
          118  +
          119  +## 3.b. Extract FUSE
          120  +extract fuse.tar.gz fuse || exit 1
          121  +rm -f fuse.tar.gz
          122  +
          123  +## 3.c. Compile FUSE
          124  +(
          125  +	cd fuse || exit 1
          126  +
          127  +	./configure --disable-shared --enable-static "${configure_extra[@]}" || exit 1
          128  +	make -j5 || exit 1
          129  +	make install MOUNT_FUSE_PATH="${workdir}/root/bin" INIT_D_PATH="${workdir}/root/etc/init.d" UDEV_RULES_PATH="${workdir}/root/etc/udev/rules.d" || exit 1
          130  +
          131  +	exit 0
          132  +) || exit 1
          133  +rm -rf fuse
          134  +
          135  +# 4. Compile Static KitDLL
          136  +## 4.a. Download KitCreator
          137  +download kitcreator.tar.gz "${kitcreator_url}" "${kitcreator_sha256}" || exit 1
          138  +
          139  +## 4.b. Extract KitCreator
          140  +extract kitcreator.tar.gz kitcreator || exit 1
          141  +rm -f kitcreator.tar.gz
          142  +
          143  +## 4.c. Patch KitCreator to build a correct Tcl
          144  +### XXX:TODO
          145  +
          146  +## 4.d. Compile KitCreator
          147  +(
          148  +	cd kitcreator || exit 1
          149  +
          150  +	export KITCREATOR_PKGS='kitdll'
          151  +	export KITCREATOR_STATIC_KITDLL='1'
          152  +	export KC_TCL_STATICPKGS='1'
          153  +	export KC_TCL_CFLAGS='-DPURIFY=1'
          154  +	export KC_TCL_CPPFLAGS='-DPURIFY=1'
          155  +
          156  +	./kitcreator "${configure_extra_common[@]}" tcl_cv_strtoul_unbroken=ok || exit 1
          157  +) || exit 1
          158  +libtclkit_sdk_archive="$(echo kitcreator/libtclkit*.tar.gz)"
          159  +
          160  +## 4.e. Extract SDK
          161  +extract "${libtclkit_sdk_archive}" root || exit 1
          162  +rm -rf kitcreator
          163  +
          164  +# 5. Compile AppFS
          165  +## 5.a. Extract AppFS
          166  +extract "${appfs_tarball}" appfs || exit 1
          167  +
          168  +## 5.b. Patch AppFS (temporary)
          169  +sed -i 's/{TCL_LIB_SPEC}/& $${TCL_LIBS}/' appfs/Makefile
          170  +
          171  +## 5.c. Compile AppFS
          172  +(
          173  +	cd appfs || exit 1
          174  +
          175  +	export PKG_CONFIG_PATH="${workdir}/root/lib/pkgconfig:${PKG_CONFIG_PATH:-/dev/null/null}"
          176  +
          177  +	if [ -n "${CC}" ]; then
          178  +		make_extra=("${make_extra[@]}" CC="${CC}")
          179  +	fi
          180  +
          181  +	if [ -n "${PKG_CONFIG}" ]; then
          182  +		make_extra=("${make_extra[@]}" PKG_CONFIG="${PKG_CONFIG}")
          183  +	fi
          184  +
          185  +	make_extra=("${make_extra[@]}" TCLKIT_SDK_DIR="${workdir}/root" TCL_LDFLAGS='' LDFLAGS='-static' PREFIX='')
          186  +
          187  +	make "${make_extra[@]}" || exit 1
          188  +	make install DESTDIR="${workdir}/output" "${make_extra[@]}" || exit 1
          189  +
          190  +	make distclean || exit 1
          191  +	make APPFS_DEBUG_BUILD=1 "${make_extra[@]}" || exit 1
          192  +	cp appfsd "${workdir}/output/sbin/appfsd_g" || exit 1
          193  +) || exit 1
          194  +
          195  +# 6. Create archive
          196  +## 6.a. Determine AppFS version and compiled platform target
          197  +### Version
          198  +appfs_version="$(grep '^APPFS_VERSION.*=' appfs/Makefile | sed 's@.*= *@@')"
          199  +
          200  +### Platform
          201  +host_platform_simple="$(${CC:-cc} -dumpmachine)"
          202  +
          203  +host_platform_simple_resolved="$("${_config_sub:-echo}" "${host_platform_simple}" 2>/dev/null)"
          204  +if [ -n "${host_platform_simple_resolved}" ]; then
          205  +	host_platform_simple="${host_platform_simple_resolved}"
          206  +fi
          207  +
          208  +case "${host_platform_simple}" in
          209  +	'')
          210  +		host_platform_simple_os="unknown"
          211  +		host_platform_simple_cpu="unknown"
          212  +		;;
          213  +	*)
          214  +		host_platform_simple_os="$(echo "${host_platform_simple}" | cut -f 3 -d '-')"
          215  +		host_platform_simple_cpu="$(echo "${host_platform_simple}" | cut -f 1 -d '-')"
          216  +		;;
          217  +esac
          218  +host_platform_simple="${host_platform_simple_os}-${host_platform_simple_cpu}"
          219  +
          220  +## 6.b. Create archive with the specified name
          221  +output_archive="${workdir}/appfs-${appfs_version}-${host_platform_simple}.tar.gz"
          222  +(
          223  +	cd "${workdir}/output" || exit 1
          224  +	tar -cf - *
          225  +) | gzip -9c > "${output_archive}"
          226  +rm -rf output appfs root
          227  +
          228  +## 6.c. Move archive to some place safe
          229  +mv -t "${startdir}" "${output_archive}" || exit 1
          230  +
          231  +## 6.d. Cleanup
          232  +cd /
          233  +rmdir "${workdir}" || exit 1
          234  +
          235  +# 7. Declare victory
          236  +exit 0