3 # install-mk - install mk files
6 # install-mk [options] [var=val] [dest]
9 # This tool installs mk files in a semi-intelligent manner into
14 # -n just say what we want to do, but don't touch anything.
16 # -f use -f when copying sys,mk.
23 # Use "mode" for installed files (444).
26 # Use "owner" for installed files.
29 # Use "group" for installed files.
32 # Set "var" to "val". See below.
34 # All our *.mk files are copied to "dest" with appropriate
35 # ownership and permissions.
37 # By default if a sys.mk can be found in a standard location
38 # (that bmake will find) then no sys.mk will be put in "dest".
41 # If set, we will avoid installing our 'sys.mk'
42 # This is probably a bad idea.
45 # If set, we will skip making bsd.*.mk links to *.mk
49 # By default (and provided we are not installing to the system
50 # mk dir - '/usr/share/mk') we install our own 'sys.mk' which
51 # includes a sys specific file, or a generic one.
55 # Simon J. Gerraty <sjg@crufty.net>
58 # $Id: install-mk,v 1.222 2022/09/09 17:44:29 sjg Exp $
60 # @(#) Copyright (c) 1994 Simon J. Gerraty
62 # This file is provided in the hope that it will
63 # be of use. There is absolutely NO WARRANTY.
64 # Permission to copy, redistribute or otherwise
65 # use this file is hereby granted provided that
66 # the above copyright notice and this notice are
69 # Please send copies of changes and bug-fixes to:
85 *=*) eval "$1"; shift;;
88 -m) MODE=$2; shift 2;;
89 -o) OWNER=$2; shift 2;;
90 -g) GROUP=$2; shift 2;;
91 -v) ECHO=echo; shift;;
93 -n) ECHO=echo SKIP=:; shift;;
100 0) echo "$0 [options] <destination> [<os>]"
102 echo "$0 -o bin -g bin -m 444 /usr/local/share/mk"
108 osrel=${3:-`uname -r`}
121 echo "WARNING: $@" >&2
124 [ "$FORCE_SYS_MK" ] && Warning "ignoring: FORCE_{BSD,SYS}_MK (no longer supported)"
126 SYS_MK_DIR=${SYS_MK_DIR:-/usr/share/mk}
127 SYS_MK=${SYS_MK:-$SYS_MK_DIR/sys.mk}
130 [ -d $1 ] && cd $1 && 'pwd' && return
134 # some Linux systems have deprecated egrep in favor of grep -E
135 case "`echo bmake | egrep 'a' 2>&1`" in
136 *"grep -E"*) egrep='grep -E';;
140 if [ -s $SYS_MK -a -d $dest ]; then
141 # if this is a BSD system we don't want to touch $SYS_MK
142 dest=`realpath $dest`
143 sys_mk_dir=`realpath $SYS_MK_DIR`
144 if [ $dest = $sys_mk_dir ]; then
150 if [ ! -d $dest/sys -a ! -s $dest/Generic.sys.mk ]; then
151 SKIP_SYS_MK=: # play safe
159 [ -d $dest/sys ] || Do mkdir -p $dest/sys
160 [ -d $dest/sys ] || Do mkdir $dest/sys || exit 1
161 [ -z "$SKIP" ] && dest=`realpath $dest`
165 if [ $mksrc = $dest ]; then
168 # we do not install the examples
169 mk_files=`grep '^[a-z].*\.mk' FILES | $egrep -v '(examples/|^sys\.mk|sys/)'`
170 mk_scripts=`$egrep '^[a-z].*\.(sh|py)' FILES | $egrep -v '/'`
171 sys_mk_files=`grep 'sys/.*\.mk' FILES`
173 [ -z "$SKIP_SYS_MK" ] && mk_files="sys.mk $mk_files"
175 $SKIP_MKFILES Do cp $cp_f $mk_files $dest
176 $SKIP_MKFILES Do cp $cp_f $sys_mk_files $dest/sys
177 $SKIP_MKFILES Do cp $cp_f $mk_scripts $dest
179 $SKIP_MKFILES Do chmod $MODE $mk_files $sys_mk_files
180 $SKIP_MKFILES Do chmod $BINMODE $mk_scripts
181 [ "$GROUP" ] && $SKIP_MKFILES Do chgrp $GROUP $mk_files $sys_mk_files
182 [ "$OWNER" ] && $SKIP_MKFILES Do chown $OWNER $mk_files $sys_mk_files
183 # if this is a BSD system the bsd.*.mk should exist and be used.
184 if [ -z "$SKIP_BSD_MK" ]; then
185 for f in dep doc files inc init lib links man nls obj own prog subdir
188 [ -s $b ] || Do ln -s $f.mk $b