cookutils rev 1008

cook, modules/deps, doc/receipts-v2.md: introduce "compiling sets"
author Aleksej Bobylev <al.bobylev@gmail.com>
date Fri Nov 17 12:47:48 2017 +0200 (2017-11-17)
parents f6dc84fcff2a
children 845d62611d92
files cook doc/receipts-v2.md modules/deps
line diff
     1.1 --- a/cook	Mon Nov 13 02:55:58 2017 +0200
     1.2 +++ b/cook	Fri Nov 17 12:47:48 2017 +0200
     1.3 @@ -479,28 +479,6 @@
     1.4  }
     1.5  
     1.6  
     1.7 -# Remove files provided by split packages
     1.8 -# For example:
     1.9 -#   1. Package "pkg-main":
    1.10 -#      SPLIT="pkg-1 pkg-2 pkg-extra"
    1.11 -#   2. Package="pkg-extra":
    1.12 -#      WANTED="pkg-main"
    1.13 -#      BUILD_DEPENDS="pkg-1 pkg-2"
    1.14 -#      cook_copy_folders usr
    1.15 -#      cook_split_rm $BUILD_DEPENDS
    1.16 -
    1.17 -cook_split_rm() {
    1.18 -	for i in $@; do
    1.19 -		action 'Remove files provided by split package %s...' "$i"
    1.20 -		while read j; do
    1.21 -			[ -f "$fs$j" -o -h "$fs$j" ] && rm $fs$j
    1.22 -			rmdir "$(dirname "$fs$j")" 2>/dev/null
    1.23 -		done < $WOK/$i/taz/$i-$VERSION/files.list
    1.24 -		:; status
    1.25 -	done
    1.26 -}
    1.27 -
    1.28 -
    1.29  # Update installed.cook.diff
    1.30  
    1.31  update_installed_cook_diff() {
    1.32 @@ -761,17 +739,22 @@
    1.33  				cd tmp; tar -c * | lzma e $SRC/$TARBALL -si
    1.34  			fi
    1.35  		fi
    1.36 +
    1.37  		cd $pkgdir/source/tmp
    1.38  		# Some archives are not well done and don't extract to one dir (ex lzma).
    1.39  		files=$(ls | wc -l)
    1.40 -		[ "$files" -eq 1 -a -d "$(ls)" ] && mv * ../$PACKAGE-$VERSION
    1.41 -		[ "$files" -eq 1 -a -f "$(ls)" ] && mkdir -p ../$PACKAGE-$VERSION && \
    1.42 -			mv * ../$PACKAGE-$VERSION/$TARBALL
    1.43 -		[ "$files" -gt 1 ] && mkdir -p ../$PACKAGE-$VERSION && \
    1.44 -			mv * ../$PACKAGE-$VERSION
    1.45 +		[ "$files" -eq 1 -a -d "$(ls)" ] &&
    1.46 +			mv *     ../$PACKAGE-$VERSION
    1.47 +		[ "$files" -eq 1 -a -f "$(ls)" ] &&
    1.48 +			mkdir -p ../$PACKAGE-$VERSION &&
    1.49 +			mv *     ../$PACKAGE-$VERSION/$TARBALL
    1.50 +		[ "$files" -gt 1 ] &&
    1.51 +			mkdir -p ../$PACKAGE-$VERSION &&
    1.52 +			mv *     ../$PACKAGE-$VERSION
    1.53  		cd ..; rm -rf tmp
    1.54  	fi
    1.55  
    1.56 +	# Check md5sum (or similar) for sources tarball
    1.57  	check_integrity
    1.58  
    1.59  	# Libtool shared libs path hack.
    1.60 @@ -779,30 +762,68 @@
    1.61  		arm*) cross libhack ;;
    1.62  	esac
    1.63  
    1.64 -	# Execute receipt rules.
    1.65 +	# Compiling all the sets
    1.66  	if grep -q ^compile_rules $receipt; then
    1.67  		_ 'Executing: %s' 'compile_rules'
    1.68  		echo "CFLAGS   : $CFLAGS"
    1.69  		#echo "LDFLAGS  : $LDFLAGS"
    1.70  		[ -d "$src" ] && cd $src
    1.71  		patchit
    1.72 -		compile_rules $@ || { broken; exit 1; }
    1.73 -		# Stay compatible with _pkg
    1.74 -		[ -d "$src/_pkg" ] && mv $src/_pkg $install
    1.75 -		# QA: compile_rules success so valid.
    1.76 -		mkdir -p $install
    1.77 -	else
    1.78 -		# QA: no compile_rules so no error, valid.
    1.79 -		mkdir -p $install
    1.80 -	fi
    1.81  
    1.82 -	copy_generic_stuff
    1.83 +		# Get set names from $SPLIT variable, format ex. 'pkg1 pkg2:set1 pkg3:set2'
    1.84 +		SETS=$(echo $SPLIT \
    1.85 +			| awk '
    1.86 +				BEGIN { RS = " "; FS = ":"; }
    1.87 +				{ print $2; }' \
    1.88 +			| sort -u \
    1.89 +			| tr '\n' ' ')
    1.90 +		SETS=${SETS% }	# normalize space
    1.91 +		# Prepare specified source sets using patched sources
    1.92 +		[ -n "$SETS" ] &&
    1.93 +		for set in $SETS; do
    1.94 +			echo "Preparing set $set"	# debug
    1.95 +			cp -a $src $src-$set
    1.96 +		done
    1.97  
    1.98 -	# Actions to do after compiling the package
    1.99 -	# Skip all for split packages (already done in main package)
   1.100 -	if [ -z "$WANTED" ]; then
   1.101 -		footer
   1.102 -		export COOKOPTS ARCH install; @@PREFIX@@/libexec/cookutils/compressor install
   1.103 +		for SET in '' $SETS; do
   1.104 +			# Switch to the specified source set
   1.105 +			set_paths
   1.106 +			local suffix=''
   1.107 +			[ -n "$SET" ] && suffix="-$SET"
   1.108 +			export     src="$WOK/$pkg/source/$PACKAGE-$VERSION$suffix"
   1.109 +			export install="$WOK/$pkg/install$suffix"
   1.110 +			export DESTDIR="$install"
   1.111 +
   1.112 +			if [ -n "$SETS" ]; then
   1.113 +				if [ -n "$SET" ]; then
   1.114 +					title "Switching to the set '$SET'"
   1.115 +				else
   1.116 +					title "Switching to the default set"
   1.117 +				fi
   1.118 +				echo "src    : $src"
   1.119 +				echo "install: $install"
   1.120 +			fi
   1.121 +			cd $src
   1.122 +			echo
   1.123 +
   1.124 +			[ -d "$install" ] && rm -r $install
   1.125 +			mkdir -p $install
   1.126 +
   1.127 +			compile_rules $@ || { broken; exit 1; }
   1.128 +
   1.129 +			# Stay compatible with _pkg
   1.130 +			[ -d "$src/_pkg" ] && mv $src/_pkg $install
   1.131 +
   1.132 +			copy_generic_stuff
   1.133 +
   1.134 +			# Actions to do after compiling the package
   1.135 +			# Skip all for split packages (already done in main package)
   1.136 +			if [ -z "$WANTED" ]; then
   1.137 +				footer
   1.138 +				export COOKOPTS ARCH install
   1.139 +				@@PREFIX@@/libexec/cookutils/compressor install
   1.140 +			fi
   1.141 +		done
   1.142  	fi
   1.143  	footer
   1.144  
   1.145 @@ -1067,18 +1088,24 @@
   1.146  # Return all the names of packages bundled in this receipt
   1.147  
   1.148  all_names() {
   1.149 -	local split=" $SPLIT "
   1.150 +	# Get package names from $SPLIT variable
   1.151 +	local split=$(echo $SPLIT \
   1.152 +		| awk '
   1.153 +			BEGIN { RS = " "; FS = ":"; }
   1.154 +			{ print $1; }' \
   1.155 +		| tr '\n' ' ')
   1.156 +	local split_space=" $split "
   1.157  	if ! head -n1 $WOK/$pkg/receipt | fgrep -q 'v2'; then
   1.158  		# For receipts v1: $SPLIT may present in the $WANTED package,
   1.159  		# but split packages have their own receipts
   1.160  		echo $PACKAGE
   1.161 -	elif [ "${split/ $PACKAGE /}" != "$split" ]; then
   1.162 +	elif [ "${split_space/ $PACKAGE /}" != "$split_space" ]; then
   1.163  		# $PACKAGE included somewhere in $SPLIT (probably in the end).
   1.164  		# We should build packages in the order defined in the $SPLIT.
   1.165 -		echo $SPLIT
   1.166 +		echo $split
   1.167  	else
   1.168  		# We'll build the $PACKAGE, then all defined in the $SPLIT.
   1.169 -		echo $PACKAGE $SPLIT
   1.170 +		echo $PACKAGE $split
   1.171  	fi
   1.172  }
   1.173  
   1.174 @@ -1335,15 +1362,44 @@
   1.175  }
   1.176  
   1.177  
   1.178 +# Function to use in genpkg_rules() to copy hicolor icons in specified sizes
   1.179 +# (default: 16 and 48) from $install to $fs
   1.180 +
   1.181 +cook_copy_icons() {
   1.182 +	local sizes=$@ i j
   1.183 +	action 'Copying hicolor icons...'
   1.184 +	[ -d "$fs/usr/share/icons/hicolor" ] && rm -rf "$fs/usr/share/icons/hicolor"
   1.185 +	mkdir -p $fs/usr/share/icons/hicolor
   1.186 +	for i in ${sizes:-16 48}; do
   1.187 +		j="${i}x$i"; [ "$i" == 'scalable' ] && j="$i"
   1.188 +		[ ! -e "$install/usr/share/icons/hicolor/$j" ] ||
   1.189 +		scopy   $install/usr/share/icons/hicolor/$j \
   1.190 +			         $fs/usr/share/icons/hicolor
   1.191 +	done
   1.192 +	status
   1.193 +}
   1.194 +
   1.195 +
   1.196  # Common function to copy files, folders and patterns
   1.197  
   1.198  copy() {
   1.199  	action 'Copying folders and files...'
   1.200  	local i j k filelist=$(mktemp) folderlist=$(mktemp)
   1.201 +
   1.202 +	# Get set name for specified package from $SPLIT variable
   1.203 +	local set=$(echo $SPLIT \
   1.204 +				| awk -vpkg="$PACKAGE" '
   1.205 +					BEGIN { RS = " "; FS = ":"; }
   1.206 +					{ if ($1 == pkg) { print "-" $2; exit; } }')
   1.207 +	# Change set, make filelist and folderlist for new set
   1.208 +	export     src="$WOK/$pkg/source/$PACKAGE-$VERSION$set"
   1.209 +	export install="$WOK/$pkg/install$set"
   1.210 +	export DESTDIR="$install"
   1.211  	IFS=$'\n'
   1.212  	cd $install
   1.213  	find ! -type d | sed 's|\.||' > $filelist
   1.214  	find   -type d | sed 's|\.||' > $folderlist
   1.215 +
   1.216  	for i in $@; do
   1.217  		case $i in
   1.218  			@std)
   1.219 @@ -1367,8 +1423,13 @@
   1.220  					' $filelist
   1.221  				;;
   1.222  			@rm)
   1.223 +				# Quick alias
   1.224  				remove_already_packed
   1.225  				;;
   1.226 +			@ico)
   1.227 +				# Quick alias
   1.228 +				cook_copy_icons >/dev/null
   1.229 +				;;
   1.230  			*/)
   1.231  				# Copy specified folders.
   1.232  				i="${i%/}"
   1.233 @@ -1378,8 +1439,9 @@
   1.234  				# Copy specified files.
   1.235  				find ! -type d -path "*/${i#/}" | sed 's|^.||'
   1.236  				;;
   1.237 -		esac | sort -u | \
   1.238 -		while read j; do
   1.239 +		esac \
   1.240 +		| sort -u \
   1.241 +		| while read j; do
   1.242  			mkdir -p $fs$(dirname "$j")
   1.243  			if [ -d "$install$j" ]; then
   1.244  				cp -a "$install$j" $fs$(dirname "$j")
   1.245 @@ -1405,9 +1467,10 @@
   1.246  						[ -z "$k" ] && break
   1.247  						echo "$k"
   1.248  						k="${k%/*}"
   1.249 -					done | tac | \
   1.250 -					# copy dir with its original ownership/permissions if it does not exist
   1.251 -					while read k; do
   1.252 +					done \
   1.253 +					| tac \
   1.254 +					| while read k; do
   1.255 +						# copy dir with its original ownership/permissions if it does not exist
   1.256  						[ -d "$fs$k" ] || cp -a "$install$k" "$fs$k"
   1.257  					done
   1.258  				done < $folderlist
   1.259 @@ -1421,24 +1484,6 @@
   1.260  }
   1.261  
   1.262  
   1.263 -# Function to use in genpkg_rules() to copy hicolor icons in specified sizes
   1.264 -# (default: 16 and 48) from $install to $fs
   1.265 -
   1.266 -cook_copy_icons() {
   1.267 -	local sizes=$@ i j
   1.268 -	action 'Copying hicolor icons...'
   1.269 -	[ -d "$fs/usr/share/icons/hicolor" ] && rm -rf "$fs/usr/share/icons/hicolor"
   1.270 -	mkdir -p $fs/usr/share/icons/hicolor
   1.271 -	for i in ${sizes:-16 48}; do
   1.272 -		j="${i}x$i"; [ "$i" == 'scalable' ] && j="$i"
   1.273 -		[ ! -e "$install/usr/share/icons/hicolor/$j" ] ||
   1.274 -		scopy   $install/usr/share/icons/hicolor/$j \
   1.275 -			         $fs/usr/share/icons/hicolor
   1.276 -	done
   1.277 -	status
   1.278 -}
   1.279 -
   1.280 -
   1.281  # Update packages database every time after successful build
   1.282  
   1.283  update_packages_db() {
     2.1 --- a/doc/receipts-v2.md	Mon Nov 13 02:55:58 2017 +0200
     2.2 +++ b/doc/receipts-v2.md	Fri Nov 17 12:47:48 2017 +0200
     2.3 @@ -135,8 +135,14 @@
     2.4  `/bin/*.sh`|`/usr/bin/gettext.sh`<br>`/usr/bin/httpd_helper.sh`
     2.5  `/lib/*.sh`|`/lib/libtaz.sh`<br>`/usr/lib/slitaz/httphelper.sh`<br>`/usr/lib/slitaz/libpkg.sh`
     2.6  
     2.7 -Also, `copy()` understands the `@rm` pattern. It does not copy anything, but it
     2.8 -removes already copied files that have already been packed.
     2.9 +Additional patterns for the `copy()`:
    2.10 +
    2.11 +  * `@rm`  - quick alias for the `remove_already_packed` function:
    2.12 +    remove from the current package already copied files, that was already
    2.13 +    packed in any of previously packed packages (within current receipt);
    2.14 +  * `@ico` - remove all the copied *hicolor* icons (if any) and copy only 16px
    2.15 +    and 48px variants of *hicolor* icons.
    2.16 +
    2.17  
    2.18  ### Some more examples of using `copy()`
    2.19  
    2.20 @@ -218,3 +224,122 @@
    2.21      esac
    2.22  }
    2.23  ```
    2.24 +
    2.25 +
    2.26 +Compiling sets
    2.27 +--------------
    2.28 +
    2.29 +Sometimes you may need to compile the same source code of the same version,
    2.30 +but with different options. For example, without PAM support and with PAM
    2.31 +support. Or with support for GTK+2 or GTK+3. Or a complete package with all
    2.32 +the rich features and a small limited package. You can not limit yourself
    2.33 +in the number of options.
    2.34 +
    2.35 +Compiling set is a pair of separate `$src` and `$install` folders. You can
    2.36 +still compile the sources using the `$src` variable and install compiled files
    2.37 +into folder defined by `$install` variable, but these values will be different
    2.38 +for the different compiling sets.
    2.39 +
    2.40 +Set defined by the name which is simple mnemonic made up of one or more letters
    2.41 +or numbers. It may be "1", "2", "z", or something more meaningful like "pam",
    2.42 +"gtk2", or "gtk3".
    2.43 +
    2.44 +Also you should know that default set with the empty name is always exists,
    2.45 +for the backward compatibility, and for the cases when you don't want to use
    2.46 +the sets.
    2.47 +
    2.48 +How to use the sets?
    2.49 +
    2.50 +First, you should define which set you want to use for each package, appending
    2.51 +package names in the `$SPLIT` variable. You may not make it for the default set
    2.52 +with empty name. Few examples:
    2.53 +
    2.54 +```bash
    2.55 +PACKAGE="fuse-emulator"
    2.56 +SPLIT="fuse-emulator-gtk3:gtk3"
    2.57 +```
    2.58 +
    2.59 +```bash
    2.60 +PACKAGE="yad"
    2.61 +SPLIT="yad-html:html yad-gtk3:gtk3"
    2.62 +```
    2.63 +
    2.64 +```bash
    2.65 +PACKAGE="urxvt"
    2.66 +SPLIT="urxvt-full:full"
    2.67 +```
    2.68 +
    2.69 +Second, function `compile_rules()` will be executed sequently for default set
    2.70 +and then for all the sets you mention in the `$SPLIT` variable on the previous
    2.71 +step. You should make the business logic inside the `compile_rules()` function
    2.72 +to compile and install different variants based on the value of the `$SET`
    2.73 +variable. This variable has an empty value for the default set, and the set
    2.74 +name in other cases. Few examples how you make the job:
    2.75 +
    2.76 +```bash
    2.77 +PACKAGE="fuse-emulator"
    2.78 +SPLIT="fuse-emulator-gtk3:gtk3"
    2.79 +
    2.80 +compile_rules() {
    2.81 +    SET_ARGS=''; [ -z "$SET" ] && SET_ARGS='--disable-gtk3'
    2.82 +
    2.83 +    ./configure \
    2.84 +        --enable-desktop-integration \
    2.85 +        $SET_ARGS \
    2.86 +        $CONFIGURE_ARGS &&
    2.87 +    make && make install
    2.88 +}
    2.89 +```
    2.90 +
    2.91 +```bash
    2.92 +PACKAGE="urxvt"
    2.93 +SPLIT="urxvt-full:full"
    2.94 +
    2.95 +compile_rules() {
    2.96 +    case $SET in
    2.97 +        '')
    2.98 +            ./configure \
    2.99 +                --disable-everything \
   2.100 +                $CONFIGURE_ARGS &&
   2.101 +            make && make install
   2.102 +            ;;
   2.103 +        full)
   2.104 +            ./configure \
   2.105 +                --enable-everything \
   2.106 +                --enable-256-color \
   2.107 +                --with-terminfo=/usr/share/terminfo \
   2.108 +                $CONFIGURE_ARGS &&
   2.109 +            make && make install || return 1
   2.110 +
   2.111 +            R="$install/usr/share/terminfo"
   2.112 +            mkdir -p $R
   2.113 +            tic -s -o $R $src/doc/etc/rxvt-unicode.terminfo
   2.114 +            ;;
   2.115 +    esac
   2.116 +}
   2.117 +```
   2.118 +
   2.119 +```bash
   2.120 +PACKAGE="yad"
   2.121 +SPLIT="yad-html:html yad-gtk3:gtk3"
   2.122 +
   2.123 +compile_rules() {
   2.124 +    case $SET in
   2.125 +        '')   Gtk=gtk2; Html=disable;;
   2.126 +        html) Gtk=gtk2; Html=enable ;;
   2.127 +        gtk3) Gtk=gtk3; Html=disable;;
   2.128 +    esac
   2.129 +
   2.130 +    ./configure \
   2.131 +        --enable-icon-browser \
   2.132 +        --with-gtk=$Gtk \
   2.133 +        --$Html-html \
   2.134 +        $CONFIGURE_ARGS &&
   2.135 +    make &&
   2.136 +    make install
   2.137 +}
   2.138 +```
   2.139 +
   2.140 +Thirdly, make `genpkg_rules()` as usual. *Cook* will switch to the required
   2.141 +set automatically, based on conformity between packages and sets, that you
   2.142 +described in the `$SPLIT` variable on the first step. That's all.
     3.1 --- a/modules/deps	Mon Nov 13 02:55:58 2017 +0200
     3.2 +++ b/modules/deps	Fri Nov 17 12:47:48 2017 +0200
     3.3 @@ -277,14 +277,20 @@
     3.4  # Return all the names of packages bundled in this receipt
     3.5  
     3.6  all_names() {
     3.7 -	local split=" $SPLIT "
     3.8 -	if [ "${split/ $PACKAGE /}" != "$split" ]; then
     3.9 +	# Get package names from $SPLIT variable
    3.10 +	local split=$(echo $SPLIT \
    3.11 +		| awk '
    3.12 +			BEGIN { RS = " "; FS = ":"; }
    3.13 +			{ print $1; }' \
    3.14 +		| tr '\n' ' ')
    3.15 +	local split_space=" $split "
    3.16 +	if [ "${split_space/ $PACKAGE /}" != "$split_space" ]; then
    3.17  		# $PACKAGE included somewhere in $SPLIT (probably in the end).
    3.18  		# We should build packages in the order defined in the $SPLIT.
    3.19 -		echo $SPLIT
    3.20 +		echo $split
    3.21  	else
    3.22  		# We'll build the $PACKAGE, then all defined in the $SPLIT.
    3.23 -		echo $PACKAGE $SPLIT
    3.24 +		echo $PACKAGE $split
    3.25  	fi
    3.26  }
    3.27