1: 2# NAME: 3# install-mk - install mk files 4# 5# SYNOPSIS: 6# install-mk [options] [var=val] [dest] 7# 8# DESCRIPTION: 9# This tool installs mk files in a semi-intelligent manner into 10# "dest". 11# 12# Options: 13# 14# -n just say what we want to do, but don't touch anything. 15# 16# -f use -f when copying sys,mk. 17# 18# -v be verbose 19# 20# -q be quiet 21# 22# -m "mode" 23# Use "mode" for installed files (444). 24# 25# -o "owner" 26# Use "owner" for installed files. 27# 28# -g "group" 29# Use "group" for installed files. 30# 31# -U "umask" 32# Use "umask" so directories are created with suitable 33# mode (default is 022). 34# 35# var=val 36# Set "var" to "val". See below. 37# 38# All our *.mk files are copied to "dest" with appropriate 39# ownership and permissions. 40# 41# By default if a sys.mk can be found in a standard location 42# (that bmake will find) then no sys.mk will be put in "dest". 43# 44# SKIP_SYS_MK: 45# If set, we will avoid installing our 'sys.mk' 46# This is probably a bad idea. 47# 48# SKIP_BSD_MK: 49# If set, we will skip making bsd.*.mk links to *.mk 50# 51# sys.mk: 52# 53# By default (and provided we are not installing to the system 54# mk dir - '/usr/share/mk') we install our own 'sys.mk' which 55# includes a sys specific file, or a generic one. 56# 57# 58# AUTHOR: 59# Simon J. Gerraty <sjg@crufty.net> 60 61# RCSid: 62# $Id: install-mk,v 1.271 2025/11/11 18:08:02 sjg Exp $ 63# 64# @(#) Copyright (c) 1994-2025 Simon J. Gerraty 65# 66# SPDX-License-Identifier: BSD-2-Clause 67# 68# Please send copies of changes and bug-fixes to: 69# sjg@crufty.net 70# 71 72MK_VERSION=20251111 73OWNER= 74GROUP= 75MODE=444 76BINMODE=555 77ECHO=: 78SKIP= 79cp_f=-f 80 81umask 022 82 83while : 84do 85 case "$1" in 86 *=*) eval "$1"; shift;; 87 +f) cp_f=; shift;; 88 -f) cp_f=-f; shift;; 89 -m) MODE=$2; shift 2;; 90 -o) OWNER=$2; shift 2;; 91 -g) GROUP=$2; shift 2;; 92 -v) ECHO=echo; shift;; 93 -q) ECHO=:; shift;; 94 -n) ECHO=echo SKIP=:; shift;; 95 -U) umask $2; shift;; 96 --) shift; break;; 97 *) break;; 98 esac 99done 100 101case $# in 1020) echo "$0 [options] <destination> [<os>]" 103 echo "eg." 104 echo "$0 -o bin -g bin -m 444 /usr/local/share/mk" 105 exit 1 106 ;; 107esac 108dest=$1 109os=${2:-`uname`} 110osrel=${3:-`uname -r`} 111 112Do() { 113 $ECHO "$@" 114 $SKIP "$@" 115} 116 117Error() { 118 echo "ERROR: $@" >&2 119 exit 1 120} 121 122Warning() { 123 echo "WARNING: $@" >&2 124} 125 126[ "$FORCE_SYS_MK" ] && Warning "ignoring: FORCE_{BSD,SYS}_MK (no longer supported)" 127 128SYS_MK_DIR=${SYS_MK_DIR:-/usr/share/mk} 129SYS_MK=${SYS_MK:-$SYS_MK_DIR/sys.mk} 130 131realpath() { 132 [ -d $1 ] && cd $1 && 'pwd' && return 133 echo $1 134} 135 136# some Linux systems have deprecated egrep in favor of grep -E 137case "`echo bmake | egrep 'a' 2>&1`" in 138*"grep -E"*) egrep='grep -E';; 139*) egrep=egrep;; 140esac 141 142if [ -s $SYS_MK -a -d $dest ]; then 143 # if this is a BSD system we don't want to touch $SYS_MK 144 dest=`realpath $dest` 145 sys_mk_dir=`realpath $SYS_MK_DIR` 146 if [ $dest = $sys_mk_dir ]; then 147 case "$os" in 148 *BSD*) SKIP_SYS_MK=: 149 SKIP_BSD_MK=: 150 ;; 151 *) # could be fake? 152 if [ ! -d $dest/sys -a ! -s $dest/Generic.sys.mk ]; then 153 SKIP_SYS_MK=: # play safe 154 SKIP_BSD_MK=: 155 fi 156 ;; 157 esac 158 fi 159fi 160 161[ -d $dest/sys ] || Do mkdir -p $dest/sys 162[ -d $dest/sys ] || Do mkdir $dest/sys || exit 1 163[ -z "$SKIP" ] && dest=`realpath $dest` 164 165cd `dirname $0` 166mksrc=`'pwd'` 167if [ $mksrc = $dest ]; then 168 SKIP_MKFILES=: 169else 170 # we do not install the examples 171 mk_files=`grep '^[a-z].*\.mk' FILES | $egrep -v '(examples/|^sys\.mk|sys/)'` 172 mk_scripts=`$egrep '^[a-z].*[.-](sh|py)' FILES | $egrep -v '/'` 173 sys_mk_files=`grep 'sys/.*\.mk' FILES` 174 SKIP_MKFILES= 175 [ -z "$SKIP_SYS_MK" ] && mk_files="sys.mk $mk_files" 176fi 177$SKIP_MKFILES Do cp $cp_f $mk_files $dest 178$SKIP_MKFILES Do cp $cp_f $sys_mk_files $dest/sys 179$SKIP_MKFILES Do cp $cp_f $mk_scripts $dest 180$SKIP cd $dest 181$SKIP_MKFILES Do chmod $MODE $mk_files $sys_mk_files 182$SKIP_MKFILES Do chmod $BINMODE $mk_scripts 183[ "$GROUP" ] && $SKIP_MKFILES Do chgrp $GROUP $mk_files $sys_mk_files 184[ "$OWNER" ] && $SKIP_MKFILES Do chown $OWNER $mk_files $sys_mk_files 185# if this is a BSD system the bsd.*.mk should exist and be used. 186if [ -z "$SKIP_BSD_MK" ]; then 187 for f in dep doc files inc init lib links man nls obj own prog subdir 188 do 189 b=bsd.$f.mk 190 [ -s $b ] || Do ln -s $f.mk $b 191 done 192fi 193exit 0 194