Makefile 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. # SPDX-License-Identifier: GPL-2.0
  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
  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. # mconf: Used for the menuconfig target based on lxdialog
  46. hostprogs-y += mconf
  47. lxdialog := $(addprefix lxdialog/, \
  48. checklist.o inputbox.o menubox.o textbox.o util.o yesno.o)
  49. mconf-objs := mconf.o $(lxdialog) $(common-objs)
  50. HOSTLDLIBS_mconf = $(shell . $(obj)/mconf-cfg && echo $$libs)
  51. $(foreach f, mconf.o $(lxdialog), \
  52. $(eval HOSTCFLAGS_$f = $$(shell . $(obj)/mconf-cfg && echo $$$$cflags)))
  53. $(addprefix $(obj)/, mconf.o $(lxdialog)): $(obj)/mconf-cfg
  54. # qconf: Used for the xconfig target based on Qt
  55. hostprogs-y += qconf
  56. qconf-cxxobjs := qconf.o
  57. qconf-objs := images.o $(common-objs)
  58. HOSTLDLIBS_qconf = $(shell . $(obj)/qconf-cfg && echo $$libs)
  59. HOSTCXXFLAGS_qconf.o = $(shell . $(obj)/qconf-cfg && echo $$cflags)
  60. $(obj)/qconf.o: $(obj)/qconf-cfg $(obj)/qconf.moc
  61. quiet_cmd_moc = MOC $@
  62. cmd_moc = $(shell . $(obj)/qconf-cfg && echo $$moc) -i $< -o $@
  63. $(obj)/%.moc: $(src)/%.h $(obj)/qconf-cfg
  64. $(call cmd,moc)
  65. # check if necessary packages are available, and configure build flags
  66. filechk_conf_cfg = $(CONFIG_SHELL) $<
  67. $(obj)/%conf-cfg: $(src)/%conf-cfg.sh FORCE
  68. $(call filechk,conf_cfg)
  69. clean-files += *conf-cfg
  70. # ===========================================================================
  71. # OpenWrt rules and final adjustments that need to be made after reading the
  72. # full upstream Makefile
  73. FORCE:
  74. ifdef BUILD_SHIPPED_FILES
  75. shipped-files := lexer.lex.c parser.tab.c parser.tab.h
  76. clean-files += $(shipped-files)
  77. .SECONDARY: $(shipped-files)
  78. %.tab.c %.tab.h: %.y
  79. bison -l -d -b $* $<
  80. %.lex.c: %.l
  81. flex -L -o$@ $<
  82. endif
  83. $(foreach f, mconf.o $(lxdialog), \
  84. $(eval $f: CFLAGS+=$$(HOSTCFLAGS_$f)))
  85. $(obj)/lexer.lex.o: CFLAGS += $(HOSTCFLAGS_lexer.lex.o)
  86. $(obj)/parser.tab.o: CFLAGS += $(HOSTCFLAGS_parser.tab.o)
  87. $(obj)/qconf.o: CXXFLAGS+=$(HOSTCXXFLAGS_qconf.o)
  88. conf: $(conf-objs)
  89. # The *conf-cfg file is used (then filtered out) as the first prerequisite to
  90. # avoid sourcing it before the script is built, when trying to compute CFLAGS
  91. # for the actual first prerequisite. This avoids errors like:
  92. # '/bin/sh: ./mconf-cfg: No such file or directory'
  93. mconf: mconf-cfg $(mconf-objs)
  94. $(CC) -o $@ $(filter-out mconf-cfg,$^) $(HOSTLDLIBS_mconf)
  95. qconf: qconf-cfg $(qconf-cxxobjs) $(qconf-objs)
  96. $(CXX) -o $@ $(filter-out qconf-cfg,$^) $(HOSTLDLIBS_qconf)