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.115 2015/10/20 22:04:53 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=20151020 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 134if [ -s $SYS_MK -a -d $dest ]; then 135 # if this is a BSD system we don't want to touch $SYS_MK 136 dest=`realpath $dest` 137 sys_mk_dir=`realpath $SYS_MK_DIR` 138 if [ $dest = $sys_mk_dir ]; then 139 case "$os" in 140 *BSD*) SKIP_SYS_MK=: 141 SKIP_BSD_MK=: 142 ;; 143 *) # could be fake? 144 if [ ! -d $dest/sys -a ! -s $dest/Generic.sys.mk ]; then 145 SKIP_SYS_MK=: # play safe 146 SKIP_BSD_MK=: 147 fi 148 ;; 149 esac 150 fi 151fi 152 153[ -d $dest/sys ] || Do mkdir -p $dest/sys 154[ -d $dest/sys ] || Do mkdir $dest/sys || exit 1 155[ -z "$SKIP" ] && dest=`realpath $dest` 156 157cd `dirname $0` 158mksrc=`'pwd'` 159if [ $mksrc = $dest ]; then 160 SKIP_MKFILES=: 161else 162 # we do not install the examples 163 mk_files=`grep '^[a-z].*\.mk' FILES | egrep -v '(examples/|^sys\.mk|sys/)'` 164 mk_scripts=`egrep '^[a-z].*\.(sh|py)' FILES | egrep -v '/'` 165 sys_mk_files=`grep 'sys/.*\.mk' FILES` 166 SKIP_MKFILES= 167 [ -z "$SKIP_SYS_MK" ] && mk_files="sys.mk $mk_files" 168fi 169$SKIP_MKFILES Do cp $cp_f $mk_files $dest 170$SKIP_MKFILES Do cp $cp_f $sys_mk_files $dest/sys 171$SKIP_MKFILES Do cp $cp_f $mk_scripts $dest 172$SKIP cd $dest 173$SKIP_MKFILES Do chmod $MODE $mk_files $sys_mk_files 174$SKIP_MKFILES Do chmod $BINMODE $mk_scripts 175[ "$GROUP" ] && $SKIP_MKFILES Do chgrp $GROUP $mk_files $sys_mk_files 176[ "$OWNER" ] && $SKIP_MKFILES Do chown $OWNER $mk_files $sys_mk_files 177# if this is a BSD system the bsd.*.mk should exist and be used. 178if [ -z "$SKIP_BSD_MK" ]; then 179 for f in dep doc init lib links man nls obj own prog subdir 180 do 181 b=bsd.$f.mk 182 [ -s $b ] || Do ln -s $f.mk $b 183 done 184fi 185exit 0 186