pthbs

Packaging Through Hashed Build Scripts
git clone https://ccx.te2000.cz/git/pthbs
Log | Files | Refs | Submodules | README

getent (2515B)


      1 #!/usr/bin/env pthbs-build
      2 #+musl-cross-make.65f98305f5666435bf0c6b9ccedffae2179ff1b3286752756886f760cf7771d2
      3 #+gnu-make.782c9e6625fd7420e2cd38b847afed19db3b3844cae8a0426a0dbf73e10d78e5
      4 #+busybox.e60885fe93ee85c01831673bb29f0e62a64903f4ce3094e3dc35bc8ec8887ad9
      5 #@sha256:002c1a216f6bed0f816ab1cfebde94a0b127193ef410c36b2190599983e015b8:getent.c
      6 
      7 name=getent
      8 check_static() {
      9 	local exe || true
     10 	exe=$pthbs_destdir/'/versions'/$pthbs_package/$1
     11 	if ! test -f $exe; then
     12 		printf '%s\n' "Error: file '$1' doesn't exist!"
     13 		exit 1
     14 	fi
     15 	interp_info=$(readelf --string-dump=.interp "$exe") || exit $?
     16 	if test x '!=' "x$interp_info"; then
     17 		printf '%s\n' "Error: '$1' is a dynamic binary!"
     18 		exit 1
     19 	fi
     20 }
     21 build_env_static() {
     22 	export LD_LIBRARY_PATH="$pthbs_build_environment/library"
     23 	export CPATH="$pthbs_build_environment/include"
     24 	export LDFLAGS="-static -L$pthbs_build_environment/library $LDFLAGS"
     25 }
     26 def_prefix() {
     27 	prefix=/versions/$pthbs_package
     28 }
     29 def_dest() {
     30 	dest=${pthbs_destdir%/}//versions/$pthbs_package
     31 }
     32 build_env_static
     33 def_prefix
     34 
     35 gcc -static -o $name $name.c
     36 
     37 install -d "$pthbs_destdir/$prefix/command"
     38 install -m 755 $name "$pthbs_destdir/$prefix/command"
     39 check_static command/$name
     40 
     41 cd "$pthbs_destdir/versions/$pthbs_package"
     42 find -type d -o -print | awk -F/ '
     43 BEGIN {
     44 	x["./command/getent"]=1}
     45 
     46 function r1(s) {
     47 	sub("^[.]/[^/]*", ".", s)
     48 	return s
     49 }
     50 function s1(repl, s) {
     51 	sub("^[.]/[^/]*", "./"repl, s)
     52 	return s
     53 }
     54 function link(src) {
     55 	x[$0]=0
     56 	printf "%s\t%s\n", $0, src
     57 	printf "genlinks >>%s\t%s<<\n", $0, src >>"/dev/stderr"
     58 }
     59 $1!="."{exit 1}
     60 
     61 
     62 $2 == "command" { link($0); next }
     63 $2 == "bin" { link(s1("command", $0)); next }
     64 
     65 $2 == "library.so" { link($0); next }
     66 $2 == "library" { link($0); next }
     67 $2 == "lib" && $NF ~ /\.l?a$/ { link(s1("library", $0)); next }
     68 $2 == "lib" && $NF ~ /\.so(|\..*)$/ { link(s1("library.so", $0)); next }
     69 
     70 $2 == "share" && $3 ~ /^(info|man|doc|icons|terminfo)$/ { link(r1($0)); next }
     71 
     72 $2 == "man" { link($0); next }
     73 $2 == "info" { link($0); next }
     74 $2 == "doc" { link($0); next }
     75 $2 == "icons" { link($0); next }
     76 $2 == "terminfo" { link($0); next }
     77 $2 == "data" { link($0); next }
     78 $2 == "include" { link($0); next }
     79 
     80 { printf "genlinks ##%s## skipped\n", $0 >>"/dev/stderr" }
     81 
     82 END {
     83 	for(fname in x) { printf "DEBUG: x[\"%s\"]=\"%s\"\n", fname, x[fname] >"/dev/stderr" }
     84 	for(fname in x) {
     85 		if(x[fname]) {
     86 			printf "ERROR: missing expected file \"%s\"\n", fname >"/dev/stderr"
     87 			exit 3
     88 		}
     89 	}
     90 }' >.install-links.new
     91 mv .install-links.new .install-links