Subversion Repositories Kolibri OS

Rev

Rev 2777 | Blame | Compare with Previous | 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;s| |\\ |g;push @a,$$$$1 if/^;include\\ \x27(.*?)\x27/;' \
  35.         -e 'END{$$$$a=join " \\\n ",@a;print q`$(1): `,"$$$$a\n$$$$a:\n"}' > .deps/$(4).Po
  36.         kpack --nologo "$$@"
  37. -include .deps/$(4).Po
  38. endef
  39.  
  40. define fasm_nokpack_meta_rule
  41. $(1): $(2) Makefile.fasm .deps/.dir $$(call respace,$$(addsuffix .dir,$(3)))
  42.         fasm -m 65536 "$$<" "$$@" -s .deps/$(4).fas
  43.         prepsrc .deps/$(4).fas /dev/null
  44.         prepsrc .deps/$(4).fas /dev/stdout | \
  45.         perl -n -e 's|\\|/|g;s| |\\ |g;push @a,$$$$1 if/^;include\\ \x27(.*?)\x27/;' \
  46.         -e 'END{$$$$a=join " \\\n ",@a;print q`$(1): `,"$$$$a\n$$$$a:\n"}' > .deps/$(4).Po
  47. -include .deps/$(4).Po
  48. endef
  49.  
  50. progname=$(call respace,$(basename $(notdir $(call binarypart,$(f)))))
  51. binarydir=$(subst ./,,$(dir $(call binarypart,$(f))))
  52. $(foreach f,$(FASM_PROGRAMS) $(FASM_PROGRAMS_CD) $(SKIN_SOURCES),$(eval $(call fasm_meta_rule,$(fbinary),$(fsource),$(binarydir),$(progname))))
  53. $(foreach f,$(FASM_NOKPACK_PROGRAMS),$(eval $(call fasm_nokpack_meta_rule,$(fbinary),$(fsource),$(binarydir),$(progname))))
  54.  
  55. # Rule for the kernel differs: it uses kerpack instead of kpack.
  56. kernel.mnt: $(KERNEL)/kernel.asm Makefile.fasm .deps/.dir
  57.         fasm -m 65536 "$<" "$@" -s .deps/kernel.fas
  58.         prepsrc .deps/kernel.fas /dev/null
  59.         prepsrc .deps/kernel.fas /dev/stdout | \
  60.         perl -n -e 's|\\|/|g;s| |\\ |g;push @a,$$1 if/^;include\\ \x27(.*?)\x27/;' \
  61.         -e 'END{$$a=join " \\\n ",@a;print "$@: $$a\n$$a:\n"}' > .deps/kernel.Po
  62.         kerpack $@
  63. -include .deps/kernel.Po
  64.