diff --git a/README.md b/README.md
index 4193e355..0a28c4ab 100644
--- a/README.md
+++ b/README.md
@@ -2,37 +2,34 @@
 
 [![Build Status](https://travis-ci.org/kewlbear/FFmpeg-iOS-build-script.svg?branch=master)](https://travis-ci.org/kewlbear/FFmpeg-iOS-build-script)
 
-This is a shell script to build FFmpeg libraries for iOS and tvOS apps.
+This is a shell script to build FFmpeg as XCFramework
 
 Tested with:
 
 * FFmpeg 4.2
-* Xcode 10.1
+* Xcode 11
 
 ## Requirements
 
 * https://github.com/libav/gas-preprocessor
 * yasm 1.2.0
 
-## Usage
-
-Use build-ffmpeg-tvos.sh for tvOS.
-
-* To build everything:
+## Supported platforms
 
-        ./build-ffmpeg.sh
+* iOS: arm64 for device and X86_64 for simulator
+* tvOS: arm64 for device and X86_64 for simulator
+* macOS: X86_64
+* macOS-catalyst: X86_64
 
-* To build arm64 libraries:
-
-        ./build-ffmpeg.sh arm64
+## Usage
 
-* To build fat libraries for armv7 and x86_64 (64-bit simulator):
+* To build XCFramework with all platforms included, run
 
-        ./build-ffmpeg.sh armv7 x86_64
+        ./build.sh
 
-* To build fat libraries from separately built thin libraries:
+## Issues
 
-        ./build-ffmpeg.sh lipo
+* x86_64 binaries are built without ASM support, since ASM for x86_64 is actually x86 and that confuses `xcodebuild -create-xcframework`
 
 ## Download
 
diff --git a/build-ffmpeg-iOS-framework.sh b/build-ffmpeg-iOS-framework.sh
deleted file mode 100755
index 56e2be6b..00000000
--- a/build-ffmpeg-iOS-framework.sh
+++ /dev/null
@@ -1,191 +0,0 @@
-#!/bin/sh
-
-# directories
-SCRATCH=`pwd`/"scratch"
-ARCHS="arm64 armv7 i386 x86_64"
-
-FFMPEG_VERSION="3.4"
-export FFMPEG_VERSION
-HEADER_SUFFIX=".h"
-CURRENT_FOLDER=`pwd`
-FRAMEWORK_NAME="FFmpeg"
-FRAMEWORK_EXT=".framework"
-FRAMEWORK="$FRAMEWORK_NAME$FRAMEWORK_EXT"
-BUILD_FOLDER="$CURRENT_FOLDER/FFmpeg-iOS"
-BUILD_THIN_FOLDER="$CURRENT_FOLDER/thin"
-BUILD_INCLUDE_FOLDER="$BUILD_FOLDER/include"
-BUILD_LIB_FOLDER="$BUILD_FOLDER/lib"
-OUTPUT_FOLDER="$CURRENT_FOLDER/$FRAMEWORK"
-OUTPUT_INFO_PLIST_FILE="$OUTPUT_FOLDER/Info.plist"
-OUTPUT_HEADER_FOLDER="$OUTPUT_FOLDER/Headers"
-OUTPUT_UMBRELLA_HEADER="$OUTPUT_HEADER_FOLDER/ffmpeg.h"
-OUTPUT_MODULES_FOLDER="$OUTPUT_FOLDER/Modules"
-OUTPUT_MODULES_FILE="$OUTPUT_MODULES_FOLDER/module.modulemap"
-VERSION_NEW_NAME="Version.h"
-BUNDLE_ID="org.ffmpeg.FFmpeg"
-
-function CreateFramework() {
-  rm -rf $OUTPUT_FOLDER
-  mkdir -p $OUTPUT_HEADER_FOLDER $OUTPUT_MODULES_FOLDER
-}
-
-function CompileSource() {
-  ./build-ffmpeg.sh $ARCHS
-  ./build-ffmpeg.sh lipo
-}
-
-function MergeStaticLibrary() {
-  local files=""
-
-  for ARCH in $ARCHS; do
-    folder="$SCRATCH/$ARCH"
-    name="$FRAMEWORK_NAME$ARCH.a"
-    ar cru $name $(find $folder -name "*.o")
-    files="$files $name"
-  done
-
-  lipo -create $files -output FFmpeg
-
-  for file in $files; do
-    rm -rf $file
-  done
-  mv $FRAMEWORK_NAME $OUTPUT_FOLDER
-}
-
-function RenameHeader() {
-  local include_folder="$(pwd)/FFmpeg-iOS/include"
-  local need_replace_version_folder=""
-  for folder in "$include_folder"/*; do
-    local folder_name=`basename $folder`
-    local verstion_file_name="$folder_name$VERSION_NEW_NAME"
-    for header in "$folder"/*; do
-			local header_name=`basename $header`
-
-			local dst_name=$header_name
-			if [ $header_name == "version.h" ]; then
-				dst_name=$verstion_file_name
-			fi
-
-			local dst_folder=$OUTPUT_HEADER_FOLDER
-			local file_name="$folder/$header_name"
-			local dst_file_name="$dst_folder/$dst_name"
-			cp $file_name $dst_file_name
-			find "$dst_folder" -name "$dst_name" -type f -exec sed -i '' "s/\"version.h\"/\"$verstion_file_name\"/g" {} \;
-		done
-    need_replace_version_folder="$need_replace_version_folder $folder_name"
-  done
-
-  for folder_name in $need_replace_version_folder; do
-    local verstion_file_name="$folder_name$VERSION_NEW_NAME"
-    find $OUTPUT_HEADER_FOLDER -type f -exec sed -i '' "s/\"$folder_name\/version.h\"/\"$verstion_file_name\"/g" {} \;
-  done
-  find $OUTPUT_HEADER_FOLDER -type f -exec sed -i '' "s/libavformat\///g" {} \;
-  find $OUTPUT_HEADER_FOLDER -type f -exec sed -i '' "s/libavutil\///g" {} \;
-	find $OUTPUT_HEADER_FOLDER -type f -exec sed -i '' "s/libavcodec\///g" {} \;
-}
-
-# COPY MISSING inttypes.h
-function CopyInttype() {
-  local file="$(xcode-select -p)/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/clang/include/inttypes.h"
-	cp $file $OUTPUT_HEADER_FOLDER
-	find $OUTPUT_HEADER_FOLDER -type f -exec sed -i '' "s/<inttypes.h>/\"inttypes.h\"/g" {} \;
-}
-
-function CreateModulemapAndUmbrellaHeader() {
-  #create ffmpeg.h
-  cat > $OUTPUT_UMBRELLA_HEADER <<EOF
-#import <Foundation/Foundation.h>
-#import <VideoToolbox/VideoToolbox.h>
-#import <AudioToolbox/AudioToolbox.h>
-#include "avcodec.h"
-#include "avdevice.h"
-#include "avfilter.h"
-#include "avformat.h"
-#include "avutil.h"
-#include "swscale.h"
-#include "swresample.h"
-double FFmpegVersionNumber = $FFMPEG_VERSION;
-EOF
-
-  cat > $OUTPUT_MODULES_FILE <<EOF
-framework module $FRAMEWORK_NAME {
-  umbrella header "ffmpeg.h"
-
-  export *
-  module * { export * }
-}
-EOF
-}
-
-function CreateInfoPlist() {
-  DEFAULT_iOS_SDK_VERSION=`defaults read $(xcode-select -p)/Platforms/iPhoneOS.platform/version CFBundleShortVersionString`
-  DTCompiler=`defaults read $(xcode-select -p)/../info DTCompiler`
-  DTPlatformBuild=`defaults read $(xcode-select -p)/../info DTPlatformBuild`
-  DTSDKBuild=`defaults read $(xcode-select -p)/../info DTSDKBuild`
-  DTXcode=`defaults read $(xcode-select -p)/../info DTXcode`
-  DTXcodeBuild=`defaults read $(xcode-select -p)/../info DTXcodeBuild`
-  OS_BUILD_VERSION=$(sw_vers -buildVersion)
-  cat > $OUTPUT_INFO_PLIST_FILE <<EOF
-  <?xml version="1.0" encoding="UTF-8"?>
-  <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
-  <plist version="1.0">
-  <dict>
-          <key>BuildMachineOSBuild</key>
-          <string>$OS_BUILD_VERSION</string>
-          <key>CFBundleDevelopmentRegion</key>
-          <string>en</string>
-          <key>CFBundleExecutable</key>
-          <string>$FRAMEWORK_NAME</string>
-          <key>CFBundleIdentifier</key>
-          <string>$BUNDLE_ID</string>
-          <key>CFBundleInfoDictionaryVersion</key>
-          <string>6.0</string>
-          <key>CFBundleName</key>
-          <string>$FRAMEWORK_NAME</string>
-          <key>CFBundlePackageType</key>
-          <string>FMWK</string>
-          <key>CFBundleShortVersionString</key>
-          <string>$FFMPEG_VERSION</string>
-          <key>CFBundleSignature</key>
-          <string>????</string>
-          <key>CFBundleSupportedPlatforms</key>
-          <array>
-          <string>iPhoneOS</string>
-          </array>
-          <key>CFBundleVersion</key>
-          <string>1</string>
-          <key>DTCompiler</key>
-          <string>$DTCompiler</string>
-          <key>DTPlatformBuild</key>
-          <string>$DTPlatformBuild</string>
-          <key>DTPlatformName</key>
-          <string>iphoneos</string>
-          <key>DTPlatformVersion</key>
-          <string>$DEFAULT_iOS_SDK_VERSION</string>
-          <key>DTSDKBuild</key>
-          <string>$DTSDKBuild</string>
-          <key>DTSDKName</key>
-          <string>iphoneos$DEFAULT_iOS_SDK_VERSION</string>
-          <key>DTXcode</key>
-          <string>$DTXcode</string>
-          <key>DTXcodeBuild</key>
-          <string>$DTXcodeBuild</string>
-          <key>MinimumOSVersion</key>
-          <string>8.0</string>
-          <key>UIDeviceFamily</key>
-          <array>
-          <integer>1</integer>
-          <integer>2</integer>
-          </array>
-  </dict>
-  </plist>
-EOF
-}
-
-CompileSource
-CreateFramework
-MergeStaticLibrary
-RenameHeader
-CreateModulemapAndUmbrellaHeader
-CopyInttype
-CreateInfoPlist
diff --git a/build-ffmpeg-tvos.sh b/build-ffmpeg-tvos.sh
deleted file mode 100755
index 7717bfda..00000000
--- a/build-ffmpeg-tvos.sh
+++ /dev/null
@@ -1,156 +0,0 @@
-#!/bin/sh
-
-# directories
-SOURCE="ffmpeg-3.1.1"
-FAT="FFmpeg-tvOS"
-
-SCRATCH="scratch-tvos"
-# must be an absolute path
-THIN=`pwd`/"thin-tvos"
-
-# absolute path to x264 library
-#X264=`pwd`/../x264-ios/x264-iOS
-
-#FDK_AAC=`pwd`/fdk-aac/fdk-aac-ios
-
-CONFIGURE_FLAGS="--enable-cross-compile --disable-debug --disable-programs \
-                 --disable-doc --enable-pic --disable-indev=avfoundation"
-
-if [ "$X264" ]
-then
-	CONFIGURE_FLAGS="$CONFIGURE_FLAGS --enable-gpl --enable-libx264"
-fi
-
-if [ "$FDK_AAC" ]
-then
-	CONFIGURE_FLAGS="$CONFIGURE_FLAGS --enable-libfdk-aac"
-fi
-
-# avresample
-#CONFIGURE_FLAGS="$CONFIGURE_FLAGS --enable-avresample"
-
-ARCHS="arm64 x86_64"
-
-COMPILE="y"
-LIPO="y"
-
-DEPLOYMENT_TARGET="9.0"
-
-if [ "$*" ]
-then
-	if [ "$*" = "lipo" ]
-	then
-		# skip compile
-		COMPILE=
-	else
-		ARCHS="$*"
-		if [ $# -eq 1 ]
-		then
-			# skip lipo
-			LIPO=
-		fi
-	fi
-fi
-
-if [ "$COMPILE" ]
-then
-	if [ ! `which yasm` ]
-	then
-		echo 'Yasm not found'
-		if [ ! `which brew` ]
-		then
-			echo 'Homebrew not found. Trying to install...'
-                        ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" \
-				|| exit 1
-		fi
-		echo 'Trying to install Yasm...'
-		brew install yasm || exit 1
-	fi
-	if [ ! `which gas-preprocessor.pl` ]
-	then
-		echo 'gas-preprocessor.pl not found. Trying to install...'
-		(curl -L https://github.com/libav/gas-preprocessor/raw/master/gas-preprocessor.pl \
-			-o /usr/local/bin/gas-preprocessor.pl \
-			&& chmod +x /usr/local/bin/gas-preprocessor.pl) \
-			|| exit 1
-	fi
-
-	if [ ! -r $SOURCE ]
-	then
-		echo 'FFmpeg source not found. Trying to download...'
-		curl http://www.ffmpeg.org/releases/$SOURCE.tar.bz2 | tar xj \
-			|| exit 1
-	fi
-
-	CWD=`pwd`
-	for ARCH in $ARCHS
-	do
-		echo "building $ARCH..."
-		mkdir -p "$SCRATCH/$ARCH"
-		cd "$SCRATCH/$ARCH"
-
-		CFLAGS="-arch $ARCH"
-		if [ "$ARCH" = "x86_64" ]
-		then
-		    PLATFORM="AppleTVSimulator"
-		    CFLAGS="$CFLAGS -mtvos-simulator-version-min=$DEPLOYMENT_TARGET"
-		else
-		    PLATFORM="AppleTVOS"
-		    CFLAGS="$CFLAGS -mtvos-version-min=$DEPLOYMENT_TARGET -fembed-bitcode"
-		    if [ "$ARCH" = "arm64" ]
-		    then
-		        EXPORT="GASPP_FIX_XCODE5=1"
-		    fi
-		fi
-
-		XCRUN_SDK=`echo $PLATFORM | tr '[:upper:]' '[:lower:]'`
-		CC="xcrun -sdk $XCRUN_SDK clang"
-		AR="xcrun -sdk $XCRUN_SDK ar"
-		CXXFLAGS="$CFLAGS"
-		LDFLAGS="$CFLAGS"
-		if [ "$X264" ]
-		then
-			CFLAGS="$CFLAGS -I$X264/include"
-			LDFLAGS="$LDFLAGS -L$X264/lib"
-		fi
-		if [ "$FDK_AAC" ]
-		then
-			CFLAGS="$CFLAGS -I$FDK_AAC/include"
-			LDFLAGS="$LDFLAGS -L$FDK_AAC/lib"
-		fi
-
-		TMPDIR=${TMPDIR/%\/} $CWD/$SOURCE/configure \
-		    --target-os=darwin \
-		    --arch=$ARCH \
-		    --cc="$CC" \
-		    --ar="$AR" \
-		    $CONFIGURE_FLAGS \
-		    --extra-cflags="$CFLAGS" \
-		    --extra-ldflags="$LDFLAGS" \
-		    --prefix="$THIN/`basename $PWD`" \
-		|| exit 1
-
-		xcrun -sdk $XCRUN_SDK make -j3 install $EXPORT || exit 1
-		cd $CWD
-	done
-fi
-
-if [ "$LIPO" ]
-then
-	echo "building fat binaries..."
-	mkdir -p $FAT/lib
-	set - $ARCHS
-	CWD=`pwd`
-	cd $THIN/$1/lib
-	for LIB in *.a
-	do
-		cd $CWD
-		echo lipo -create `find $THIN -name $LIB` -output $FAT/lib/$LIB 1>&2
-		lipo -create `find $THIN -name $LIB` -output $FAT/lib/$LIB || exit 1
-	done
-
-	cd $CWD
-	cp -rf $THIN/$1/include $FAT
-fi
-
-echo Done
diff --git a/build-ffmpeg.sh b/build-ffmpeg.sh
deleted file mode 100755
index a67ae908..00000000
--- a/build-ffmpeg.sh
+++ /dev/null
@@ -1,169 +0,0 @@
-#!/bin/sh
-
-# directories
-FF_VERSION="4.2"
-#FF_VERSION="snapshot-git"
-if [[ $FFMPEG_VERSION != "" ]]; then
-  FF_VERSION=$FFMPEG_VERSION
-fi
-SOURCE="ffmpeg-$FF_VERSION"
-FAT="FFmpeg-iOS"
-
-SCRATCH="scratch"
-# must be an absolute path
-THIN=`pwd`/"thin"
-
-# absolute path to x264 library
-#X264=`pwd`/fat-x264
-
-#FDK_AAC=`pwd`/../fdk-aac-build-script-for-iOS/fdk-aac-ios
-
-CONFIGURE_FLAGS="--enable-cross-compile --disable-debug --disable-programs \
-                 --disable-doc --enable-pic"
-
-if [ "$X264" ]
-then
-	CONFIGURE_FLAGS="$CONFIGURE_FLAGS --enable-gpl --enable-libx264"
-fi
-
-if [ "$FDK_AAC" ]
-then
-	CONFIGURE_FLAGS="$CONFIGURE_FLAGS --enable-libfdk-aac --enable-nonfree"
-fi
-
-# avresample
-#CONFIGURE_FLAGS="$CONFIGURE_FLAGS --enable-avresample"
-
-ARCHS="arm64 armv7 x86_64 i386"
-
-COMPILE="y"
-LIPO="y"
-
-DEPLOYMENT_TARGET="8.0"
-
-if [ "$*" ]
-then
-	if [ "$*" = "lipo" ]
-	then
-		# skip compile
-		COMPILE=
-	else
-		ARCHS="$*"
-		if [ $# -eq 1 ]
-		then
-			# skip lipo
-			LIPO=
-		fi
-	fi
-fi
-
-if [ "$COMPILE" ]
-then
-	if [ ! `which yasm` ]
-	then
-		echo 'Yasm not found'
-		if [ ! `which brew` ]
-		then
-			echo 'Homebrew not found. Trying to install...'
-                        ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" \
-				|| exit 1
-		fi
-		echo 'Trying to install Yasm...'
-		brew install yasm || exit 1
-	fi
-	if [ ! `which gas-preprocessor.pl` ]
-	then
-		echo 'gas-preprocessor.pl not found. Trying to install...'
-		(curl -L https://github.com/libav/gas-preprocessor/raw/master/gas-preprocessor.pl \
-			-o /usr/local/bin/gas-preprocessor.pl \
-			&& chmod +x /usr/local/bin/gas-preprocessor.pl) \
-			|| exit 1
-	fi
-
-	if [ ! -r $SOURCE ]
-	then
-		echo 'FFmpeg source not found. Trying to download...'
-		curl http://www.ffmpeg.org/releases/$SOURCE.tar.bz2 | tar xj \
-			|| exit 1
-	fi
-
-	CWD=`pwd`
-	for ARCH in $ARCHS
-	do
-		echo "building $ARCH..."
-		mkdir -p "$SCRATCH/$ARCH"
-		cd "$SCRATCH/$ARCH"
-
-		CFLAGS="-arch $ARCH"
-		if [ "$ARCH" = "i386" -o "$ARCH" = "x86_64" ]
-		then
-		    PLATFORM="iPhoneSimulator"
-		    CFLAGS="$CFLAGS -mios-simulator-version-min=$DEPLOYMENT_TARGET"
-		else
-		    PLATFORM="iPhoneOS"
-		    CFLAGS="$CFLAGS -mios-version-min=$DEPLOYMENT_TARGET -fembed-bitcode"
-		    if [ "$ARCH" = "arm64" ]
-		    then
-		        EXPORT="GASPP_FIX_XCODE5=1"
-		    fi
-		fi
-
-		XCRUN_SDK=`echo $PLATFORM | tr '[:upper:]' '[:lower:]'`
-		CC="xcrun -sdk $XCRUN_SDK clang"
-
-		# force "configure" to use "gas-preprocessor.pl" (FFmpeg 3.3)
-		if [ "$ARCH" = "arm64" ]
-		then
-		    AS="gas-preprocessor.pl -arch aarch64 -- $CC"
-		else
-		    AS="gas-preprocessor.pl -- $CC"
-		fi
-
-		CXXFLAGS="$CFLAGS"
-		LDFLAGS="$CFLAGS"
-		if [ "$X264" ]
-		then
-			CFLAGS="$CFLAGS -I$X264/include"
-			LDFLAGS="$LDFLAGS -L$X264/lib"
-		fi
-		if [ "$FDK_AAC" ]
-		then
-			CFLAGS="$CFLAGS -I$FDK_AAC/include"
-			LDFLAGS="$LDFLAGS -L$FDK_AAC/lib"
-		fi
-
-		TMPDIR=${TMPDIR/%\/} $CWD/$SOURCE/configure \
-		    --target-os=darwin \
-		    --arch=$ARCH \
-		    --cc="$CC" \
-		    --as="$AS" \
-		    $CONFIGURE_FLAGS \
-		    --extra-cflags="$CFLAGS" \
-		    --extra-ldflags="$LDFLAGS" \
-		    --prefix="$THIN/$ARCH" \
-		|| exit 1
-
-		make -j3 install $EXPORT || exit 1
-		cd $CWD
-	done
-fi
-
-if [ "$LIPO" ]
-then
-	echo "building fat binaries..."
-	mkdir -p $FAT/lib
-	set - $ARCHS
-	CWD=`pwd`
-	cd $THIN/$1/lib
-	for LIB in *.a
-	do
-		cd $CWD
-		echo lipo -create `find $THIN -name $LIB` -output $FAT/lib/$LIB 1>&2
-		lipo -create `find $THIN -name $LIB` -output $FAT/lib/$LIB || exit 1
-	done
-
-	cd $CWD
-	cp -rf $THIN/$1/include $FAT
-fi
-
-echo Done
diff --git a/build.sh b/build.sh
new file mode 100755
index 00000000..786b0c19
--- /dev/null
+++ b/build.sh
@@ -0,0 +1,134 @@
+#!/bin/sh
+
+source common.sh
+source config.sh
+
+PrepareYasm
+
+FFMPEG_PLATFORMS="ffmpeg_ios ffmpeg_tvos ffmpeg_macos ffmpeg_maccatalyst"
+
+function Build() {
+    local platform=$1
+    local arch=$2
+
+    echo "${ORANGE}Building for platform: $platform, arch: $arch ${NOCOLOR}"
+
+	  local current_dir=`pwd`
+    local build_dir="$platform/scratch/$arch"
+    local thin="$current_dir/$platform/thin"
+    local prefix="$thin/$arch"
+
+    mkdir -p "$build_dir"
+    cd "$build_dir"
+
+    local xcrun_sdk=`echo $PLATFORM | tr '[:upper:]' '[:lower:]'`
+		CC="xcrun -sdk $xcrun_sdk clang"
+
+		# force "configure" to use "gas-preprocessor.pl" (FFmpeg 3.3)
+		if [ "$arch" = "arm64" ]
+		then
+  			AS="gas-preprocessor.pl -arch aarch64 -- $CC"
+		else
+			  AS="gas-preprocessor.pl -- $CC"
+		fi
+
+		CXXFLAGS="$CFLAGS"
+		LDFLAGS="$CFLAGS"
+
+		if [ "$X264" ]
+		then
+			   CFLAGS="$CFLAGS -I$X264/include"
+         LDFLAGS="$LDFLAGS -L$X264/lib"
+		fi
+
+		if [ "$FDK_AAC" ]
+		then
+        CFLAGS="$CFLAGS -I$FDK_AAC/include"
+        LDFLAGS="$LDFLAGS -L$FDK_AAC/lib"
+		fi
+
+		TMPDIR=${TMPDIR/%\/} $current_dir/$SOURCE/configure \
+			--target-os=darwin \
+			--arch=$arch \
+			--cc="$CC" \
+			--as="$AS" \
+			$CONFIGURE_FLAGS \
+			--extra-cflags="$CFLAGS" \
+			--extra-ldflags="$LDFLAGS" \
+			--prefix="$prefix" \
+		|| exit 1
+
+		make -j3 install $EXPORT || exit 1
+		cd $current_dir
+}
+
+function PackageToLibrary() {
+    local platform=$1
+    local arch=$2
+
+    echo "${ORANGE}Packaging library for platform: $platform, arch: $arch ${NOCOLOR}"
+
+    local current_dir=`pwd`
+    local build_dir="$platform/scratch/$arch"
+    local thin_dir="$current_dir/$platform/thin/$arch"
+
+    local object_files="$(FindObjectFiles $build_dir)"
+
+#    echo $object_files
+
+    libtool $LIBTOOL_FLAGS \
+        -static -D -arch_only $arch \
+        $object_files -o "$thin_dir/$LIBRARY_FILE"
+}
+
+function BuildAll() {
+    echo "${ORANGE}Building for platforms:${MAGENTA} $FFMPEG_PLATFORMS ${NOCOLOR}"
+
+    for FFMPEG_PLATFORM in $FFMPEG_PLATFORMS
+    do
+        rm -rf "$FFMPEG_PLATFORM"
+
+        local archs="$(Architectures $FFMPEG_PLATFORM)"
+        echo "${ORANGE}>>> Building platform: $FFMPEG_PLATFORM Available ARCHS:${MAGENTA} $archs ${NOCOLOR}"
+
+        for arch in $archs
+        do
+            Configure $FFMPEG_PLATFORM $arch
+            Build $FFMPEG_PLATFORM $arch
+            PackageToLibrary $FFMPEG_PLATFORM $arch
+        done
+
+    done
+}
+
+function CreateXCFramework() {
+    echo "${ORANGE}Creating framework: $FFMPEG_PLATFORMS ${NOCOLOR}"
+
+    local framework_arguments=""
+
+    rm -rf $XCFRAMEWORK_FILE
+
+    for FFMPEG_PLATFORM in $FFMPEG_PLATFORMS
+    do
+        local archs="$(Architectures $FFMPEG_PLATFORM)"
+
+        for arch in $archs
+        do
+            local thin_dir="$FFMPEG_PLATFORM/thin/$arch"
+            local include_dir="$thin_dir/include"
+
+            framework_arguments="$framework_arguments -library $thin_dir/$LIBRARY_FILE"
+            framework_arguments="$framework_arguments -headers $include_dir"
+        done
+
+    done
+
+    echo $XCFRAMEWORK_FILE
+
+    xcodebuild -create-xcframework \
+        $framework_arguments \
+        -output "$XCFRAMEWORK_FILE"
+}
+
+BuildAll
+CreateXCFramework
diff --git a/common.sh b/common.sh
new file mode 100755
index 00000000..474e5886
--- /dev/null
+++ b/common.sh
@@ -0,0 +1,49 @@
+#!/bin/sh
+
+ORANGE="\033[1;93m"
+RED="\033[1;91m"
+MAGENTA="\033[1;35m"
+NOCOLOR="\033[0m"
+
+function PrepareYasm() {
+    if [ ! `which yasm` ]
+	  then
+		    echo 'Yasm not found'
+
+        if [ ! `which brew` ]
+        then
+            echo "${RED}Homebrew not found. Trying to install... ${NOCOLOR}"
+				    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" \
+		        || exit 1
+        fi
+
+        echo 'Trying to install Yasm...'
+        brew install yasm || exit 1
+    fi
+
+	  if [ ! `which gas-preprocessor.pl` ]
+	  then
+		    echo "${RED}gas-preprocessor.pl not found. Trying to install... ${NOCOLOR}"
+		    (curl -L https://github.com/libav/gas-preprocessor/raw/master/gas-preprocessor.pl \
+		          -o /usr/local/bin/gas-preprocessor.pl \
+			        && chmod +x /usr/local/bin/gas-preprocessor.pl) \
+			  || exit 1
+	  fi
+
+    if [ ! -r $SOURCE ]
+	  then
+		    echo "${RED}FFmpeg source not found ${NOCOLOR}"
+        exit 1
+	  fi
+}
+
+function FindObjectFiles() {
+    local search_dir=$1
+
+	  local object_files=""
+
+	  local name=$(find $search_dir -maxdepth 3 -name "*.o")
+	  object_files="$object_files $name"
+
+    echo $object_files
+}
diff --git a/config.sh b/config.sh
new file mode 100755
index 00000000..1cb383eb
--- /dev/null
+++ b/config.sh
@@ -0,0 +1,151 @@
+#!/bin/sh
+
+FF_VERSION="4.1"
+#FF_VERSION="snapshot-git"
+if [[ $FFMPEG_VERSION != "" ]]; then
+  FF_VERSION=$FFMPEG_VERSION
+fi
+
+SOURCE="../"
+XCODE_PATH=$(xcode-select -p)
+LIBRARY_NAME="FFmpeg"
+LIBRARY_FILE="$LIBRARY_NAME.a"
+
+XCFRAMEWORK_FILE="$LIBRARY_NAME.xcframework"
+
+CONFIGURE_FLAGS="\
+				--enable-cross-compile \
+				--disable-debug --disable-programs --disable-doc \
+				--disable-encoders --disable-decoders --disable-protocols --disable-filters  \
+				--disable-muxers --disable-bsfs --disable-indevs --disable-outdevs --disable-demuxers \
+				--enable-pic \
+				--enable-decoder=h264 \
+				--enable-demuxer=mpegts \
+				--enable-parser=h264 \
+				--enable-videotoolbox"
+
+if [ "$X264" ]
+then
+		CONFIGURE_FLAGS="$CONFIGURE_FLAGS --enable-gpl --enable-libx264"
+fi
+
+if [ "$FDK_AAC" ]
+then
+		CONFIGURE_FLAGS="$CONFIGURE_FLAGS --enable-libfdk-aac --enable-nonfree"
+fi
+
+function ConfigureForIOS() {
+		local arch=$1
+		DEPLOYMENT_TARGET="9.0"
+		PLATFORM="iPhoneOS"
+
+    LIBTOOL_FLAGS="\
+		 -syslibroot $XCODE_PATH/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk \
+		 -L$XCODE_PATH/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/iOSSupport/usr/lib"
+
+    CFLAGS="-arch $arch"
+
+		if [ "$arch" = "i386" -o "$arch" = "x86_64" ]
+		then
+				PLATFORM="iPhoneSimulator"
+				CFLAGS="$CFLAGS -mios-simulator-version-min=$DEPLOYMENT_TARGET"
+				CONFIGURE_FLAGS="$CONFIGURE_FLAGS --disable-asm"
+		else
+				CFLAGS="$CFLAGS -mios-version-min=$DEPLOYMENT_TARGET -fembed-bitcode"
+				if [ "$ARCH" = "arm64" ]
+				then
+						EXPORT="GASPP_FIX_XCODE5=1"
+				fi
+		fi
+}
+
+function ConfigureForTVOS() {
+		local arch=$1
+		DEPLOYMENT_TARGET="12.0"
+		PLATFORM="AppleTVOS"
+
+    LIBTOOL_FLAGS="\
+		 -syslibroot $XCODE_PATH/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS.sdk \
+		 -L$XCODE_PATH/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS.sdk/System/usr/lib"
+
+    CFLAGS="-arch $arch"
+
+		if [ "$arch" = "i386" -o "$arch" = "x86_64" ]
+		then
+				PLATFORM="AppleTVSimulator"
+				CFLAGS="$CFLAGS -mtvos-simulator-version-min=$DEPLOYMENT_TARGET"
+				CONFIGURE_FLAGS="$CONFIGURE_FLAGS --disable-asm"
+		else
+				CFLAGS="$CFLAGS -mtvos-version-min=$DEPLOYMENT_TARGET -fembed-bitcode"
+				if [ "$ARCH" = "arm64" ]
+				then
+						EXPORT="GASPP_FIX_XCODE5=1"
+				fi
+		fi
+}
+
+function ConfigureForMacOS() {
+		local arch=$1
+		DEPLOYMENT_TARGET="10.14"
+		PLATFORM="MacOSX"
+
+    LIBTOOL_FLAGS="\
+		 -syslibroot $XCODE_PATH/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk \
+		 -L$XCODE_PATH/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/usr/lib"
+
+    CFLAGS="-arch $arch"
+		CONFIGURE_FLAGS="$CONFIGURE_FLAGS --disable-asm"
+		CFLAGS="$CFLAGS -mmacosx-version-min=$DEPLOYMENT_TARGET"
+}
+
+function ConfigureForMacCatalyst() {
+		local arch=$1
+		DEPLOYMENT_TARGET="10.15"
+		PLATFORM="iPhoneOS"
+
+    LIBTOOL_FLAGS="\
+		-syslibroot $XCODE_PATH/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk \
+		-L$XCODE_PATH/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/iOSSupport/usr/lib \
+		-L$XCODE_PATH/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/maccatalyst"
+
+		CFLAGS="-arch $arch"
+		CONFIGURE_FLAGS="$CONFIGURE_FLAGS --disable-asm"
+
+		CFLAGS="$CFLAGS -target x86_64-apple-ios13.0-macabi \
+						-isysroot $XCODE_PATH/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk \
+						-isystem $XCODE_PATH/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/iOSSupport/usr/include \
+						-iframework $XCODE_PATH/Platforms/MacOSX.platform/Developer/SDKs/MacOS.sdk/System/iOSSupport/System/Library/Frameworks"
+
+		LDFLAGS="$LDFLAGS -target x86_64-apple-ios13.0-macabi \
+				-isysroot $XCODE_PATH/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk \
+				-L$XCODE_PATH/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/iOSSupport/usr/lib \
+				-L$XCODE_PATH/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/maccatalyst \
+				-iframework $XCODE_PATH/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/iOSSupport/System/Library/Frameworks"
+}
+
+# supported platforms are: "ffmpeg_ios", "ffmpeg_tvos", "ffmpeg_macos", "ffmpeg_maccatalyst"
+
+function Architectures() {
+		local platform=$1
+
+		case $platform in
+				ffmpeg_ios)					echo "arm64 x86_64" ;;
+				ffmpeg_tvos) 				echo "arm64 x86_64" ;;
+				ffmpeg_macos)				echo "x86_64" ;;
+				ffmpeg_maccatalyst)	echo "x86_64" ;;
+		esac
+}
+
+function Configure() {
+		local platform=$1
+		local arch=$2
+
+		echo "${ORANGE}Configuring for platform: $platform, arch: $arch"
+
+		case $platform in
+				ffmpeg_ios)					ConfigureForIOS $arch ;;
+				ffmpeg_tvos) 				ConfigureForTVOS $arch ;;
+				ffmpeg_macos)				ConfigureForMacOS $arch ;;
+				ffmpeg_maccatalyst)	ConfigureForMacCatalyst $arch ;;
+		esac
+}