os161.hostprog.mk 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #
  2. # OS/161 build environment: build a host-system program
  3. #
  4. # Usage:
  5. # TOP=../..
  6. # .include "$(TOP)/mk/os161.config.mk"
  7. # [defs go here]
  8. # .include "$(TOP)/mk/os161.hostprog.mk"
  9. # [any extra rules go here]
  10. #
  11. # Variables controlling this file:
  12. #
  13. # PROG Name of program to generate.
  14. # SRCS .c and .S files to compile.
  15. #
  16. # HOST_CFLAGS Compile flags.
  17. # HOST_LDFLAGS Link flags.
  18. # HOST_LIBS Libraries to link with.
  19. #
  20. # HOSTBINDIR Directory under $(OSTREE) to install into,
  21. # e.g. /hostbin. Should have a leading slash.
  22. # If not set, the program goes in
  23. # $(TOOLDIR)/hostbin instead.
  24. #
  25. # Note that individual program makefiles should only *append* to
  26. # HOST_CFLAGS, HOST_LDFLAGS, and HOST_LIBS, not assign them. Otherwise
  27. # stuff set by os161.config.mk will get lost and bad things will
  28. # happen.
  29. #
  30. # This is set up so it can be used together with os161.prog.mk if
  31. # necessary.
  32. #
  33. # Real name
  34. _PROG_=host-$(PROG)
  35. # Directory to install into
  36. .if defined(HOSTBINDIR)
  37. _INSTALLDIR_=$(INSTALLTOP)$(HOSTBINDIR)
  38. .else
  39. _INSTALLDIR_=$(TOOLDIR)/hostbin
  40. .endif
  41. # We may want these directories created. (Used by os161.baserules.mk.)
  42. MKDIRS+=$(MYBUILDDIR)
  43. MKDIRS+=$(_INSTALLDIR_)
  44. .if defined(HOSTBINDIR)
  45. MKDIRS+=$(OSTREE)$(HOSTBINDIR)
  46. .endif
  47. # Default rule: create the program.
  48. # (In make the first rule found is the default.)
  49. all: $(MYBUILDDIR) .WAIT $(MYBUILDDIR)/$(_PROG_)
  50. # Now get rules to compile the SRCS.
  51. .include "$(TOP)/mk/os161.hostcompile.mk"
  52. # Further rules for programs.
  53. # Clean: delete extraneous files.
  54. clean: cleanhostprog
  55. cleanhostprog:
  56. rm -f $(MYBUILDDIR)/$(_PROG_)
  57. #
  58. # Install: we can install into either $(INSTALLTOP) or $(OSTREE).
  59. # When building the whole system, we always install into the staging
  60. # area. However, if you're working on a particular program it is
  61. # usually convenient to be able to install it directly to $(OSTREE)
  62. # instead of doing a complete top-level install.
  63. #
  64. # Note that we make a hard link instead of a copy by default to reduce
  65. # overhead.
  66. #
  67. install-staging: $(_INSTALLDIR_) .WAIT $(_INSTALLDIR_)/$(_PROG_)
  68. $(_INSTALLDIR_)/$(_PROG_): $(MYBUILDDIR)/$(_PROG_)
  69. rm -f $(.TARGET)
  70. ln $(MYBUILDDIR)/$(_PROG_) $(.TARGET) || \
  71. cp $(MYBUILDDIR)/$(_PROG_) $(.TARGET)
  72. .if defined(HOSTBINDIR)
  73. install: install-hostprog
  74. install-hostprog: $(OSTREE)$(HOSTBINDIR) $(MYBUILDDIR)/$(_PROG_)
  75. rm -f $(OSTREE)$(HOSTBINDIR)/$(_PROG_)
  76. ln $(MYBUILDDIR)/$(_PROG_) $(OSTREE)$(HOSTBINDIR)/$(_PROG_) || \
  77. cp $(MYBUILDDIR)/$(_PROG_) $(OSTREE)$(HOSTBINDIR)/$(_PROG_)
  78. .else
  79. install:
  80. @echo "Nothing to manually install"
  81. .endif
  82. # Always implicitly include the compat library.
  83. _COMPATLIB_=$(TOOLDIR)/hostlib/libhostcompat.a
  84. # Link the program.
  85. $(MYBUILDDIR)/$(_PROG_): $(HOST_OBJS) $(_COMPATLIB_)
  86. $(HOST_LDCC) $(HOST_LDFLAGS) $(HOST_OBJS) $(HOST_LIBS) $(_COMPATLIB_) \
  87. -o $(.TARGET)
  88. # Mark targets that don't represent files PHONY, to prevent various
  89. # lossage if files by those names appear.
  90. .PHONY: all clean cleanhostprog install-staging install install-hostprog
  91. # Finally, get the shared definitions for the most basic rules.
  92. .include "$(TOP)/mk/os161.baserules.mk"
  93. # End.