Subject: misc/1578: make make macros more useful
To: None <gnats-bugs@gnats.netbsd.org>
From: Simon J. Gerraty <sjg@zen.void.oz.au>
List: netbsd-bugs
Date: 10/06/1995 13:48:31
>Number:         1578
>Category:       misc
>Synopsis:       -current *.mk macros useless for anyone but root.
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    misc-bug-people (Misc Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Oct  5 23:50:00 1995
>Last-Modified:
>Originator:     Simon J. Gerraty
>Organization:
Zen Programming...
>Release:        95-08-18
>Environment:
	
System: NetBSD zen.void.oz.au 1.0A NetBSD 1.0A (ZEN) #0: Fri Aug 18 18:59:14 EST 1995 root@zen.void.oz.au:/f1/usr.src/sys/arch/i386/compile/ZEN i386


>Description:
	
The BSD *.mk macros are great for building projects other than BSD.
However the install args used make it very difficult (impossible)
to use the macros as other than root.

Some time back the install flags were defined as in
BININSTALL_FLAGS?=${COPY} ${STRIP} -o ${BINOWN} ...

This at least made it possible for a Makefile.inc to redefine the flags
used.  Something like:
BININSTALL_FLAGS?=${COPY} ${STRIP} ${BINOWN} ...

Such that if needed BINOWN could be set to -oroot, but could also be left
blank this avoiding the errors from non-root users trying to
chown.

The patch below  re-introduces the BININSTALL_FLAGS concept as a
reasonable compromize between the current setup and the ideal one
where BINOWN etc contain the -o or can be blank.
It also uses ${INSTALL} for the install command itself, as
I've often needed to use an install-sh which would mv the old binary away
before installing.

>How-To-Repeat:
	
make install as non-root
>Fix:
	

Index: bsd.doc.mk
===================================================================
RCS file: /local/src/master/usr.src/share/mk/bsd.doc.mk,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -c -b -r1.1.1.1 -r1.2
*** bsd.doc.mk	1995/04/11 08:44:00	1.1.1.1
--- bsd.doc.mk	1995/09/13 22:18:28	1.2
***************
*** 42,48 ****
  
  FILES?=	${SRCS}
  install:
! 	install -c -o ${BINOWN} -g ${BINGRP} -m 444 \
  	    Makefile ${FILES} ${EXTRA} ${DESTDIR}${BINDIR}/${DIR}
  
  spell: ${SRCS}
--- 42,48 ----
  
  FILES?=	${SRCS}
  install:
! 	${INSTALL} -c -o ${BINOWN} -g ${BINGRP} -m 444 \
  	    Makefile ${FILES} ${EXTRA} ${DESTDIR}${BINDIR}/${DIR}
  
  spell: ${SRCS}
Index: bsd.lib.mk
===================================================================
RCS file: /local/src/master/usr.src/share/mk/bsd.lib.mk,v
retrieving revision 1.1.1.5
retrieving revision 1.3
diff -c -b -r1.1.1.5 -r1.3
*** bsd.lib.mk	1995/07/10 09:02:31	1.1.1.5
--- bsd.lib.mk	1995/09/19 13:41:56	1.3
***************
*** 153,184 ****
  beforeinstall:
  .endif
  
  realinstall:
  #	ranlib lib${LIB}.a
! 	install ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m 600 lib${LIB}.a \
  	    ${DESTDIR}${LIBDIR}
  	${RANLIB} -t ${DESTDIR}${LIBDIR}/lib${LIB}.a
  	chmod ${LIBMODE} ${DESTDIR}${LIBDIR}/lib${LIB}.a
  .if !defined(NOPROFILE)
  #	ranlib lib${LIB}_p.a
! 	install ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m 600 \
  	    lib${LIB}_p.a ${DESTDIR}${LIBDIR}
  	${RANLIB} -t ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
  	chmod ${LIBMODE} ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
  .endif
  .if !defined(NOPIC)
  #	ranlib lib${LIB}_pic.a
! 	install ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m 600 \
  	    lib${LIB}_pic.a ${DESTDIR}${LIBDIR}
  	${RANLIB} -t ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
  	chmod ${LIBMODE} ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
  .endif
  .if !defined(NOPIC) && defined(SHLIB_MAJOR) && defined(SHLIB_MINOR)
! 	install ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
  	    lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} ${DESTDIR}${LIBDIR}
  .endif
  .if !defined(NOLINT)
! 	install ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
  	    llib-l${LIB}.ln ${DESTDIR}${LINTLIBDIR}
  .endif
  .if defined(LINKS) && !empty(LINKS)
--- 153,186 ----
  beforeinstall:
  .endif
  
+ LIBINSTALL_FLAGS?=${COPY} -o ${LIBOWN} -g ${LIBGRP} 
+ 
  realinstall:
  #	ranlib lib${LIB}.a
! 	${INSTALL} ${LIBINSTALL_FLAGS} -m 0600 lib${LIB}.a \
  	    ${DESTDIR}${LIBDIR}
  	${RANLIB} -t ${DESTDIR}${LIBDIR}/lib${LIB}.a
  	chmod ${LIBMODE} ${DESTDIR}${LIBDIR}/lib${LIB}.a
  .if !defined(NOPROFILE)
  #	ranlib lib${LIB}_p.a
! 	${INSTALL} ${LIBINSTALL_FLAGS} -m 0600 \
  	    lib${LIB}_p.a ${DESTDIR}${LIBDIR}
  	${RANLIB} -t ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
  	chmod ${LIBMODE} ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
  .endif
  .if !defined(NOPIC)
  #	ranlib lib${LIB}_pic.a
