Makefile 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 $(clean-files) $(hostprogs)
  8. clean-files := *.o lxdialog/*.o *.moc qconf-moc.cc \
  9. *conf-cfg # <- This should be removed after 23.05 is EOL
  10. # ===========================================================================
  11. # Variables needed by the upstream Makefile
  12. export HOSTPKG_CONFIG=pkg-config
  13. CONFIG_SHELL:=$(SHELL)
  14. src:=$(CURDIR)
  15. obj:=.
  16. Q:=$(if $V,,@)
  17. quiet:=$(if $V,,_silent)
  18. include Kbuild.include
  19. ### Stripped down upstream Makefile follows:
  20. # ===========================================================================
  21. # object files used by all kconfig flavours
  22. common-objs := confdata.o expr.o lexer.lex.o menu.o parser.tab.o \
  23. preprocess.o symbol.o util.o
  24. $(obj)/lexer.lex.o: $(obj)/parser.tab.h
  25. HOSTCFLAGS_lexer.lex.o := -I $(srctree)/$(src)
  26. HOSTCFLAGS_parser.tab.o := -I $(srctree)/$(src)
  27. # conf: Used for defconfig, oldconfig and related targets
  28. hostprogs += conf
  29. conf-objs := conf.o $(common-objs)
  30. # nconf: Used for the nconfig target based on ncurses
  31. hostprogs += nconf
  32. nconf-objs := nconf.o nconf.gui.o $(common-objs)
  33. HOSTLDLIBS_nconf = $(call read-file, $(obj)/nconf-libs)
  34. HOSTCFLAGS_nconf.o = $(call read-file, $(obj)/nconf-cflags)
  35. HOSTCFLAGS_nconf.gui.o = $(call read-file, $(obj)/nconf-cflags)
  36. $(obj)/nconf: | $(obj)/nconf-libs
  37. $(obj)/nconf.o $(obj)/nconf.gui.o: | $(obj)/nconf-cflags
  38. # mconf: Used for the menuconfig target based on lxdialog
  39. hostprogs += mconf
  40. lxdialog := $(addprefix lxdialog/, \
  41. checklist.o inputbox.o menubox.o textbox.o util.o yesno.o)
  42. mconf-objs := mconf.o $(lxdialog) $(common-objs)
  43. HOSTLDLIBS_mconf = $(call read-file, $(obj)/mconf-libs)
  44. $(foreach f, mconf.o $(lxdialog), \
  45. $(eval HOSTCFLAGS_$f = $$(call read-file, $(obj)/mconf-cflags)))
  46. $(obj)/mconf: | $(obj)/mconf-libs
  47. $(addprefix $(obj)/, mconf.o $(lxdialog)): | $(obj)/mconf-cflags
  48. # qconf: Used for the xconfig target based on Qt
  49. hostprogs += qconf
  50. qconf-cxxobjs := qconf.o qconf-moc.o
  51. qconf-objs := images.o $(common-objs)
  52. HOSTLDLIBS_qconf = $(call read-file, $(obj)/qconf-libs)
  53. HOSTCXXFLAGS_qconf.o = -std=c++11 -fPIC $(call read-file, $(obj)/qconf-cflags)
  54. HOSTCXXFLAGS_qconf-moc.o = -std=c++11 -fPIC $(call read-file, $(obj)/qconf-cflags)
  55. $(obj)/qconf: | $(obj)/qconf-libs
  56. $(obj)/qconf.o $(obj)/qconf-moc.o: | $(obj)/qconf-cflags
  57. quiet_cmd_moc = MOC $@
  58. cmd_moc = $(call read-file, $(obj)/qconf-bin)/moc $< -o $@
  59. $(obj)/qconf-moc.cc: $(src)/qconf.h FORCE | $(obj)/qconf-bin
  60. $(call if_changed,moc)
  61. targets += qconf-moc.cc
  62. # check if necessary packages are available, and configure build flags
  63. cmd_conf_cfg = $< $(addprefix $(obj)/$*conf-, cflags libs bin); touch $(obj)/$*conf-bin
  64. $(obj)/%conf-cflags $(obj)/%conf-libs $(obj)/%conf-bin: $(src)/%conf-cfg.sh
  65. $(call cmd,conf_cfg)
  66. clean-files += *conf-cflags *conf-libs *conf-bin
  67. # ===========================================================================
  68. # OpenWrt rules and final adjustments that need to be made after reading the
  69. # full upstream Makefile
  70. FORCE:
  71. ifdef BUILD_SHIPPED_FILES
  72. shipped-files := lexer.lex.c parser.tab.c parser.tab.h
  73. clean-files += $(shipped-files)
  74. .SECONDARY: $(shipped-files)
  75. %.tab.c %.tab.h: %.y
  76. bison -l -d -b $* $<
  77. %.lex.c: %.l
  78. flex -L -o$@ $<
  79. endif
  80. define link_rule
  81. $(1): LDLIBS+=$$(HOSTLDLIBS_$(1))
  82. $(1): $($(1)-objs) $$($(1)-cxxobjs)
  83. $(if $($(1)-cxxobjs), $(CXX) $$(LDFLAGS) -o $$@ $$^ $$(LDLIBS))
  84. all-objs += $($(1)-objs)
  85. all-cxxobjs += $($(1)-cxxobjs)
  86. endef
  87. all-objs:=
  88. all-cxxobjs:=
  89. $(foreach f,$(hostprogs),$(eval $(call link_rule,$f)))
  90. $(foreach f,$(sort $(all-objs)), \
  91. $(eval $f: CFLAGS+=$$(HOSTCFLAGS_$f)))
  92. $(foreach f,$(sort $(all-cxxobjs)), \
  93. $(eval $f: CXXFLAGS+=$$(HOSTCXXFLAGS_$f)))