Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. # This is not a independent Makefile; it is auxiliary file
  2. # included from main Makefile.
  3. # It depends on the following variables and macro:
  4. # $(FASM_PROGRAMS) is a list of all programs to build with FASM rule;
  5. # $(binarypart) is a macro which converts from $(1)=item of $(FASM_PROGRAMS)
  6. # to space-escaped full name of binary, $(respace) unescapes spaces;
  7. # $(fbinary) and $(fsource) gives space-unescaped full name of binary
  8. # and source (respectively) of $(f)=item of $(FASM_PROGRAMS).
  9.  
  10. # Define the rule for all FASM programs.
  11. # Yes, this looks like a black magic.
  12. # But it is not so scary as it seems.
  13. # First, we define "meta-rule" as a rule which is
  14. # macro depending on $(fasmprog).
  15. # Second, the construction foreach+eval creates
  16. # usual rules, one for each $(fasmprog) in $(FASM_PROGRAMS).
  17. # Note that meta-rule is double-expanded, first
  18. # time as the arg of eval - it is the place where $(fasmprog)
  19. # gets expanded - and second time as the rule;
  20. # so all $ which are expected to expand at the second time should be escaped.
  21. # And all $ which are expected to be expanded by the shell should be escaped
  22. # twice, so they become $$$$.
  23.  
  24. # The arguments of macro fasm_meta_rule:
  25. # $(1) = name of binary file,
  26. # $(2) = name of main source file.
  27. # $(3) = folder of binary file - without spaces.
  28. # $(4) = name of program - without path and extension,
  29. define fasm_meta_rule
  30. $(1): $(2) Makefile.fasm .deps/.dir $$(call respace,$$(addsuffix .dir,$(3)))
  31.         fasm -m 65536 $$< "$$@" -s .deps/$(4).fas
  32.         prepsrc .deps/$(4).fas /dev/null
  33.         prepsrc .deps/$(4).fas /dev/stdout | \
  34.         perl -n -e 's|\\|/|g;push @a,$$$$1 if/^;include \x27(.*?)\x27/;' \
  35.         -e 'END{$$$$a=join " \\\n ",@a;print "$(1): $$$$a\n$$$$a:\n"}' > .deps/$(4).Po
  36.         kpack --nologo "$$@"
  37. -include .deps/$(4).Po
  38. endef
  39.  
  40. progname=$(call respace,$(basename $(notdir $(call binarypart,$(f)))))
  41. binarydir=$(subst ./,,$(dir $(call binarypart,$(f))))
  42. $(foreach f,$(FASM_PROGRAMS),$(eval $(call fasm_meta_rule,$(fbinary),$(fsource),$(binarydir),$(progname))))
  43.  
  44. # Rule for the kernel differs: it uses kerpack instead of kpack.
  45. kernel.mnt: $(KERNEL)/kernel.asm Makefile.fasm .deps/.dir
  46.         fasm -m 65536 $< "$@" -s .deps/kernel.fas
  47.         prepsrc .deps/kernel.fas /dev/null
  48.         prepsrc .deps/kernel.fas /dev/stdout | \
  49.         perl -n -e 's|\\|/|g;push @a,$$1 if/^;include \x27(.*?)\x27/;' \
  50.         -e 'END{$$a=join " \\\n ",@a;print "$@: $$a\n$$a:\n"}' > .deps/kernel.Po
  51.         kerpack $@
  52. -include .deps/kernel.Po
  53.