1
0

Makefile 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. # SPDX-License-Identifier: GPL-2.0-only
  2. # ===========================================================================
  3. # libreCMC configuration targets
  4. .PHONY: clean all
  5. all: conf mconf
  6. clean:
  7. rm -f *.o lxdialog/*.o *.moc .*.cmd $(clean-files)
  8. # This clean-files definition is here to ensure that temporary files from the
  9. # previous version are removed by make config-clean.
  10. # It should be emptied after the end of support for libreCMC 19.07.
  11. clean-files := zconf.tab.c zconf.lex.c zconf.hash.c .tmp_qtcheck
  12. # ===========================================================================
  13. # Variables needed by the upstream Makefile
  14. # Avoids displaying 'UPD mconf-cfg' in an otherwise quiet make menuconfig
  15. kecho:=true
  16. CONFIG_SHELL:=$(SHELL)
  17. srctree:=.
  18. src:=.
  19. obj:=.
  20. Q:=$(if $V,,@)
  21. cmd = $(cmd_$(1))
  22. # some definitions taken from ../Kbuild.include
  23. dot-target = $(dir $@).$(notdir $@)
  24. squote := '
  25. escsq = $(subst $(squote),'\$(squote)',$1)
  26. define filechk
  27. $(Q)set -e; \
  28. mkdir -p $(dir $@); \
  29. trap "rm -f $(dot-target).tmp" EXIT; \
  30. { $(filechk_$(1)); } > $(dot-target).tmp; \
  31. if [ ! -r $@ ] || ! cmp -s $@ $(dot-target).tmp; then \
  32. $(kecho) ' UPD $@'; \
  33. mv -f $(dot-target).tmp $@; \
  34. fi
  35. endef
  36. cmd-check = $(if $(strip $(cmd_$@)),,1)
  37. make-cmd = $(call escsq,$(subst $(pound),$$(pound),$(subst $$,$$$$,$(cmd_$(1)))))
  38. newer-prereqs = $(filter-out $(PHONY),$?)
  39. if_changed = $(if $(newer-prereqs)$(cmd-check), \
  40. $(cmd); \
  41. printf '%s\n' 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd, @:)
  42. ### Stripped down upstream Makefile follows:
  43. # ===========================================================================
  44. # object files used by all kconfig flavours
  45. common-objs := confdata.o expr.o lexer.lex.o menu.o parser.tab.o \
  46. preprocess.o symbol.o util.o
  47. $(obj)/lexer.lex.o: $(obj)/parser.tab.h
  48. HOSTCFLAGS_lexer.lex.o := -I $(srctree)/$(src)
  49. HOSTCFLAGS_parser.tab.o := -I $(srctree)/$(src)
  50. # conf: Used for defconfig, oldconfig and related targets
  51. hostprogs += conf
  52. conf-objs := conf.o $(common-objs)
  53. # nconf: Used for the nconfig target based on ncurses
  54. hostprogs += nconf
  55. nconf-objs := nconf.o nconf.gui.o $(common-objs)
  56. HOSTLDLIBS_nconf = $(shell . $(obj)/nconf-cfg && echo $$libs)
  57. HOSTCFLAGS_nconf.o = $(shell . $(obj)/nconf-cfg && echo $$cflags)
  58. HOSTCFLAGS_nconf.gui.o = $(shell . $(obj)/nconf-cfg && echo $$cflags)
  59. $(obj)/nconf.o $(obj)/nconf.gui.o: $(obj)/nconf-cfg
  60. # mconf: Used for the menuconfig target based on lxdialog
  61. hostprogs += mconf
  62. lxdialog := $(addprefix lxdialog/, \
  63. checklist.o inputbox.o menubox.o textbox.o util.o yesno.o)
  64. mconf-objs := mconf.o $(lxdialog) $(common-objs)
  65. HOSTLDLIBS_mconf = $(shell . $(obj)/mconf-cfg && echo $$libs)
  66. $(foreach f, mconf.o $(lxdialog), \
  67. $(eval HOSTCFLAGS_$f = $$(shell . $(obj)/mconf-cfg && echo $$$$cflags)))
  68. $(addprefix $(obj)/, mconf.o $(lxdialog)): $(obj)/mconf-cfg
  69. # qconf: Used for the xconfig target based on Qt
  70. hostprogs += qconf
  71. qconf-cxxobjs := qconf.o qconf-moc.o
  72. qconf-objs := images.o $(common-objs)
  73. HOSTLDLIBS_qconf = $(shell . $(obj)/qconf-cfg && echo $$libs)
  74. HOSTCXXFLAGS_qconf.o = $(shell . $(obj)/qconf-cfg && echo $$cflags)
  75. HOSTCXXFLAGS_qconf-moc.o = $(shell . $(obj)/qconf-cfg && echo $$cflags)
  76. $(obj)/qconf.o: $(obj)/qconf-cfg
  77. quiet_cmd_moc = MOC $@
  78. cmd_moc = $(shell . $(obj)/qconf-cfg && echo $$moc) $< -o $@
  79. $(obj)/qconf-moc.cc: $(src)/qconf.h $(obj)/qconf-cfg FORCE
  80. $(call if_changed,moc)
  81. targets += qconf-moc.cc
  82. # check if necessary packages are available, and configure build flags
  83. filechk_conf_cfg = $(CONFIG_SHELL) $<
  84. $(obj)/%conf-cfg: $(src)/%conf-cfg.sh FORCE
  85. $(call filechk,conf_cfg)
  86. clean-files += *conf-cfg
  87. # ===========================================================================
  88. # libreCMC rules and final adjustments that need to be made after reading the
  89. # full upstream Makefile
  90. clean-files += $(targets) $(hostprogs)
  91. FORCE:
  92. ifdef BUILD_SHIPPED_FILES
  93. shipped-files := lexer.lex.c parser.tab.c parser.tab.h
  94. clean-files += $(shipped-files)
  95. .SECONDARY: $(shipped-files)
  96. %.tab.c %.tab.h: %.y
  97. bison -l -d -b $* $<
  98. %.lex.c: %.l
  99. flex -L -o$@ $<
  100. endif
  101. $(foreach f,$(conf-objs) $(filter-out $(common-objs),$(mconf-objs) \
  102. $(qconf-objs) \
  103. $(nconf-objs)), \
  104. $(eval $(obj)/$f: CFLAGS+=$$(HOSTCFLAGS_$f)))
  105. $(foreach f,$(qconf-cxxobjs), \
  106. $(eval $(obj)/$f: CXXFLAGS+=$$(HOSTCXXFLAGS_$f)))
  107. $(obj)/conf: $(addprefix $(obj)/,$(conf-objs))
  108. # The *conf-cfg file is used (then filtered out) as the first prerequisite to
  109. # avoid sourcing it before the script is built, when trying to compute CFLAGS
  110. # for the actual first prerequisite. This avoids errors like:
  111. # '/bin/sh: ./mconf-cfg: No such file or directory'
  112. $(obj)/mconf: mconf-cfg $(addprefix $(obj)/,$(mconf-objs))
  113. $(CC) -o $@ $(filter-out mconf-cfg,$^) $(HOSTLDLIBS_mconf)
  114. $(obj)/nconf: nconf-cfg $(addprefix $(obj)/,$(nconf-objs))
  115. $(CC) -o $@ $(filter-out nconf-cfg,$^) $(HOSTLDLIBS_nconf)
  116. $(obj)/qconf: qconf-cfg $(addprefix $(obj)/,$(qconf-cxxobjs) $(qconf-objs))
  117. $(CXX) -o $@ $(filter-out qconf-cfg,$^) $(HOSTLDLIBS_qconf)