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# var=val 32# Set "var" to "val". See below. 33# 34# All our *.mk files are copied to "dest" with appropriate 35# ownership and permissions. 36# 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". 39# 40# SKIP_SYS_MK: 41# If set, we will avoid installing our 'sys.mk' 42# This is probably a bad idea. 43# 44# SKIP_BSD_MK: 45# If set, we will skip making bsd.*.mk links to *.mk 46# 47# sys.mk: 48# 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. 52# 53# 54# AUTHOR: 55# Simon J. Gerraty <sjg@crufty.net> 56 57# RCSid: 58# $Id: install-mk,v 1.224 2023/01/20 17:34:06 sjg Exp $ 59# 60# @(#) Copyright (c) 1994 Simon J. Gerraty 61# 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 67# left intact. 68# 69# Please send copies of changes and bug-fixes to: 70# sjg@crufty.net 71# 72 73MK_VERSION=20230120 74OWNER= 75GROUP= 76MODE=444 77BINMODE=555 78ECHO=: 79SKIP= 80cp_f=-f 81 82while : 83do 84 case "$1" in 85 *=*) eval "$1"; shift;; 86 +f) cp_f=; shift;; 87 -f) cp_f=-f; shift;; 88 -m) MODE=$2; shift 2;; 89 -o) OWNER=$2; shift 2;; 90 -g) GROUP=$2; shift 2;; 91 -v) ECHO=echo; shift;; 92 -q) ECHO=:; shift;; 93 -n) ECHO=echo SKIP=:; shift;; 94 --) shift; break;; 95 *) break;; 96 esac 97done 98 99case $# in 1000) echo "$0 [options] <destination> [<os>]" 101 echo "eg." 102 echo "$0 -o bin -g bin -m 444 /usr/local/share/mk" 103 exit 1 104 ;; 105esac 106dest=$1 107os=${2:-`uname`} 108osrel=${3:-`uname -r`} 109 110Do() { 111 $ECHO "$@" 112 $SKIP "$@" 113} 114 115Error() { 116 echo "ERROR: $@" >&2 117 exit 1 118} 119 120Warning() { 121 echo "WARNING: $@" >&2 122} 123 124[ "$FORCE_SYS_MK" ] && Warning "ignoring: FORCE_{BSD,SYS}_MK (no longer supported)" 125 126SYS_MK_DIR=${SYS_MK_DIR:-/usr/share/mk} 127SYS_MK=${SYS_MK:-$SYS_MK_DIR/sys.mk} 128 129realpath() { 130 [ -d $1 ] && cd $1 && 'pwd' && return 131 echo $1 132} 133 134# some Linux systems have deprecated egrep in favor of grep -E 135case "`echo bmake | egrep 'a' 2>&1`" in 136*"grep -E"*) egrep='grep -E';; 137*) egrep=egrep;; 138esac 139 140if [ -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 145 case "$os" in 146 *BSD*) SKIP_SYS_MK=: 147 SKIP_BSD_MK=: 148 ;; 149 *) # could be fake? 150 if [ ! -d $dest/sys -a ! -s $dest/Generic.sys.mk ]; then 151 SKIP_SYS_MK=: # play safe 152 SKIP_BSD_MK=: 153 fi 154 ;; 155 esac 156 fi 157fi 158 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` 162 163cd `dirname $0` 164mksrc=`'pwd'` 165if [ $mksrc = $dest ]; then 166 SKIP_MKFILES=: 167else 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` 172 SKIP_MKFILES= 173 [ -z "$SKIP_SYS_MK" ] && mk_files="sys.mk $mk_files" 174fi 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 178$SKIP cd $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. 184if [ -z "$SKIP_BSD_MK" ]; then 185 for f in dep doc files inc init lib links man nls obj own prog subdir 186 do 187 b=bsd.$f.mk 188 [ -s $b ] || Do ln -s $f.mk $b 189 done 190fi 191exit 0 192