Makefile 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. # SPDX-License-Identifier: GPL-2.0-only
  2. # ===========================================================================
  3. # OpenWrt configuration targets
  4. .PHONY: clean all
  5. all: conf mconf
  6. clean:
  7. rm -f *.o lxdialog/*.o *.moc $(clean-files) conf mconf qconf nconf
  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 removed or emptied when this Makefile get updated again.
  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. dot-target = $(dir $@).$(notdir $@)
  23. # taken from ../Kbuild.include
  24. define filechk
  25. $(Q)set -e; \
  26. mkdir -p $(dir $@); \
  27. trap "rm -f $(dot-target).tmp" EXIT; \
  28. { $(filechk_$(1)); } > $(dot-target).tmp; \
  29. if [ ! -r $@ ] || ! cmp -s $@ $(dot-target).tmp; then \
  30. $(kecho) ' UPD $@'; \
  31. mv -f $(dot-target).tmp $@; \
  32. fi
  33. endef
  34. ### Stripped down upstream Makefile follows:
  35. # ===========================================================================
  36. # object files used by all kconfig flavours
  37. common-objs := confdata.o expr.o lexer.lex.o parser.tab.o preprocess.o \
  38. symbol.o util.o
  39. $(obj)/lexer.lex.o: $(obj)/parser.tab.h
  40. HOSTCFLAGS_lexer.lex.o := -I $(srctree)/$(src)
  41. HOSTCFLAGS_parser.tab.o := -I $(srctree)/$(src)
  42. # conf: Used for defconfig, oldconfig and related targets
  43. hostprogs-y += conf
  44. conf-objs := conf.o $(common-objs)
  45. # nconf: Used for the nconfig target based on ncurses
  46. hostprogs-y += nconf
  47. nconf-objs := nconf.o nconf.gui.o $(common-objs)
  48. HOSTLDLIBS_nconf = $(shell . $(obj)/nconf-cfg && echo $$libs)
  49. HOSTCFLAGS_nconf.o = $(shell . $(obj)/nconf-cfg && echo $$cflags)
  50. HOSTCFLAGS_nconf.gui.o = $(shell . $(obj)/nconf-cfg && echo $$cflags)
  51. $(obj)/nconf.o $(obj)/nconf.gui.o: $(obj)/nconf-cfg
  52. # mconf: Used for the menuconfig target based on lxdialog
  53. hostprogs-y += mconf
  54. lxdialog := $(addprefix lxdialog/, \
  55. checklist.o inputbox.o menubox.o textbox.o util.o yesno.o)
  56. mconf-objs := mconf.o $(lxdialog) $(common-objs)
  57. HOSTLDLIBS_mconf = $(shell . $(obj)/mconf-cfg && echo $$libs)
  58. $(foreach f, mconf.o $(lxdialog), \
  59. $(eval HOSTCFLAGS_$f = $$(shell . $(obj)/mconf-cfg && echo $$$$cflags)))
  60. $(addprefix $(obj)/, mconf.o $(lxdialog)): $(obj)/mconf-cfg
  61. # qconf: Used for the xconfig target based on Qt
  62. hostprogs-y += qconf
  63. qconf-cxxobjs := qconf.o
  64. qconf-objs := images.o $(common-objs)
  65. HOSTLDLIBS_qconf = $(shell . $(obj)/qconf-cfg && echo $$libs)
  66. HOSTCXXFLAGS_qconf.o = $(shell . $(obj)/qconf-cfg && echo $$cflags)
  67. $(obj)/qconf.o: $(obj)/qconf-cfg $(obj)/qconf.moc
  68. quiet_cmd_moc = MOC $@
  69. cmd_moc = $(shell . $(obj)/qconf-cfg && echo $$moc) -i $< -o $@
  70. $(obj)/%.moc: $(src)/%.h $(obj)/qconf-cfg
  71. $(call cmd,moc)
  72. # check if necessary packages are available, and configure build flags
  73. filechk_conf_cfg = $(CONFIG_SHELL) $<
  74. $(obj)/%conf-cfg: $(src)/%conf-cfg.sh FORCE
  75. $(call filechk,conf_cfg)
  76. clean-files += *conf-cfg
  77. # ===========================================================================
  78. # OpenWrt rules and final adjustments that need to be made after reading the
  79. # full upstream Makefile
  80. FORCE:
  81. ifdef BUILD_SHIPPED_FILES
  82. shipped-files := lexer.lex.c parser.tab.c parser.tab.h
  83. clean-files += $(shipped-files)
  84. .SECONDARY: $(shipped-files)
  85. %.tab.c %.tab.h: %.y
  86. bison -l -d -b $* $<
  87. %.lex.c: %.l
  88. flex -L -o$@ $<
  89. endif
  90. $(foreach f, mconf.o $(lxdialog), \
  91. $(eval $f: CFLAGS+=$$(HOSTCFLAGS_$f)))
  92. $(obj)/lexer.lex.o: CFLAGS += $(HOSTCFLAGS_lexer.lex.o)
  93. $(obj)/parser.tab.o: CFLAGS += $(HOSTCFLAGS_parser.tab.o)
  94. $(obj)/qconf.o: CXXFLAGS+=$(HOSTCXXFLAGS_qconf.o)
  95. conf: $(conf-objs)
  96. # The *conf-cfg file is used (then filtered out) as the first prerequisite to
  97. # avoid sourcing it before the script is built, when trying to compute CFLAGS
  98. # for the actual first prerequisite. This avoids errors like:
  99. # '/bin/sh: ./mconf-cfg: No such file or directory'
  100. mconf: mconf-cfg $(mconf-objs)
  101. $(CC) -o $@ $(filter-out mconf-cfg,$^) $(HOSTLDLIBS_mconf)
  102. nconf: nconf-cfg $(nconf-objs)
  103. $(CC) -o $@ $(filter-out nconf-cfg,$^) $(HOSTLDLIBS_nconf)
  104. qconf: qconf-cfg $(qconf-cxxobjs) $(qconf-objs)
  105. $(CXX) -o $@ $(filter-out qconf-cfg,$^) $(HOSTLDLIBS_qconf)