Config.mk 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. ############################################################################
  2. # tools/Config.mk
  3. #
  4. # Licensed to the Apache Software Foundation (ASF) under one or more
  5. # contributor license agreements. See the NOTICE file distributed with
  6. # this work for additional information regarding copyright ownership. The
  7. # ASF licenses this file to you under the Apache License, Version 2.0 (the
  8. # "License"); you may not use this file except in compliance with the
  9. # License. You may obtain a copy of the License at
  10. #
  11. # http://www.apache.org/licenses/LICENSE-2.0
  12. #
  13. # Unless required by applicable law or agreed to in writing, software
  14. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  16. # License for the specific language governing permissions and limitations
  17. # under the License.
  18. #
  19. ############################################################################
  20. # Disable all built-in rules
  21. .SUFFIXES:
  22. ifeq ($(CONFIG_WINDOWS_NATIVE),y)
  23. export SHELL=cmd
  24. endif
  25. # Control build verbosity
  26. #
  27. # V=1,2: Enable echo of commands
  28. # V=2: Enable bug/verbose options in tools and scripts
  29. ifeq ($(V),1)
  30. export Q :=
  31. else ifeq ($(V),2)
  32. export Q :=
  33. else
  34. export Q := @
  35. endif
  36. # These are configuration variables that are quoted by configuration tool
  37. # but which must be unquoted when used in the build system.
  38. CONFIG_ARCH := $(patsubst "%",%,$(strip $(CONFIG_ARCH)))
  39. CONFIG_ARCH_CHIP := $(patsubst "%",%,$(strip $(CONFIG_ARCH_CHIP)))
  40. CONFIG_ARCH_BOARD := $(patsubst "%",%,$(strip $(CONFIG_ARCH_BOARD)))
  41. # Some defaults.
  42. # $(TOPDIR)/Make.defs can override these appropriately.
  43. MODULECC ?= $(CC)
  44. MODULELD ?= $(LD)
  45. MODULESTRIP ?= $(STRIP)
  46. # Define HOSTCC on the make command line if it differs from these defaults
  47. # Define HOSTCFLAGS with -g on the make command line to build debug versions
  48. ifeq ($(CONFIG_WINDOWS_MSYS),y)
  49. # In the Windows native environment, the MinGW GCC compiler is used
  50. HOSTCC ?= mingw32-gcc.exe
  51. HOSTCFLAGS ?= -O2 -Wall -Wstrict-prototypes -Wshadow -DCONFIG_WINDOWS_NATIVE=y
  52. else
  53. # GCC or clang is assumed in all other POSIX environments
  54. # (Linux, Cygwin, MSYS2, macOS).
  55. # strtok_r is used in some tools, but does not seem to be available in
  56. # the MinGW environment.
  57. HOSTCC ?= cc
  58. HOSTCFLAGS ?= -O2 -Wall -Wstrict-prototypes -Wshadow
  59. HOSTCFLAGS += -DHAVE_STRTOK_C=1
  60. ifeq ($(CONFIG_WINDOWS_CYGWIN),y)
  61. HOSTCFLAGS += -DHOST_CYGWIN=1
  62. endif
  63. endif
  64. # Some defaults just to prohibit some bad behavior if for some reason they
  65. # are not defined
  66. ASMEXT ?= .S
  67. OBJEXT ?= .o
  68. LIBEXT ?= .a
  69. ifeq ($(CONFIG_WINDOWS_CYGWIN),y)
  70. EXEEXT ?= .exe
  71. endif
  72. ifeq ($(CONFIG_HOST_WINDOWS),y)
  73. HOSTEXEEXT ?= .exe
  74. endif
  75. # This define is passed as EXTRAFLAGS for kernel-mode builds. It is also passed
  76. # during PASS1 (but not PASS2) context and depend targets.
  77. KDEFINE ?= ${shell $(DEFINE) "$(CC)" __KERNEL__}
  78. # DELIM - Path segment delimiter character
  79. #
  80. # Depends on this settings defined in board-specific defconfig file installed
  81. # at $(TOPDIR)/.config:
  82. #
  83. # CONFIG_WINDOWS_NATIVE - Defined for a Windows native build
  84. ifeq ($(CONFIG_WINDOWS_NATIVE),y)
  85. DELIM ?= $(strip \)
  86. else
  87. DELIM ?= $(strip /)
  88. endif
  89. # Process chip-specific directories
  90. ifeq ($(CONFIG_ARCH_CHIP_CUSTOM),y)
  91. CUSTOM_CHIP_DIR = $(patsubst "%",%,$(CONFIG_ARCH_CHIP_CUSTOM_DIR))
  92. ifeq ($(CONFIG_ARCH_CHIP_CUSTOM_DIR_RELPATH),y)
  93. CHIP_DIR ?= $(TOPDIR)$(DELIM)$(CUSTOM_CHIP_DIR)
  94. CHIP_KCONFIG = $(TOPDIR)$(DELIM)$(CUSTOM_CHIP_DIR)$(DELIM)Kconfig
  95. else
  96. CHIP_DIR ?= $(CUSTOM_CHIP_DIR)
  97. CHIP_KCONFIG = $(CUSTOM_CHIP_DIR)$(DELIM)Kconfig
  98. endif
  99. else
  100. CHIP_DIR ?= $(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)$(CONFIG_ARCH_CHIP)
  101. CHIP_KCONFIG = $(TOPDIR)$(DELIM)arch$(DELIM)dummy$(DELIM)dummy_kconfig
  102. endif
  103. # Process board-specific directories
  104. ifeq ($(CONFIG_ARCH_BOARD_CUSTOM),y)
  105. CUSTOM_DIR = $(patsubst "%",%,$(CONFIG_ARCH_BOARD_CUSTOM_DIR))
  106. ifeq ($(CONFIG_ARCH_BOARD_CUSTOM_DIR_RELPATH),y)
  107. BOARD_DIR ?= $(TOPDIR)$(DELIM)$(CUSTOM_DIR)
  108. else
  109. BOARD_DIR ?= $(CUSTOM_DIR)
  110. endif
  111. else
  112. BOARD_DIR ?= $(TOPDIR)$(DELIM)boards$(DELIM)$(CONFIG_ARCH)$(DELIM)$(CONFIG_ARCH_CHIP)$(DELIM)$(CONFIG_ARCH_BOARD)
  113. endif
  114. BOARD_COMMON_DIR ?= $(wildcard $(BOARD_DIR)$(DELIM)..$(DELIM)common)
  115. BOARD_DRIVERS_DIR ?= $(wildcard $(BOARD_DIR)$(DELIM)..$(DELIM)drivers)
  116. ifeq ($(BOARD_DRIVERS_DIR),)
  117. BOARD_DRIVERS_DIR = $(TOPDIR)$(DELIM)drivers$(DELIM)dummy
  118. endif
  119. # DIRLINK - Create a directory link in the portable way
  120. ifeq ($(CONFIG_WINDOWS_NATIVE),y)
  121. ifeq ($(CONFIG_WINDOWS_MKLINK),y)
  122. DIRLINK ?= $(TOPDIR)$(DELIM)tools$(DELIM)link.bat
  123. else
  124. DIRLINK ?= $(TOPDIR)$(DELIM)tools$(DELIM)copydir.bat
  125. endif
  126. DIRUNLINK ?= $(TOPDIR)$(DELIM)tools$(DELIM)unlink.bat
  127. else
  128. ifeq ($(CONFIG_CYGWIN_WINTOOL),y)
  129. DIRLINK ?= $(TOPDIR)$(DELIM)tools$(DELIM)copydir.sh
  130. else ifeq ($(CONFIG_WINDOWS_MSYS),y)
  131. DIRLINK ?= $(TOPDIR)$(DELIM)tools$(DELIM)copydir.sh
  132. else
  133. DIRLINK ?= $(TOPDIR)$(DELIM)tools$(DELIM)link.sh
  134. endif
  135. DIRUNLINK ?= $(TOPDIR)$(DELIM)tools$(DELIM)unlink.sh
  136. endif
  137. # MKDEP - Create the depend rule in the portable way
  138. ifeq ($(CONFIG_WINDOWS_NATIVE),y)
  139. MKDEP ?= $(TOPDIR)$(DELIM)tools$(DELIM)mkdeps$(HOSTEXEEXT) --winnative
  140. else ifeq ($(CONFIG_CYGWIN_WINTOOL),y)
  141. MKDEP ?= $(TOPDIR)$(DELIM)tools$(DELIM)mkwindeps.sh
  142. else
  143. MKDEP ?= $(TOPDIR)$(DELIM)tools$(DELIM)mkdeps$(HOSTEXEEXT)
  144. endif
  145. # Per-file dependency generation rules
  146. OBJPATH ?= .
  147. %.dds: %.S
  148. $(Q) $(MKDEP) --obj-path $(OBJPATH) --obj-suffix $(OBJEXT) $(DEPPATH) "$(CC)" -- $(CFLAGS) -- $< > $@
  149. %.ddc: %.c
  150. $(Q) $(MKDEP) --obj-path $(OBJPATH) --obj-suffix $(OBJEXT) $(DEPPATH) "$(CC)" -- $(CFLAGS) -- $< > $@
  151. %.ddp: %.cpp
  152. $(Q) $(MKDEP) --obj-path $(OBJPATH) --obj-suffix $(OBJEXT) $(DEPPATH) "$(CXX)" -- $(CXXFLAGS) -- $< > $@
  153. %.ddx: %.cxx
  154. $(Q) $(MKDEP) --obj-path $(OBJPATH) --obj-suffix $(OBJEXT) $(DEPPATH) "$(CXX)" -- $(CXXFLAGS) -- $< > $@
  155. %.ddh: %.c
  156. $(Q) $(MKDEP) --obj-path $(OBJPATH) --obj-suffix $(OBJEXT) $(DEPPATH) "$(CC)" -- $(HOSTCFLAGS) -- $< > $@
  157. # INCDIR - Convert a list of directory paths to a list of compiler include
  158. # directories
  159. # Example: CFFLAGS += ${shell $(INCDIR) [options] "compiler" "dir1" "dir2" "dir2" ...}
  160. #
  161. # Note that the compiler string and each directory path string must quoted if
  162. # they contain spaces or any other characters that might get mangled by the
  163. # shell
  164. #
  165. # Depends on this setting passed as a make command line definition from the
  166. # toplevel Makefile:
  167. #
  168. # TOPDIR - The path to the top level NuttX directory in the form
  169. # appropriate for the current build environment
  170. #
  171. # Depends on this settings defined in board-specific defconfig file installed
  172. # at $(TOPDIR)/.config:
  173. #
  174. # CONFIG_WINDOWS_NATIVE - Defined for a Windows native build
  175. ifeq ($(CONFIG_WINDOWS_NATIVE),y)
  176. DEFINE ?= "$(TOPDIR)\tools\define.bat"
  177. INCDIR ?= "$(TOPDIR)\tools\incdir.bat"
  178. else ifeq ($(CONFIG_CYGWIN_WINTOOL),y)
  179. DEFINE ?= "$(TOPDIR)/tools/define.sh" -w
  180. INCDIR ?= "$(TOPDIR)/tools/incdir$(HOSTEXEEXT)" -w
  181. else
  182. DEFINE ?= "$(TOPDIR)/tools/define.sh"
  183. INCDIR ?= "$(TOPDIR)/tools/incdir$(HOSTEXEEXT)"
  184. endif
  185. # PREPROCESS - Default macro to run the C pre-processor
  186. # Example: $(call PREPROCESS, in-file, out-file)
  187. #
  188. # Depends on these settings defined in board-specific Make.defs file
  189. # installed at $(TOPDIR)/Make.defs:
  190. #
  191. # CPP - The command to invoke the C pre-processor
  192. # CPPFLAGS - Options to pass to the C pre-processor
  193. #
  194. # '<filename>.c_CPPFLAGS += <options>' may also be used, as an example, to
  195. # change the options used with the single file <filename>.c (or
  196. # <filename>.S)
  197. define PREPROCESS
  198. @echo "CPP: $1->$2"
  199. $(Q) $(CPP) $(CPPFLAGS) $($(strip $1)_CPPFLAGS) $1 -o $2
  200. endef
  201. # COMPILE - Default macro to compile one C file
  202. # Example: $(call COMPILE, in-file, out-file)
  203. #
  204. # Depends on these settings defined in board-specific Make.defs file
  205. # installed at $(TOPDIR)/Make.defs:
  206. #
  207. # CC - The command to invoke the C compiler
  208. # CFLAGS - Options to pass to the C compiler
  209. #
  210. # '<filename>.c_CFLAGS += <options>' may also be used, as an example, to
  211. # change the options used with the single file <filename>.c
  212. define COMPILE
  213. @echo "CC: $1"
  214. $(Q) $(CC) -c $(CFLAGS) $($(strip $1)_CFLAGS) $1 -o $2
  215. endef
  216. # COMPILEXX - Default macro to compile one C++ file
  217. # Example: $(call COMPILEXX, in-file, out-file)
  218. #
  219. # Depends on these settings defined in board-specific Make.defs file
  220. # installed at $(TOPDIR)/Make.defs:
  221. #
  222. # CXX - The command to invoke the C++ compiler
  223. # CXXFLAGS - Options to pass to the C++ compiler
  224. #
  225. # '<filename>.cxx_CXXFLAGS += <options>' may also be used, as an example, to
  226. # change the options used with the single file <filename>.cxx. The
  227. # extension .cpp could also be used. The same applies mutatis mutandis.
  228. define COMPILEXX
  229. @echo "CXX: $1"
  230. $(Q) $(CXX) -c $(CXXFLAGS) $($(strip $1)_CXXFLAGS) $1 -o $2
  231. endef
  232. # ASSEMBLE - Default macro to assemble one assembly language file
  233. # Example: $(call ASSEMBLE, in-file, out-file)
  234. #
  235. # NOTE that the most common toolchain, GCC, uses the compiler to assemble
  236. # files because this has the advantage of running the C Pre-Processor against
  237. # the assembly language files. This is not possible with other toolchains;
  238. # platforms using those other tools should define AS and over-ride this
  239. # definition in order to use the assembler directly.
  240. #
  241. # Depends on these settings defined in board-specific Make.defs file
  242. # installed at $(TOPDIR)/Make.defs:
  243. #
  244. # CC - By default, the C compiler is used to compile assembly language
  245. # files
  246. # AFLAGS - Options to pass to the C+compiler
  247. #
  248. # '<filename>.s_AFLAGS += <options>' may also be used, as an example, to change
  249. # the options used with the single file <filename>.s. The extension .asm
  250. # is used by some toolchains. The same applies mutatis mutandis.
  251. define ASSEMBLE
  252. @echo "AS: $1"
  253. $(Q) $(CC) -c $(AFLAGS) $1 $($(strip $1)_AFLAGS) -o $2
  254. endef
  255. # INSTALL_LIB - Install a library $1 into target $2
  256. # Example: $(call INSTALL_LIB, libabc.a, $(TOPDIR)/staging/)
  257. define INSTALL_LIB
  258. @echo "IN: $1 -> $2"
  259. $(Q) install -m 0644 $1 $2
  260. endef
  261. # ARCHIVE_ADD - Add a list of files to an archive
  262. # Example: $(call ARCHIVE_ADD, archive-file, "file1 file2 file3 ...")
  263. #
  264. # Note: The fileN strings may not contain spaces or characters that may be
  265. # interpreted strangely by the shell
  266. #
  267. # Depends on these settings defined in board-specific Make.defs file
  268. # installed at $(TOPDIR)/Make.defs:
  269. #
  270. # AR - The command to invoke the archiver (includes any options)
  271. #
  272. # Depends on this settings defined in board-specific defconfig file installed
  273. # at $(TOPDIR)/.config:
  274. #
  275. # CONFIG_WINDOWS_NATIVE - Defined for a Windows native build
  276. define ARCHIVE_ADD
  277. @echo "AR (add): ${shell basename $(1)} $(2)"
  278. $(Q) $(AR) $1 $(2)
  279. endef
  280. # ARCHIVE - Same as above, but ensure the archive is
  281. # created from scratch
  282. define ARCHIVE
  283. @echo "AR (create): ${shell basename $(1)} $(2)"
  284. $(Q) $(RM) $1
  285. $(Q) $(AR) $1 $(2)
  286. endef
  287. # PRELINK - Prelink a list of files
  288. # This is useful when files were compiled with fvisibility=hidden.
  289. # Any symbol which was not explicitly made global is invisible outside the
  290. # prelinked file.
  291. #
  292. # Example: $(call PRELINK, prelink-file, "file1 file2 file3 ...")
  293. #
  294. # Note: The fileN strings may not contain spaces or characters that may be
  295. # interpreted strangely by the shell
  296. #
  297. # Depends on these settings defined in board-specific Make.defs file
  298. # installed at $(TOPDIR)/Make.defs:
  299. #
  300. # LD - The command to invoke the linker (includes any options)
  301. # OBJCOPY - The command to invoke the object cop (includes any options)
  302. #
  303. # Depends on this settings defined in board-specific defconfig file installed
  304. # at $(TOPDIR)/.config:
  305. #
  306. # CONFIG_WINDOWS_NATIVE - Defined for a Windows native build
  307. ifeq ($(CONFIG_WINDOWS_NATIVE),y)
  308. define PRELINK
  309. @echo PRELINK: $1
  310. $(Q) $(LD) -Ur -o $1 $2 && $(OBJCOPY) --localize-hidden $1
  311. endef
  312. else
  313. define PRELINK
  314. @echo "PRELINK: $1"
  315. $(Q) $(LD) -Ur -o $1 $2 && $(OBJCOPY) --localize-hidden $1
  316. endef
  317. endif
  318. # POSTBUILD -- Perform post build operations
  319. # Some architectures require the use of special tools and special handling
  320. # AFTER building the NuttX binary. Make.defs files for those architectures
  321. # should override the following define with the correct operations for
  322. # that platform
  323. define POSTBUILD
  324. endef
  325. # DELFILE - Delete one file
  326. ifeq ($(CONFIG_WINDOWS_NATIVE),y)
  327. define DELFILE
  328. $(Q) if exist $1 (del /f /q $1)
  329. endef
  330. else
  331. define DELFILE
  332. $(Q) rm -f $1
  333. endef
  334. endif
  335. # DELDIR - Delete one directory
  336. ifeq ($(CONFIG_WINDOWS_NATIVE),y)
  337. define DELDIR
  338. $(Q) if exist $1 (rmdir /q /s $1)
  339. endef
  340. else
  341. define DELDIR
  342. $(Q) rm -rf $1
  343. endef
  344. endif
  345. # MOVEFILE - Move one file
  346. ifeq ($(CONFIG_WINDOWS_NATIVE),y)
  347. define MOVEFILE
  348. $(Q) if exist $1 (move /Y $1 $2)
  349. endef
  350. else
  351. define MOVEFILE
  352. $(Q) mv -f $1 $2
  353. endef
  354. endif
  355. # COPYFILE - Copy one file
  356. ifeq ($(CONFIG_WINDOWS_NATIVE),y)
  357. define COPYFILE
  358. $(Q) if exist $1 (copy /y /b $1 $2)
  359. endef
  360. else
  361. define COPYFILE
  362. $(Q) cp -f $1 $2
  363. endef
  364. endif
  365. # CATFILE - Cat a list of files
  366. #
  367. # USAGE: $(call CATFILE,dest,src1,src2,src3,...)
  368. ifeq ($(CONFIG_WINDOWS_NATIVE),y)
  369. define CATFILE
  370. $(Q) type $(2) > $1
  371. endef
  372. else
  373. define CATFILE
  374. $(Q) if [ -z "$(strip $(2))" ]; then echo '' > $(1); else cat $(2) > $1; fi
  375. endef
  376. endif
  377. # RWILDCARD - Recursive wildcard used to get lists of files from directories
  378. #
  379. # USAGE: FILELIST = $(call RWILDCARD,<dir>,<wildcard-filename)
  380. #
  381. # This is functionally equivalent to the following, but has the advantage in
  382. # that it is portable
  383. #
  384. # FILELIST = ${shell find <dir> -name <wildcard-file>}
  385. define RWILDCARD
  386. $(foreach d,$(wildcard $1/*),$(call RWILDCARD,$d,$2)$(filter $(subst *,%,$2),$d))
  387. endef
  388. # CLEAN - Default clean target
  389. ifeq ($(CONFIG_WINDOWS_NATIVE),y)
  390. define CLEAN
  391. $(Q) if exist *$(OBJEXT) (del /f /q *$(OBJEXT))
  392. $(Q) if exist *$(LIBEXT) (del /f /q *$(LIBEXT))
  393. $(Q) if exist *~ (del /f /q *~)
  394. $(Q) if exist (del /f /q .*.swp)
  395. $(Q) if exist $(OBJS) (del /f /q $(OBJS))
  396. $(Q) if exist $(BIN) (del /f /q $(BIN))
  397. endef
  398. else
  399. define CLEAN
  400. $(Q) rm -f *$(OBJEXT) *$(LIBEXT) *~ .*.swp $(OBJS) $(BIN)
  401. endef
  402. endif
  403. # TESTANDREPLACEFILE - Test if two files are different. If so replace the
  404. # second with the first. Otherwise, delete the first.
  405. #
  406. # USAGE: $(call TESTANDREPLACEFILE, newfile, oldfile)
  407. #
  408. # args: $1 - newfile: Temporary file to test
  409. # $2 - oldfile: File to replace
  410. ifeq ($(CONFIG_WINDOWS_NATIVE),y)
  411. define TESTANDREPLACEFILE
  412. $(Q) move /Y $1 $2
  413. endef
  414. else
  415. define TESTANDREPLACEFILE
  416. if [ -f $2 ]; then \
  417. if cmp $1 $2; then \
  418. rm -f $1; \
  419. else \
  420. mv $1 $2; \
  421. fi \
  422. else \
  423. mv $1 $2; \
  424. fi
  425. endef
  426. endif
  427. # Invoke make
  428. define MAKE_template
  429. +$(Q) $(MAKE) -C $(1) $(2) APPDIR="$(APPDIR)"
  430. endef
  431. define SDIR_template
  432. $(1)_$(2):
  433. +$(Q) $(MAKE) -C $(1) $(2) APPDIR="$(APPDIR)"
  434. endef
  435. # ARCHxxx means the predefined setting(either toolchain, arch, or system specific)
  436. ARCHDEFINES += ${shell $(DEFINE) "$(CC)" __NuttX__}
  437. # The default C/C++ search path
  438. ARCHINCLUDES += ${shell $(INCDIR) -s "$(CC)" $(TOPDIR)$(DELIM)include}
  439. ifeq ($(CONFIG_LIBCXX),y)
  440. ARCHXXINCLUDES += ${shell $(INCDIR) -s "$(CC)" $(TOPDIR)$(DELIM)include$(DELIM)libcxx}
  441. else ifeq ($(CONFIG_UCLIBCXX),y)
  442. ARCHXXINCLUDES += ${shell $(INCDIR) -s "$(CC)" $(TOPDIR)$(DELIM)include$(DELIM)uClibc++}
  443. else
  444. ARCHXXINCLUDES += ${shell $(INCDIR) -s "$(CC)" $(TOPDIR)$(DELIM)include$(DELIM)cxx}
  445. endif
  446. ARCHXXINCLUDES += ${shell $(INCDIR) -s "$(CC)" $(TOPDIR)$(DELIM)include}