/share/mk/bsd.crunchgen.mk

https://bitbucket.org/freebsd/freebsd-head/ · Makefile · 164 lines · 112 code · 13 blank · 39 comment · 8 complexity · ce2ada1d42dc85dfa49a0dd46471b839 MD5 · raw file

  1. #################################################################
  2. #
  3. # General notes:
  4. #
  5. # A number of Make variables are used to generate the crunchgen config file.
  6. #
  7. # CRUNCH_SRCDIRS: lists directories to search for included programs
  8. # CRUNCH_PROGS: lists programs to be included
  9. # CRUNCH_LIBS: libraries to statically link with
  10. # CRUNCH_SHLIBS: libraries to dynamically link with
  11. # CRUNCH_BUILDOPTS: generic build options to be added to every program
  12. # CRUNCH_BUILDTOOLS: lists programs that need build tools built in the
  13. # local architecture.
  14. #
  15. # Special options can be specified for individual programs
  16. # CRUNCH_SRCDIR_$(P): base source directory for program $(P)
  17. # CRUNCH_BUILDOPTS_$(P): additional build options for $(P)
  18. # CRUNCH_ALIAS_$(P): additional names to be used for $(P)
  19. #
  20. # By default, any name appearing in CRUNCH_PROGS or CRUNCH_ALIAS_${P}
  21. # will be used to generate a hard link to the resulting binary.
  22. # Specific links can be suppressed by setting
  23. # CRUNCH_SUPPRESS_LINK_$(NAME) to 1.
  24. #
  25. # If CRUNCH_GENERATE_LINKS is set to no, no links will be generated.
  26. #
  27. # $FreeBSD$
  28. ##################################################################
  29. # The following is pretty nearly a generic crunchgen-handling makefile
  30. #
  31. CONF= $(PROG).conf
  32. OUTMK= $(PROG).mk
  33. OUTC= $(PROG).c
  34. OUTPUTS=$(OUTMK) $(OUTC) $(PROG).cache
  35. CRUNCHOBJS= ${.OBJDIR}
  36. .if defined(MAKEOBJDIRPREFIX)
  37. CANONICALOBJDIR:= ${MAKEOBJDIRPREFIX}${.CURDIR}
  38. .elif defined(MAKEOBJDIR) && ${MAKEOBJDIR:M/*} != ""
  39. CANONICALOBJDIR:=${MAKEOBJDIR}
  40. .else
  41. CANONICALOBJDIR:= /usr/obj${.CURDIR}
  42. .endif
  43. CRUNCH_GENERATE_LINKS?= yes
  44. CLEANFILES+= $(CONF) *.o *.lo *.c *.mk *.cache *.a *.h
  45. # Program names and their aliases contribute hardlinks to 'rescue' executable,
  46. # except for those that get suppressed.
  47. .for D in $(CRUNCH_SRCDIRS)
  48. .for P in $(CRUNCH_PROGS_$(D))
  49. .ifdef CRUNCH_SRCDIR_${P}
  50. $(OUTPUTS): $(CRUNCH_SRCDIR_${P})/Makefile
  51. .else
  52. $(OUTPUTS): $(.CURDIR)/../../$(D)/$(P)/Makefile
  53. .endif
  54. .if ${CRUNCH_GENERATE_LINKS} == "yes"
  55. .ifndef CRUNCH_SUPPRESS_LINK_${P}
  56. LINKS+= $(BINDIR)/$(PROG) $(BINDIR)/$(P)
  57. .endif
  58. .for A in $(CRUNCH_ALIAS_$(P))
  59. .ifndef CRUNCH_SUPPRESS_LINK_${A}
  60. LINKS+= $(BINDIR)/$(PROG) $(BINDIR)/$(A)
  61. .endif
  62. .endfor
  63. .endif
  64. .endfor
  65. .endfor
  66. all: $(PROG)
  67. exe: $(PROG)
  68. $(CONF): Makefile
  69. echo \# Auto-generated, do not edit >$(.TARGET)
  70. .ifdef CRUNCH_BUILDOPTS
  71. echo buildopts $(CRUNCH_BUILDOPTS) >>$(.TARGET)
  72. .endif
  73. .ifdef CRUNCH_LIBS
  74. echo libs $(CRUNCH_LIBS) >>$(.TARGET)
  75. .endif
  76. .ifdef CRUNCH_SHLIBS
  77. echo libs_so $(CRUNCH_SHLIBS) >>$(.TARGET)
  78. .endif
  79. .for D in $(CRUNCH_SRCDIRS)
  80. .for P in $(CRUNCH_PROGS_$(D))
  81. echo progs $(P) >>$(.TARGET)
  82. .ifdef CRUNCH_SRCDIR_${P}
  83. echo special $(P) srcdir $(CRUNCH_SRCDIR_${P}) >>$(.TARGET)
  84. .else
  85. echo special $(P) srcdir $(.CURDIR)/../../$(D)/$(P) >>$(.TARGET)
  86. .endif
  87. .ifdef CRUNCH_BUILDOPTS_${P}
  88. echo special $(P) buildopts DIRPRFX=${DIRPRFX}${P}/ \
  89. $(CRUNCH_BUILDOPTS_${P}) >>$(.TARGET)
  90. .else
  91. echo special $(P) buildopts DIRPRFX=${DIRPRFX}${P}/ >>$(.TARGET)
  92. .endif
  93. .for A in $(CRUNCH_ALIAS_$(P))
  94. echo ln $(P) $(A) >>$(.TARGET)
  95. .endfor
  96. .endfor
  97. .endfor
  98. # XXX Make sure we don't pass -P to crunchgen(1).
  99. .MAKEFLAGS:= ${.MAKEFLAGS:N-P}
  100. .ORDER: $(OUTPUTS) objs
  101. $(OUTPUTS): $(CONF)
  102. MAKE=${MAKE} MAKEOBJDIRPREFIX=${CRUNCHOBJS} crunchgen -fq -m $(OUTMK) \
  103. -c $(OUTC) $(CONF)
  104. $(PROG): $(OUTPUTS) objs
  105. MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} -f $(OUTMK) exe
  106. objs: $(OUTMK)
  107. MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} -f $(OUTMK) objs
  108. # <sigh> Someone should replace the bin/csh and bin/sh build-tools with
  109. # shell scripts so we can remove this nonsense.
  110. build-tools:
  111. .for _tool in $(CRUNCH_BUILDTOOLS)
  112. cd $(.CURDIR)/../../${_tool}; \
  113. MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} obj; \
  114. MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} build-tools
  115. .endfor
  116. # Use a separate build tree to hold files compiled for this crunchgen binary
  117. # Yes, this does seem to partly duplicate bsd.subdir.mk, but I can't
  118. # get that to cooperate with bsd.prog.mk. Besides, many of the standard
  119. # targets should NOT be propagated into the components.
  120. cleandepend cleandir obj objlink:
  121. .for D in $(CRUNCH_SRCDIRS)
  122. .for P in $(CRUNCH_PROGS_$(D))
  123. .ifdef CRUNCH_SRCDIR_${P}
  124. cd ${CRUNCH_SRCDIR_$(P)} && \
  125. MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \
  126. DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${.TARGET}
  127. .else
  128. cd $(.CURDIR)/../../${D}/${P} && \
  129. MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \
  130. DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${.TARGET}
  131. .endif
  132. .endfor
  133. .endfor
  134. clean:
  135. rm -f ${CLEANFILES}
  136. if [ -e ${.OBJDIR}/$(OUTMK) ]; then \
  137. MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} -f $(OUTMK) clean; \
  138. fi
  139. .for D in $(CRUNCH_SRCDIRS)
  140. .for P in $(CRUNCH_PROGS_$(D))
  141. .ifdef CRUNCH_SRCDIR_${P}
  142. cd ${CRUNCH_SRCDIR_$(P)} && \
  143. MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \
  144. DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${.TARGET}
  145. .else
  146. cd $(.CURDIR)/../../${D}/${P} && \
  147. MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \
  148. DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${.TARGET}
  149. .endif
  150. .endfor
  151. .endfor