Remove building with NOCRYPTO option
[minix.git] / distrib / sets / sets.subr
bloba691141c9044d5281755c3c6f2f7175fcec3fed5
1 #       $NetBSD: sets.subr,v 1.173 2015/07/23 08:03:25 mrg Exp $
5 # The following variables contain defaults for sets.subr functions and callers:
6 #       setsdir                 path to src/distrib/sets
7 #       nlists                  list of base sets
8 #       xlists                  list of x11 sets
9 #       extlists                list of extsrc sets
10 #       obsolete                controls if obsolete files are selected instead
11 #       module                  if != "no", enable MODULE sets
12 #       shlib                   shared library format (a.out, elf, or "")
13 #       stlib                   static library format (a.out, elf)
15 # The following <bsd.own.mk> variables are exported to the environment:
16 #       MACHINE 
17 #       MACHINE_ARCH
18 #       MACHINE_CPU
19 #       HAVE_BINUTILS
20 #       HAVE_GCC
21 #       HAVE_GDB
22 #       HAVE_SSP
23 #       TOOLCHAIN_MISSING
24 #       OBJECT_FMT
25 # as well as:
29 # The following variables refer to tools that are used when building sets:
31 : ${AWK:=awk}
32 : ${CKSUM:=cksum}
33 : ${COMM:=comm}
34 : ${DATE:=date}
35 : ${DB:=db}
36 : ${EGREP:=egrep}
37 : ${ENV_CMD:=env}       # ${ENV} is special to sh(1), ksh(1), etc.
38 : ${FGREP:=fgrep}
39 : ${FIND:=find}
40 : ${GREP:=grep}
41 : ${GZIP_CMD:=gzip}     # ${GZIP} is special to gzip(1)
42 : ${HOSTNAME_CMD:=hostname}     # ${HOSTNAME} is special to bash(1)
43 : ${HOST_SH:=sh}
44 : ${IDENT:=ident}
45 : ${JOIN:=join}
46 : ${LS:=ls}
47 : ${MAKE:=make}
48 : ${MKTEMP:=mktemp}
49 : ${MTREE:=mtree}
50 : ${PASTE:=paste}
51 : ${PAX:=pax}
52 : ${PRINTF:=printf}
53 : ${SED:=sed}
54 : ${SORT:=sort}
55 : ${STAT:=stat}
56 : ${TSORT:=tsort}
57 : ${UNAME:=uname}
58 : ${WC:=wc}
59 : ${XARGS:=xargs}
62 # If printf is a shell builtin command, then we can
63 # implement cheaper versions of basename and dirname
64 # that do not involve any fork/exec overhead.
65 # If printf is not builtin, approximate it using echo,
66 # and hope there are no weird file names that cause
67 # some versions of echo to do the wrong thing.
68 # (Converting to this version of dirname speeded up the
69 # syspkgdeps script by an order of magnitude, from 68
70 # seconds to 6.3 seconds on one particular host.)
72 # Note that naive approximations for dirname
73 # using ${foo%/*} do not do the right thing in cases
74 # where the result should be "/" or ".".
76 case "$(type printf)" in
77 *builtin*)
78         basename ()
79         {
80                 local bn
81                 bn="${1##*/}"
82                 bn="${bn%$2}"
83                 printf "%s\n" "$bn"
84         }
85         dirname ()
86         {
87                 local dn
88                 case "$1" in
89                 ?*/*)   dn="${1%/*}" ;;
90                 /*)     dn=/ ;;
91                 *)      dn=. ;;
92                 esac
93                 printf "%s\n" "$dn"
94         }
95         ;;
97         basename ()
98         {
99                 local bn
100                 bn="${1##*/}"
101                 bn="${bn%$2}"
102                 echo "$bn"
103         }
104         dirname ()
105         {
106                 local dn
107                 case "$1" in
108                 ?*/*)   dn="${1%/*}" ;;
109                 /*)     dn=/ ;;
110                 *)      dn=. ;;
111                 esac
112                 echo "$dn"
113         }
114         ;;
115 esac
117 #####
119 oIFS=$IFS
120 IFS="
123 for x in $( ${MAKE} -B -f ${rundir}/mkvars.mk mkvars ); do
124         eval export $x
125 done
127 IFS=$oIFS
129 MKVARS="$( ${MAKE} -B -f ${rundir}/mkvars.mk mkvars | ${SED} -e 's,=.*,,' | ${XARGS} )"
131 #####
133 setsdir=${rundir}
134 obsolete=0
135 if [ "${MKKMOD}" = "no" ]; then
136         module=no                       # MODULEs are off.
137         modset=""
138 else
139         module=yes
140         modset="modules"
142 if [ "${MKATF}" = "no" ]; then
143         testset=""
144 else
145         testset="tests minix-tests"
147 if [ "${MKDEBUG}" = "no" -a "${MKDEBUGLIB}" = "no" ]; then
148         debugset=""
149         xdebugset=""
150 else
151         debugset="minix-debug"
152         xdebugset="xdebug"
154 # Determine lib type. Do this first so stlib also gets set.
155 if [ "${OBJECT_FMT}" = "ELF" ]; then
156         shlib=elf
157 else
158         shlib=aout
160 stlib=$shlib
161 # Now check for MKPIC or specials and turn off shlib if need be.
162 if [ "${MKPIC}" = "no" ]; then
163         shlib=no
165 # LSC for Minix
166 nlists="minix-base minix-comp minix-games minix-kernel minix-man $testset $debugset"
167 #nlists="base comp $debugset etc games man misc $modset $testset text"
168 xlists="xbase xcomp $xdebugset xetc xfont xserver"
169 extlists="extbase extcomp extetc"
171 OSRELEASE=$(${HOST_SH} ${NETBSDSRCDIR}/sys/conf/osrelease.sh -k)
172 MODULEDIR="stand/${MACHINE}/${OSRELEASE}/modules"
173 SUBST="s#@MODULEDIR@#${MODULEDIR}#g"
174 SUBST="${SUBST};s#@OSRELEASE@#${OSRELEASE}#g"
175 SUBST="${SUBST};s#@MACHINE@#${MACHINE}#g"
178 # list_set_files setfile [...]
180 # Produce a packing list for setfile(s).
181 # In each file, a record consists of a path and a System Package name,
182 # separated by whitespace. E.g.,
184 #       # $NetBSD: sets.subr,v 1.173 2015/07/23 08:03:25 mrg Exp $
185 #       .                       base-sys-root   [keyword[,...]]
186 #       ./altroot               base-sys-root
187 #       ./bin                   base-sys-root
188 #       ./bin/[                 base-util-root
189 #       ./bin/cat               base-util-root
190 #               [...]
192 # A # in the first column marks a comment.
194 # If ${obsolete} != 0, only entries with an "obsolete" keyword will
195 # be printed.  All other keywords must be present.
197 # The third field is an optional comma separated list of keywords to
198 # control if a record is printed; every keyword listed must be enabled
199 # for the record to be printed.  The following keywords are available:
200 #       dummy                   dummy entry (ignored)
201 #       obsolete                file is obsolete, and only printed if 
202 #                               ${obsolete} != 0
204 #       atf                     ${MKATF} != no
205 #       bfd                     obsolete, use binutils.
206 #       binutils                ${MKBINUTILS} != no
207 #       bsdgrep                 ${MKBSDGREP} != no
208 #       catpages                ${MKCATPAGES} != no
209 #       compat                  ${MKCOMPAT} != no
210 #       compatmodules           ${MKCOMPATMODULES} != no
211 #       compattests             ${MKCOMPATTESTS} != no
212 #       crypto                  ${MKCRYPTO} != no
213 #       crypto_rc5              ${MKCRYPTO_RC5} != no
214 #       cvs                     ${MKCVS} != no
215 #       debug                   ${MKDEBUG} != no
216 #       debuglib                ${MKDEBUGLIB} != no
217 #       doc                     ${MKDOC} != no
218 #       dtrace                  ${MKDTRACE} != no
219 #       dynamicroot             ${MKDYNAMICROOT} != no
220 #       extsrc                  ${MKEXTSRC} != no
221 #       gcc                     ${MKGCC} != no
222 #       gcccmds                 ${MKGCCCMDS} != no
223 #       gdb                     ${MKGDB} != no
224 #       hesiod                  ${MKHESIOD} != no
225 #       html                    ${MKHTML} != no
226 #       inet6                   ${MKINET6} != no
227 #       info                    ${MKINFO} != no
228 #       ipfilter                ${MKIPFILTER} != no
229 #       iscsi                   ${MKISCSI} != no
230 #       kerberos                ${MKKERBEROS} != no
231 #       kmod                    ${MKKMOD} != no
232 #       kyua                    ${MKKYUA} != no
233 #       ldap                    ${MKLDAP} != no
234 #       lint                    ${MKLINT} != no
235 #       libcxx                  ${MKLIBCXX} != no
236 #       libgcc_eh               ${HAVE_LIBGCC_EH} != no
237 #       libstdcxx               ${MKLIBSTDCXX} != no
238 #       lld                     ${MKLLD} != no
239 #       lldb                    ${MKLLDB} != no
240 #       llvm                    ${MKLLVM} != no
241 #       lvm                     ${MKLVM} != no
242 #       makemandb               ${MKMAKEMANDB} != no
243 #       man                     ${MKMAN} != no
244 #       manpages                ${MKMANPAGES} != no
245 #       manz                    ${MKMANZ} != no
246 #       mclinker                ${MKMCLINKER} != no
247 #       mdns                    ${MKMDNS} != no
248 #       nls                     ${MKNLS} != no
249 #       nvi                     ${MKNVI} != no
250 #       pam                     ${MKPAM} != no
251 #       pcc                     ${MKPCC} != no
252 #       pf                      ${MKPF} != no
253 #       pic                     ${MKPIC} != no
254 #       picinstall              ${MKPICINSTALL} != no
255 #       pigzgzip                ${MKPIGZGZIP} != no
256 #       postfix                 ${MKPOSTFIX} != no
257 #       profile                 ${MKPROFILE} != no
258 #       perfuse                 ${MKPERFUSE} != no
259 #       rump                    ${MKRUMP} != no
260 #       share                   ${MKSHARE} != no
261 #       skey                    ${MKSKEY} != no
262 #       sljit                   ${MKSLJIT} != no
263 #       softfloat               ${MKSOFTFLOAT} != no
264 #       solaris                 ${MKDTRACE} != no or ${MKZFS} != no
265 #       ssp                     ${HAVE_SSP} != no
266 #       tpm                     ${MKTPM} != no
267 #       xorg                    ${MKX11} != no
268 #       xorg_server             ${MKXORG_SERVER} != no
269 #       yp                      ${MKYP} != no
270 #       zfs                     ${MKZFS} != no
272 #       endian=<n>              <n> = value of ${TARGET_ENDIANNESS}
273 #       binutils=<n>            <n> = value of ${HAVE_BINUTILS}
274 #       gcc=<n>                 <n> = value of ${HAVE_GCC}
275 #       gdb=<n>                 <n> = value of ${HAVE_GDB}
277 #       use_inet6               ${USE_INET6} != no
278 #       use_kerberos            ${USE_KERBEROS} != no
279 #       use_yp                  ${USE_YP} != no
281 #       .cat                    if ${MKMANZ} != "no" && ${MKCATPAGES} != "no"
282 #                                 automatically append ".gz" to the filename
284 #       .man                    if ${MKMANZ} != "no" && ${MKMAN} != "no"
285 #                                 automatically append ".gz" to the filename
287 list_set_files()
289         if [ ${MAKEVERBOSE:-2} -lt 3 ]; then
290                 verbose=false
291         else
292                 verbose=true
293         fi
294         print_set_lists "$@" | \
295         ${AWK} -v obsolete=${obsolete} '
296                 BEGIN {
297                         if (obsolete)
298                                 wanted["obsolete"] = 1
299                 
300                         split("'"${MKVARS}"'", needvars)
301                         doingcompat = 0
302                         doingcompattests = 0
303                         ignoredkeywords["compatdir"] = 1
304                         ignoredkeywords["compatfile"] = 1
305                         ignoredkeywords["compattestdir"] = 1
306                         ignoredkeywords["compattestfile"] = 1
307                         ignoredkeywords["compatx11dir"] = 1
308                         ignoredkeywords["compatx11file"] = 1
309                         for (vi in needvars) {
310                                 nv = needvars[vi]
311                                 kw = tolower(nv)
312                                 sub(/^mk/, "", kw)
313                                 sub(/^have_/, "", kw)
314                                 sub(/^target_endianness/, "endian", kw)
315                                 if (nv != "HAVE_GCC" && nv != "HAVE_GDB" && ENVIRON[nv] != "no" && nv != "COMPATARCHDIRS" && nv != "KMODARCHDIRS") {
316                                         wanted[kw] = 1 
317                                 }
318                         }
320                         if ("compat" in wanted) {
321                                 doingcompat = 1;
322                                 split("'"${COMPATARCHDIRS}"'", compatarchdirs, ",");
323                                 compatdirkeywords["compatdir"] = 1
324                                 compatfilekeywords["compatfile"] = 1
326                                 if (wanted["compattests"]) {
327                                         doingcompattests = 1;
328                                         compatdirkeywords["compattestdir"] = 1
329                                         compatfilekeywords["compattestfile"] = 1
330                                 }
331                                 if (wanted["compatx11"]) {
332                                         doingcompatx11 = 1;
333                                         compatdirkeywords["compatx11dir"] = 1
334                                         compatfilekeywords["compatx11file"] = 1
335                                 }
336                         }
338                         if (("kmod" in wanted) && ("compatmodules" in wanted)) {
339                                 split("'"${KMODARCHDIRS}"'", kmodarchdirs, ",");
340                                 kmodpat = "./stand/" ENVIRON["MACHINE"]
341                                 l_kmodpat = length(kmodpat)
342                         }
344                         if ("'"${TOOLCHAIN_MISSING}"'" != "yes") {
345                                 if ("binutils" in wanted)
346                                         wanted["binutils=" "'"${HAVE_BINUTILS}"'"] = 1
347                                 if ("gcc" in wanted)
348                                         wanted["gcc=" "'"${HAVE_GCC}"'"] = 1
349                                 if ("gdb" in wanted)
350                                         wanted["gdb=" "'"${HAVE_GDB}"'"] = 1
351                         }
352                         if (("man" in wanted) && ("catpages" in wanted))
353                                 wanted[".cat"] = 1
354                         if (("man" in wanted) && ("manpages" in wanted))
355                                 wanted[".man"] = 1
356                         if ("endian" in wanted)
357                                 wanted["endian=" "'"${TARGET_ENDIANNESS}"'"] = 1
358                         if ("machine" in wanted)
359                                 wanted["machine=" "'"${MACHINE}"'"] = 1
360                         if ("machine_arch" in wanted)
361                                 wanted["machine_arch=" "'"${MACHINE_ARCH}"'"] = 1
362                         if ("machine_cpu" in wanted)
363                                 wanted["machine_cpu=" "'"${MACHINE_CPU}"'"] = 1
364                 }
366                 /^#/ {
367                         next;
368                 }
370                 /^-/ {
371                         notwanted[substr($1, 2)] = 1;
372                         delete list [substr($1, 2)];
373                         next;
374                 }
375                                 
377                 NF > 2 && $3 != "-" {
378                         if (notwanted[$1] != "")
379                                 next;
380                         split($3, keywords, ",")
381                         show = 1
382                         haveobs = 0
383                         iscompatfile = 0
384                         havekmod = 0
385                         iscompatdir = 0
386                         for (ki in keywords) {
387                                 kw = keywords[ki]
388                                 if (("manz" in wanted) &&
389                                     (kw == ".cat" || kw == ".man"))
390                                         $1 = $1 ".gz"
391                                 if (substr(kw, 1, 1) == "!") {
392                                         kw = substr(kw, 2)
393                                         if (kw in wanted)
394                                                 show = 0
395                                 } else if (kw in compatdirkeywords) {
396                                         iscompatdir = 1
397                                 } else if (kw in compatfilekeywords) {
398                                         iscompatfile = 1
399                                 } else if (kw == "nocompatmodules") {
400                                         havekmod = -1
401                                 } else if (kw in ignoredkeywords) {
402                                         # ignore
403                                 } else if (! (kw in wanted)) {
404                                         show = 0
405                                 } else if (kw == "kmod" && havekmod == 0) {
406                                         havekmod = 1
407                                 }
408                                 if (kw == "obsolete")
409                                         haveobs = 1
410                         }
411                         if (obsolete && ! haveobs)
412                                 next
413                         if (!show)
414                                 next
416                         list[$1] = $0
417                         if (havekmod > 0 && substr($1,1,l_kmodpat) == kmodpat) {
418                                 for (d in kmodarchdirs) {
419                                         xd = "./stand/" kmodarchdirs[d]
420                                         xfile = xd substr($1, l_kmodpat+1)
421                                         tmp = xd substr($0, l_kmodpat+1)
422                                         list[xfile] = tmp;
423                                 }
424                                 next
425                         }
427                         if (!doingcompat || !(iscompatfile || iscompatdir))
428                                 next
430                         if (iscompatfile) {
431                                 emitcompat[$1] = 1;
432                                 next
433                         }
434                         for (d in cpaths) {
435                                 if (cpaths[d] == $1 "/")
436                                         next
437                         }
438                         cpaths[ncpaths++] = $1 "/"
439                         for (d in compatarchdirs) {
440                                 tmp = $0
441                                 xfile = $1 "/" compatarchdirs[d]
442                                 tmp = xfile substr(tmp, length($1) + 1)
443                                 if (xfile in notwanted)
444                                         continue;
445                                 sub("compatdir","compat",tmp);
446                                 sub("compattestdir","compat",tmp);
447                                 list[xfile] = tmp
448                         }
449                         next
450                 }
452                 {
453                         if ($1 in notwanted)
454                                 next;
455                         if (! obsolete)
456                                 list[$1] = $0
457                 }
459                 END {
460                         for (i in list) {
461                                 print list[i]
462                                 if (! (i in emitcompat))
463                                         continue;
464                                 l_i = length(i)
465                                 l = 0
466                                 for (j in cpaths) {
467                                         lx = length(cpaths[j])
468                                         if (lx >= l_i || cpaths[j] != substr(i, 1, lx)) {
469                                                 continue;
470                                         }
471                                         if (lx > l) {
472                                                 l = lx;
473                                                 cpath = cpaths[j];
474                                         }
475                                 }
476                                 for (d in compatarchdirs) {
477                                         tmp = list[i]
478                                         extrapath = compatarchdirs[d] "/"
479                                         xfile = cpath extrapath substr(i, l + 1)
480                                         if (xfile in notwanted)
481                                                 continue;
482                                         sub("compatfile","compat",tmp);
483                                         sub("compattestfile","compat",tmp);
484                                         tmp = xfile substr(tmp, l_i + 1)
485                                         print tmp;
486                                 }
487                         }
488                 }'
493 # list_set_lists setname
495 # Print to stdout a list of files, one filename per line, which
496 # concatenate to create the packing list for setname. E.g.,
498 #       .../lists/base/mi
499 #       .../lists/base/rescue.mi
500 #       .../lists/base/md.i386
501 #               [...]
503 # For a given setname $set, the following files may be selected from
504 # .../list/$set:
505 #       mi
506 #       mi.ext.*
507 #       ad.${MACHINE_ARCH}
508 # (or)  ad.${MACHINE_CPU}
509 #       ad.${MACHINE_CPU}.shl
510 #       md.${MACHINE}.${MACHINE_ARCH}
511 # (or)  md.${MACHINE}
512 #       stl.mi
513 #       stl.${stlib}
514 #       shl.mi
515 #       shl.mi.ext.*
516 #       shl.${shlib}
517 #       shl.${shlib}.ext.*
518 #       module.mi                       if ${module} != no
519 #       module.${MACHINE}               if ${module} != no
520 #       module.ad.${MACHINE_ARCH}       if ${module} != no
521 # (or)  module.ad.${MACHINE_CPU}        if ${module} != no
522 #       rescue.shl
523 #       rescue.${MACHINE}
524 #       rescue.ad.${MACHINE_ARCH}
525 # (or)  rescue.ad.${MACHINE_CPU}
526 #       rescue.ad.${MACHINE_CPU}.shl
528 # Environment:
529 #       shlib
530 #       stlib
532 list_set_lists()
534         setname=$1
536         list_set_lists_mi $setname
537         list_set_lists_ad $setname
538         list_set_lists_md $setname
539         list_set_lists_stl $setname
540         list_set_lists_shl $setname
541         list_set_lists_module $setname
542         list_set_lists_rescue $setname
543         return 0
546 list_set_lists_mi()
548         setdir=$setsdir/lists/$1
549         # always exist!
550         echo $setdir/mi
553 list_set_lists_ad()
555         setdir=$setsdir/lists/$1
556         [ "${MACHINE}" != "${MACHINE_ARCH}" ] && \
557         list_set_lists_common_ad $1
560 list_set_lists_md()
562         setdir=$setsdir/lists/$1
563         echo_if_exist $setdir/md.${MACHINE}.${MACHINE_ARCH} || \
564         echo_if_exist $setdir/md.${MACHINE}
567 list_set_lists_stl()
569         setdir=$setsdir/lists/$1
570         echo_if_exist $setdir/stl.mi
571         echo_if_exist $setdir/stl.${stlib}
574 list_set_lists_shl()
576         setdir=$setsdir/lists/$1
577         [ "$shlib" != "no" ] || return
578         echo_if_exist $setdir/shl.mi
579         echo_if_exist $setdir/shl.${shlib}
582 list_set_lists_module()
584         setdir=$setsdir/lists/$1
585         [ "$module" != "no" ] || return
586         echo_if_exist $setdir/module.mi
587         echo_if_exist $setdir/module.${MACHINE}
588         # XXX module never has .shl
589         [ "${MACHINE}" != "${MACHINE_ARCH}" ] && \
590         list_set_lists_common_ad $1 module
593 list_set_lists_rescue()
595         setdir=$setsdir/lists/$1
596         echo_if_exist $setdir/rescue.mi
597         echo_if_exist $setdir/rescue.${MACHINE}
598         [ "${MACHINE}" != "${MACHINE_ARCH}" ] && \
599         list_set_lists_common_ad $1 rescue
602 list_set_lists_common_ad()
604         setdir=$setsdir/lists/$1; _prefix=$2
606         [ -n "$_prefix" ] && prefix="$_prefix".
608         # Prefer a <prefix>.ad.${MACHINE_ARCH} over a
609         # <prefix>.ad.${MACHINE_CPU}, since the arch-
610         # specific one will be more specific than the
611         # cpu-specific one.
612         echo_if_exist $setdir/${prefix}ad.${MACHINE_ARCH} || \
613         echo_if_exist $setdir/${prefix}ad.${MACHINE_CPU}
614         [ "$shlib" != "no" ] && \
615         echo_if_exist $setdir/${prefix}ad.${MACHINE_CPU}.shl
618 echo_if_exist()
620         [ -f $1 ] && echo $1
621         return $?
624 echo_if_exist_foreach()
626         local _list=$1; shift
627         for _suffix in $@; do
628                 echo_if_exist ${_list}.${_suffix}
629         done
632 print_set_lists()
634         for setname; do
635                 list=$(list_set_lists $setname)
636                 for l in $list; do
637                         echo $l
638                         if $verbose; then
639                                 echo >&2 "DEBUG: list_set_files: $l"
640                         fi
641                 done
642         done | ${XARGS} ${SED} ${SUBST}
645 # arch_to_cpu mach
647 # Print the ${MACHINE_CPU} for ${MACHINE_ARCH}=mach,
648 # as determined by <bsd.own.mk>.
650 arch_to_cpu()
652         MACHINE_ARCH=${1} ${MAKE} -B -f- all <<EOMAKE
653 .include <bsd.own.mk>
654 all:
655         @echo \${MACHINE_CPU}
656 EOMAKE
659 # arch_to_endian mach
661 # Print the ${TARGET_ENDIANNESS} for ${MACHINE_ARCH}=mach,
662 # as determined by <bsd.endian.mk>.
664 arch_to_endian()
666         MACHINE_ARCH=${1} ${MAKE} -B -f- all <<EOMAKE
667 .include <bsd.endian.mk>
668 all:
669         @echo \${TARGET_ENDIANNESS}
670 EOMAKE
673 #####
675 # print_mkvars
676 print_mkvars()
678         for v in $MKVARS; do
679                 eval echo $v=\$$v
680         done
683 # print_set_lists_{base,x,ext}
684 # list_set_lists_{base,x,ext}
685 # list_set_files_{base,x,ext}
686 for func in print_set_lists list_set_lists list_set_files; do
687         for x in base x ext; do
688                 if [ $x = base ]; then
689                         list=nlists
690                 else
691                         list=${x}lists
692                 fi
693                 eval ${func}_${x} \(\) \{ $func \$$list \; \}
694         done
695 done