os161.hostcompile.mk 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #
  2. # OS/161 build environment: compile source files for the host system.
  3. #
  4. # Usage: use os161.hostprog.mk or os161.hostlib.mk
  5. #
  6. # Variables controlling this file:
  7. #
  8. # SRCS .c and .S files to compile.
  9. #
  10. # Provides:
  11. #
  12. # HOST_OBJS .ho files from compilation.
  13. #
  14. # Objects list starts empty. It is added to below.
  15. HOST_OBJS=
  16. # .ho is a host object.
  17. .SUFFIXES: .ho
  18. clean: cleanhostcompile
  19. cleanhostcompile:
  20. rm -f $(MYBUILDDIR)/*.ho $(MYBUILDDIR)/*.ha
  21. distclean: distcleanhostcompile
  22. distcleanhostcompile:
  23. rm -f .hostdepend
  24. #
  25. # Depend: generate dependency information.
  26. # Use gcc's -MM argument for this.
  27. #
  28. # Note that we use -MM rather than -M, so we don't get system headers.
  29. # They would be host system headers and we don't want to get involved
  30. # with those.
  31. #
  32. # The awk scripts and the first sed invocation transform the results to
  33. # have one file per line.
  34. #
  35. # The second sed command changes the .o filenames in gcc's output
  36. # to .ho names.
  37. #
  38. # The third sed command replaces the value of $(INSTALLTOP) -- which
  39. # is some pathname -- with the string $(INSTALLTOP). This makes the
  40. # depend file independent of the value of $(INSTALLTOP).
  41. #
  42. # XXX: why the $p;$x? That seems like a no-op in this script... also,
  43. # this logic is extremely opaque and could be done a lot better...
  44. #
  45. depend: dependhostcompile
  46. dependhostcompile:
  47. $(HOST_CC) $(HOST_CFLAGS) -DHOST -MM $(SRCS) |\
  48. awk '{x=$$0~"^ ";for(i=1;i<=NF;i++){printf "%d %s\n",x,$$i;x=1; }}'|\
  49. sed '/1 \\/d' | awk '{ printf "%s%s", $$1?" \\\n ":"\n", $$2 }' |\
  50. sed 's/\.o/\.ho/' |\
  51. sed 's|$(INSTALLTOP)|$$(INSTALLTOP)|;$$p;$$x' |\
  52. sed 's|^\([^ ]\)|$$(MYBUILDDIR)/\1|' > .deptmp
  53. mv -f .deptmp .depend
  54. # We do need to explicitly include .hostdepend, unlike .depend.
  55. .-include ".hostdepend"
  56. # No tags for host programs.
  57. tags: tagshostcompile
  58. tagshostcompile: ;
  59. #
  60. # Compile rules.
  61. # We can use the same rules for .c and .S because gcc knows how to handle
  62. # .S files.
  63. #
  64. .for _S_ in $(SRCS:M*.[cS])
  65. HOST_OBJS+=$(MYBUILDDIR)/$(_S_:T:R).ho
  66. $(MYBUILDDIR)/$(_S_:T:R).ho: $(_S_)
  67. $(HOST_CC) $(HOST_CFLAGS) -DHOST -c $(_S_) -o $(.TARGET)
  68. .endfor
  69. # Make non-file rules PHONY.
  70. .PHONY: clean cleanhostcompile distclean distcleanhostcompile
  71. .PHONY: depend dependhostcompile tags tagshostcompile
  72. # End.