os161.compile.mk 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #
  2. # OS/161 build environment: compile source files.
  3. #
  4. # Usage: use os161.prog.mk or os161.lib.mk
  5. #
  6. # Variables controlling this file:
  7. #
  8. # SRCS .c and .S files to compile.
  9. #
  10. # Provides:
  11. #
  12. # OBJS .o files from compilation.
  13. #
  14. # Objects list starts empty. It is added to below.
  15. OBJS=
  16. clean: cleancompile
  17. cleancompile:
  18. rm -f $(MYBUILDDIR)/*.[oa]
  19. distclean: distcleancompile
  20. distcleancompile:
  21. rm -f .depend
  22. #
  23. # Depend: generate dependency information.
  24. # Use gcc's -M argument for this.
  25. #
  26. # Note that we use -M rather than -MM, to get both system headers
  27. # and program-local headers. This is because we *are* the system and
  28. # we might well change those system headers.
  29. #
  30. # The awk scripts and the first sed invocation transform the results to
  31. # have one file per line.
  32. #
  33. # The second sed command replaces the value of $(INSTALLTOP) -- which
  34. # is some pathname -- with the string $(INSTALLTOP). This makes the
  35. # depend file independent of the value of $(INSTALLTOP).
  36. #
  37. # XXX: why the $p;$x? That seems like a no-op in this script... also,
  38. # this logic is extremely opaque and could be done a lot better...
  39. #
  40. depend: dependcompile
  41. dependcompile:
  42. $(CC) $(CFLAGS) $(MORECFLAGS) -M $(SRCS) |\
  43. awk '{x=$$0~"^ ";for(i=1;i<=NF;i++){printf "%d %s\n",x,$$i;x=1; }}'|\
  44. sed '/1 \\/d' | awk '{ printf "%s%s", $$1?" \\\n ":"\n", $$2 }' |\
  45. sed 's|$(INSTALLTOP)|$$(INSTALLTOP)|;$$p;$$x' |\
  46. sed 's|^\([^ ]\)|$$(MYBUILDDIR)/\1|' > .deptmp
  47. mv -f .deptmp .depend
  48. # We don't need to explicitly include .depend; our make does this on its own.
  49. #.-include ".depend"
  50. tags: tagscompile
  51. tagscompile:
  52. ctags -wtd $(SRCS) *.h
  53. #
  54. # Compile rules.
  55. # We can use the same rules for .c and .S because gcc knows how to handle
  56. # .S files.
  57. #
  58. # Make it so typing "make foo.o" does the right thing.
  59. #
  60. .for _S_ in $(SRCS:M*.[cS])
  61. OBJS+=$(MYBUILDDIR)/$(_S_:T:R).o
  62. $(MYBUILDDIR)/$(_S_:T:R).o: $(_S_)
  63. $(CC) $(CFLAGS) $(MORECFLAGS) -c $(_S_) -o $(.TARGET)
  64. $(_S_:T:R).o: $(MYBUILDDIR)/$(_S_:T:R).o
  65. .PHONY: $(_S_:T:R).o
  66. .endfor
  67. # Make non-file rules PHONY.
  68. .PHONY: clean cleancompile distclean distcleancompile
  69. .PHONY: depend dependcompile tags tagscompile
  70. # End.