! 	${INSTALL} ${LIBINSTALL_FLAGS} -m 0600 \
  	    lib${LIB}_pic.a ${DESTDIR}${LIBDIR}
  	${RANLIB} -t ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
  	chmod ${LIBMODE} ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
  .endif
  .if !defined(NOPIC) && defined(SHLIB_MAJOR) && defined(SHLIB_MINOR)
! 	${INSTALL} ${LIBINSTALL_FLAGS} -m ${LIBMODE} \
  	    lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} ${DESTDIR}${LIBDIR}
  .endif
  .if !defined(NOLINT)
! 	${INSTALL} ${LIBINSTALL_FLAGS} -m ${LIBMODE} \
  	    llib-l${LIB}.ln ${DESTDIR}${LINTLIBDIR}
  .endif
  .if defined(LINKS) && !empty(LINKS)
Index: bsd.man.mk
===================================================================
RCS file: /local/src/master/usr.src/share/mk/bsd.man.mk,v
retrieving revision 1.1.1.2
retrieving revision 1.3
diff -c -b -r1.1.1.2 -r1.3
*** bsd.man.mk	1995/06/27 01:08:32	1.1.1.2
--- bsd.man.mk	1995/09/19 13:41:58	1.3
***************
*** 22,28 ****
  MANALL=	${MAN:S/.1$/.cat1/g:S/.2$/.cat2/g:S/.3$/.cat3/g:S/.4$/.cat4/g:S/.5$/.cat5/g:S/.6$/.cat6/g:S/.7$/.cat7/g:S/.8$/.cat8/g}
  .endif
  
! MINSTALL=	install ${COPY} -o ${MANOWN} -g ${MANGRP} -m ${MANMODE}
  .if defined(MANZ)
  # chown and chmod are done afterward automatically
  MCOMPRESS=	gzip -cf
--- 22,28 ----
  MANALL=	${MAN:S/.1$/.cat1/g:S/.2$/.cat2/g:S/.3$/.cat3/g:S/.4$/.cat4/g:S/.5$/.cat5/g:S/.6$/.cat6/g:S/.7$/.cat7/g:S/.8$/.cat8/g}
  .endif
  
! MINSTALL=	${INSTALL} ${COPY} -o ${MANOWN} -g ${MANGRP} -m ${MANMODE}
  .if defined(MANZ)
  # chown and chmod are done afterward automatically
  MCOMPRESS=	gzip -cf
Index: bsd.nls.mk
===================================================================
RCS file: /local/src/master/usr.src/share/mk/bsd.nls.mk,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -c -b -r1.1.1.1 -r1.2
*** bsd.nls.mk	1995/05/02 05:55:58	1.1.1.1
--- bsd.nls.mk	1995/09/13 22:18:35	1.2
***************
*** 31,38 ****
  	@for msg in ${NLSALL}; do \
  		NLSLANG=`basename $$msg .cat`; \
  		dir=${DESTDIR}${NLSDIR}/$${NLSLANG}; \
! 		install -d $$dir; \
! 		install ${COPY} -o ${NLSOWN} -g ${NLSGRP} -m ${NLSMODE} $$msg $$dir/${NLSNAME}.cat; \
  	done
  .endif
  
--- 31,38 ----
  	@for msg in ${NLSALL}; do \
  		NLSLANG=`basename $$msg .cat`; \
  		dir=${DESTDIR}${NLSDIR}/$${NLSLANG}; \
! 		${INSTALL} -d $$dir; \
! 		${INSTALL} ${COPY} -o ${NLSOWN} -g ${NLSGRP} -m ${NLSMODE} $$msg $$dir/${NLSNAME}.cat; \
  	done
  .endif
  
Index: bsd.own.mk
===================================================================
RCS file: /local/src/master/usr.src/share/mk/bsd.own.mk,v
retrieving revision 1.1.1.4
retrieving revision 1.2
diff -c -b -r1.1.1.4 -r1.2
*** bsd.own.mk	1995/08/09 09:57:10	1.1.1.4
--- bsd.own.mk	1995/09/13 22:18:36	1.2
***************
*** 43,48 ****
--- 43,49 ----
  NLSOWN?=	bin
  NLSMODE?=	${NONBINMODE}
  
+ INSTALL?=	install
  COPY?=		-c
  STRIP?=		-s
  
Index: bsd.prog.mk
===================================================================
RCS file: /local/src/master/usr.src/share/mk/bsd.prog.mk,v
retrieving revision 1.1.1.3
retrieving revision 1.3
diff -c -b -r1.1.1.3 -r1.3
*** bsd.prog.mk	1995/06/27 01:08:30	1.1.1.3
--- bsd.prog.mk	1995/09/19 13:41:59	1.3
***************
*** 100,109 ****
  afterinstall:
  .endif
  
  .if !target(realinstall)
  realinstall:
  .if defined(PROG)
! 	install ${COPY} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
  	    ${PROG} ${DESTDIR}${BINDIR}
  .endif
  .if defined(HIDEGAME)
--- 100,111 ----
  afterinstall:
  .endif
  
+ BININSTALL_FLAGS?=${COPY} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE}
+ 
  .if !target(realinstall)
  realinstall:
  .if defined(PROG)
! 	${INSTALL} ${BININSTALL_FLAGS} \
  	    ${PROG} ${DESTDIR}${BINDIR}
  .endif
  .if defined(HIDEGAME)
>Audit-Trail:
>Unformatted: