From: espie Date: Sat, 1 Jul 2017 14:41:54 +0000 (+0000) Subject: effectively kill depend as an independant target (there are a few corners X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=a86afe1b9ffc646f5490ddc208710cb430fb14b0;p=openbsd effectively kill depend as an independant target (there are a few corners where a separate depend step is still needed, mostly gcc3 and mesa). Use of BUILDFIRST is mostly enough to make sure important stuff is built first. Otherwise, this makes use of -M* compiler options to generate dependencies on the fly. There is a bit of behind-the-scene for targets with several steps (like yacc and/or libraries) and the compiler needs extra hand-holding with assembler files (don't know why, don't care). Idea based on guenther@'s initial kernel work, loads of input from drahn, aoyama, tb, etc. okay tb@ "why wait" deraadt@ --- diff --git a/share/mk/bsd.dep.mk b/share/mk/bsd.dep.mk index bbbe61b2673..f6f39dde98f 100644 --- a/share/mk/bsd.dep.mk +++ b/share/mk/bsd.dep.mk @@ -1,42 +1,24 @@ -# $OpenBSD: bsd.dep.mk,v 1.15 2017/06/16 10:20:52 espie Exp $ +# $OpenBSD: bsd.dep.mk,v 1.16 2017/07/01 14:41:54 espie Exp $ # $NetBSD: bsd.dep.mk,v 1.12 1995/09/27 01:15:09 christos Exp $ -# some of the rules involve .h sources, so remove them from mkdep line .if !target(depend) -depend: beforedepend .depend realdepend afterdepend -.ORDER: beforedepend .depend realdepend afterdepend -realdepend: _SUBDIRUSE +depend: + @: +.endif -. if defined(SRCS) && !empty(SRCS) -.depend: ${SRCS} ${_LEXINTM} ${_YACCINTM} - @rm -f .depend - @files="${.ALLSRC:M*.s} ${.ALLSRC:M*.S}"; \ - if [ "$$files" != " " ]; then \ - echo mkdep -a ${MKDEP} ${CFLAGS:M-std=*} ${CFLAGS:M-[ID]*} ${CPPFLAGS} ${AINC} $$files;\ - mkdep -a ${MKDEP} ${CFLAGS:M-std=*} ${CFLAGS:M-[ID]*} ${CPPFLAGS} ${AINC} $$files; \ - fi - @files="${.ALLSRC:M*.c}"; \ - if [ "$$files" != "" ]; then \ - echo mkdep -a ${MKDEP} ${CFLAGS:M-std=*} ${CFLAGS:M-[ID]*} ${CPPFLAGS} $$files; \ - mkdep -a ${MKDEP} ${CFLAGS:M-[ID]*} ${CPPFLAGS} $$files; \ - fi - @files="${.ALLSRC:M*.cc} ${.ALLSRC:M*.C} ${.ALLSRC:M*.cpp}"; \ - files="$$files ${.ALLSRC:M*.cxx}"; \ - if [ "$$files" != " " ]; then \ - echo CC=${CXX:Q} mkdep -a ${MKDEP} ${CXXFLAGS:M-std=*} ${CXXFLAGS:M-[ID]*} ${CPPFLAGS} $$files; \ - CC=${CXX:Q} mkdep -a ${MKDEP} ${CXXFLAGS:M-std=*} ${CXXFLAGS:M-[ID]*} ${CPPFLAGS} $$files; \ - fi -. else -.depend: -. endif -. if !target(beforedepend) -beforedepend: -. endif -. if !target(afterdepend) -afterdepend: -. endif +# relies on DEPS defined by bsd.lib.mk and bsd.prog.mk +.if defined(DEPS) && !empty(DEPS) +. for o in ${DEPS} + sinclude $o +. endfor .endif +CFLAGS += -MD -MP +CXXFLAGS += -MD -MP + +# libraries need some special love +DFLAGS = -MT $*.o -MT $*.po -MT $*.so -MT $*.do + .if !target(tags) . if defined(SRCS) tags: ${SRCS} _SUBDIRUSE @@ -47,16 +29,10 @@ tags: . endif .endif -.if defined(SRCS) -cleandir: cleandepend -cleandepend: - rm -f .depend ${.CURDIR}/tags -.endif +CLEANFILES += ${DEPS} .depend BUILDFIRST ?= BUILDAFTER ?= .if !empty(BUILDFIRST) && !empty(BUILDAFTER) ${BUILDAFTER}: ${BUILDFIRST} .endif - -.PHONY: beforedepend depend afterdepend cleandepend realdepend diff --git a/share/mk/bsd.lib.mk b/share/mk/bsd.lib.mk index cf7cbeed237..cf439c88082 100644 --- a/share/mk/bsd.lib.mk +++ b/share/mk/bsd.lib.mk @@ -1,4 +1,4 @@ -# $OpenBSD: bsd.lib.mk,v 1.84 2017/06/16 10:20:52 espie Exp $ +# $OpenBSD: bsd.lib.mk,v 1.85 2017/07/01 14:41:54 espie Exp $ # $NetBSD: bsd.lib.mk,v 1.67 1996/01/17 20:39:26 mycroft Exp $ # @(#)bsd.lib.mk 5.26 (Berkeley) 5/2/91 @@ -38,92 +38,107 @@ DIST_CFLAGS+= -Os .c.o: @echo "${COMPILE.c} ${.IMPSRC} -o ${.TARGET}" - @${COMPILE.c} ${.IMPSRC} -o ${.TARGET}.o + @${COMPILE.c} ${DFLAGS} ${.IMPSRC} -o ${.TARGET}.o + @-mv $@.d $*.d @${LD} -X -r ${.TARGET}.o -o ${.TARGET} @rm -f ${.TARGET}.o .c.po: @echo "${COMPILE.c} -p ${.IMPSRC} -o ${.TARGET}" - @${COMPILE.c} -p ${.IMPSRC} -o ${.TARGET}.o + @${COMPILE.c} ${DFLAGS} -p ${.IMPSRC} -o ${.TARGET}.o + @-mv $@.d $*.d @${LD} -X -r ${.TARGET}.o -o ${.TARGET} @rm -f ${.TARGET}.o .c.so: @echo "${COMPILE.c} ${PICFLAG} -DPIC ${.IMPSRC} -o ${.TARGET}" - @${COMPILE.c} ${PICFLAG} -DPIC ${.IMPSRC} -o ${.TARGET}.o + @${COMPILE.c} ${DFLAGS} ${PICFLAG} -DPIC ${.IMPSRC} -o ${.TARGET}.o + @-mv $@.d $*.d @${LD} -X -r ${.TARGET}.o -o ${.TARGET} @rm -f ${.TARGET}.o .c.do: @echo "${COMPILE.c} ${DIST_CFLAGS} ${.IMPSRC} -o ${.TARGET}" - @${COMPILE.c} ${DIST_CFLAGS} ${.IMPSRC} -o ${.TARGET}.o + @${COMPILE.c} ${DFLAGS} ${DIST_CFLAGS} ${.IMPSRC} -o ${.TARGET}.o + @-mv $@.d $*.d @${LD} -X -r ${.TARGET}.o -o ${.TARGET} @rm -f ${.TARGET}.o .cc.o .cpp.o .C.o .cxx.o: @echo "${COMPILE.cc} ${.IMPSRC} -o ${.TARGET}" - @${COMPILE.cc} ${.IMPSRC} -o ${.TARGET}.o + @${COMPILE.cc} ${DFLAGS} ${.IMPSRC} -o ${.TARGET}.o + @-mv $@.d $*.d @${LD} -X -r ${.TARGET}.o -o ${.TARGET} @rm -f ${.TARGET}.o .cc.po .cpp.po .C.po .cxx.po: @echo "${COMPILE.cc} -p ${.IMPSRC} -o ${.TARGET}" - @${COMPILE.cc} -p ${.IMPSRC} -o ${.TARGET}.o + @${COMPILE.cc} ${DFLAGS} -p ${.IMPSRC} -o ${.TARGET}.o + @-mv $@.d $*.d @${LD} -X -r ${.TARGET}.o -o ${.TARGET} @rm -f ${.TARGET}.o .cc.so .cpp.so .C.so .cxx.so: @echo "${COMPILE.cc} ${PICFLAG} -DPIC ${.IMPSRC} -o ${.TARGET}" - @${COMPILE.cc} ${PICFLAG} -DPIC ${.IMPSRC} -o ${.TARGET}.o + @${COMPILE.cc} ${DFLAGS} ${PICFLAG} -DPIC ${.IMPSRC} -o ${.TARGET}.o + @-mv $@.d $*.d @${LD} -X -r ${.TARGET}.o -o ${.TARGET} @rm -f ${.TARGET}.o # Fortran 77 .f.o: @echo "${COMPILE.f} ${.IMPSRC} -o ${.TARGET}" - @${COMPILE.f} ${.IMPSRC} -o ${.TARGET}.o + @${COMPILE.f} ${DFLAGS} ${.IMPSRC} -o ${.TARGET}.o + @-mv $@.d $*.d @${LD} -X -r ${.TARGET}.o -o ${.TARGET} @rm -f ${.TARGET}.o .f.po: @echo "${COMPILE.f} -p ${.IMPSRC} -o ${.TARGET}" - @${COMPILE.f} -p ${.IMPSRC} -o ${.TARGET}.o + @${COMPILE.f} ${DFLAGS} -p ${.IMPSRC} -o ${.TARGET}.o + @-mv $@.d $*.d @${LD} -X -r ${.TARGET}.o -o ${.TARGET} @rm -f ${.TARGET}.o .f.so: @echo "${COMPILE.f} ${PICFLAG} -DPIC ${.IMPSRC} -o ${.TARGET}" - @${COMPILE.f} ${PICFLAG} -DPIC ${.IMPSRC} -o ${.TARGET}.o + @${COMPILE.f} ${DFLAGS} ${PICFLAG} -DPIC ${.IMPSRC} -o ${.TARGET}.o + @-mv $@.d $*.d @${LD} -X -r ${.TARGET}.o -o ${.TARGET} @rm -f ${.TARGET}.o .S.o .s.o: @echo "${COMPILE.S} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}" - @${COMPILE.S} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}.o + @${COMPILE.S} ${DFLAGS} -MF $@.d ${CFLAGS:M-[IDM]*} ${AINC} \ + ${.IMPSRC} -o ${.TARGET}.o + @-mv $@.d $*.d @${LD} -X -r ${.TARGET}.o -o ${.TARGET} @rm -f ${.TARGET}.o .S.po .s.po: @echo "${COMPILE.S} -DPROF ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} \ -o ${.TARGET}" - @${COMPILE.S} -DPROF ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} \ - -o ${.TARGET}.o + @${COMPILE.S} ${DFLAGS} -MF $@.d -DPROF ${CFLAGS:M-[IDM]*} ${AINC} \ + ${.IMPSRC} -o ${.TARGET}.o + @-mv $@.d $*.d @${LD} -X -r ${.TARGET}.o -o ${.TARGET} @rm -f ${.TARGET}.o .S.so .s.so: @echo "${COMPILE.S} ${PICFLAG} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} \ -o ${.TARGET}" - @${COMPILE.S} ${PICFLAG} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} \ - -o ${.TARGET}.o + @${COMPILE.S} ${DFLAGS} -MF $@.d ${PICFLAG} ${CFLAGS:M-[IDM]*} \ + ${AINC} ${.IMPSRC} -o ${.TARGET}.o + @-mv $@.d $*.d @${LD} -X -r ${.TARGET}.o -o ${.TARGET} @rm -f ${.TARGET}.o .S.do .s.do: @echo "${COMPILE.S} ${CFLAGS:M-[ID]*} ${AINC} ${DIST_CFLAGS} \ ${.IMPSRC} -o ${.TARGET}" - @${COMPILE.S} ${CFLAGS:M-[ID]*} ${AINC} ${DIST_CFLAGS} ${.IMPSRC} \ - -o ${.TARGET}.o + @${COMPILE.S} ${DFLAGS} -MF $@.d ${CFLAGS:M-[IDM]*} ${AINC} \ + ${DIST_CFLAGS} ${.IMPSRC} -o ${.TARGET}.o + @-mv $@.d $*.d @${LD} -X -r ${.TARGET}.o -o ${.TARGET} @rm -f ${.TARGET}.o @@ -167,6 +182,7 @@ all: ${_LIBS} _SUBDIRUSE BUILDAFTER += ${_LIBS} OBJS+= ${SRCS:N*.h:R:S/$/.o/} +DEPS+= ${OBJS:S/$/.d/} BUILDAFTER += ${OBJS} lib${LIB}.a: ${OBJS} @@ -177,6 +193,7 @@ lib${LIB}.a: ${OBJS} POBJS+= ${OBJS:.o=.po} BUILDAFTER += ${POBJS} + lib${LIB}_p.a: ${POBJS} @echo building profiled ${LIB} library @rm -f lib${LIB}_p.a @@ -185,6 +202,7 @@ lib${LIB}_p.a: ${POBJS} SOBJS+= ${OBJS:.o=.so} BUILDAFTER += ${SOBJS} + ${FULLSHLIBNAME}: ${SOBJS} ${DPADD} @echo building shared ${LIB} library \(version ${SHLIB_MAJOR}.${SHLIB_MINOR}\) @rm -f ${.TARGET} @@ -237,10 +255,6 @@ clean: _SUBDIRUSE cleandir: _SUBDIRUSE clean -.if defined(SRCS) -afterdepend: .depend - @sed -i 's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1.so \1.do:/' .depend -.endif .if !target(install) .if !target(beforeinstall) diff --git a/share/mk/bsd.prog.mk b/share/mk/bsd.prog.mk index 49f3c5b16e6..c86512e4409 100644 --- a/share/mk/bsd.prog.mk +++ b/share/mk/bsd.prog.mk @@ -1,4 +1,4 @@ -# $OpenBSD: bsd.prog.mk,v 1.71 2017/06/16 10:20:52 espie Exp $ +# $OpenBSD: bsd.prog.mk,v 1.72 2017/07/01 14:41:54 espie Exp $ # $NetBSD: bsd.prog.mk,v 1.55 1996/04/08 21:19:26 jtc Exp $ # @(#)bsd.prog.mk 5.26 (Berkeley) 6/25/91 @@ -72,6 +72,8 @@ LIBARCH?= SRCS?= ${PROG}.c . if !empty(SRCS:N*.h:N*.sh) OBJS+= ${SRCS:N*.h:N*.sh:R:S/$/.o/} +DEPS+= ${OBJS:R:S/$/.d/} + _LEXINTM+=${SRCS:M*.l:.l=.c} _YACCINTM+=${SRCS:M*.y:.y=.c} . endif @@ -141,6 +143,15 @@ realinstall: beforeinstall .include .endif +# if we already got bsd.lib.mk we don't want to wreck that +.if !defined(_LIBS) +.s.o: + ${COMPILE.S} -MD -MF ${.TARGET:R}.d -o $@ ${.IMPSRC} + +.S.o: + ${COMPILE.S} -MD -MF ${.TARGET:R}.d -o $@ ${.IMPSRC} +.endif + .include .include .include diff --git a/share/mk/bsd.sys.mk b/share/mk/bsd.sys.mk index 7fd2d00185c..b1af201eb65 100644 --- a/share/mk/bsd.sys.mk +++ b/share/mk/bsd.sys.mk @@ -1,4 +1,4 @@ -# $OpenBSD: bsd.sys.mk,v 1.10 2012/04/08 15:56:28 jsg Exp $ +# $OpenBSD: bsd.sys.mk,v 1.11 2017/07/01 14:41:54 espie Exp $ # $NetBSD: bsd.sys.mk,v 1.2 1995/12/13 01:25:07 cgd Exp $ # # Overrides used for OpenBSD source tree builds. @@ -22,6 +22,7 @@ CXXFLAGS+= -idirafter ${DESTDIR}/usr/include/g++ ${LEX.l} -o${.TARGET:R}.yy.c ${.IMPSRC} ${COMPILE.c} -o ${.TARGET} ${.TARGET:R}.yy.c rm -f ${.TARGET:R}.yy.c + if test -f ${.TARGET:R}.d; then sed -i -e 's,${.TARGET:R}.yy.c,${.IMPSRC},' ${.TARGET:R}.d; fi # Yacc .y: @@ -35,4 +36,5 @@ CXXFLAGS+= -idirafter ${DESTDIR}/usr/include/g++ ${YACC.y} -b ${.TARGET:R} ${.IMPSRC} ${COMPILE.c} -o ${.TARGET} ${.TARGET:R}.tab.c rm -f ${.TARGET:R}.tab.c + if test -f ${.TARGET:R}.d; then sed -i -e 's,${.TARGET:R}.tab.c,${.IMPSRC},' ${.TARGET:R}.d; fi .endif diff --git a/share/mk/sys.mk b/share/mk/sys.mk index fc59aec15f6..c72a44d8eb1 100644 --- a/share/mk/sys.mk +++ b/share/mk/sys.mk @@ -1,4 +1,4 @@ -# $OpenBSD: sys.mk,v 1.77 2017/03/04 16:52:47 deraadt Exp $ +# $OpenBSD: sys.mk,v 1.78 2017/07/01 14:41:54 espie Exp $ # $NetBSD: sys.mk,v 1.27 1996/04/10 05:47:19 mycroft Exp $ # @(#)sys.mk 5.11 (Berkeley) 3/13/91 @@ -195,6 +195,7 @@ CTAGS?= /usr/bin/ctags ${LEX.l} ${.IMPSRC} ${COMPILE.c} -o ${.TARGET} lex.yy.c rm -f lex.yy.c + if test -f ${.TARGET:R}.d; then sed -i -e 's,lex.yy.c,${.IMPSRC},' ${.TARGET:R}.d; fi # Yacc .y: @@ -208,6 +209,7 @@ CTAGS?= /usr/bin/ctags ${YACC.y} ${.IMPSRC} ${COMPILE.c} -o ${.TARGET} y.tab.c rm -f y.tab.c + if test -f ${.TARGET:R}.d; then sed -i -e 's,y.tab.c,${.IMPSRC},' ${.TARGET:R}.d; fi # Shell .sh: