diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index abfe8d8c..1aa20fed 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -47,8 +47,7 @@ jobs: shell: bash - name: default build run: | - tools/kconfig/defconfig.py --kconfig configs/Kconfig configs/defconfig - tools/kconfig/genconfig.py configs/Kconfig + make defconfig make coding-style: diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..f3adb532 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "tools/kconfig"] + path = tools/kconfig + url = https://github.com/sysprog21/Kconfiglib diff --git a/Makefile b/Makefile index 8c59ca3d..7ade89f8 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,18 @@ +# Ensure tools/kconfig submodule is initialized +ifeq ($(wildcard tools/kconfig/menuconfig.py),) + $(shell git submodule update --init tools/kconfig) +endif + -include .config check_goal := $(strip $(MAKECMDGOALS)) -ifneq ($(check_goal), config) -ifneq "$(CONFIG_CONFIGURED)" "y" -$(error You must first run 'make config') -endif +ifeq ($(filter $(check_goal),config defconfig),) + ifneq "$(CONFIG_CONFIGURED)" "y" + $(error You must first run 'make config' or 'make defconfig') + endif endif -# Rules +# Target variables initialization target-y := target.o-y := @@ -58,11 +63,12 @@ libtwin.a_includes-y := \ include \ src -# Features +# Optional features + libtwin.a_files-$(CONFIG_LOGGING) += src/log.c libtwin.a_files-$(CONFIG_CURSOR) += src/cursor.c -# Renderer +# Rendering backends libtwin.a_files-$(CONFIG_RENDERER_BUILTIN) += src/draw-builtin.c libtwin.a_files-$(CONFIG_RENDERER_PIXMAN) += src/draw-pixman.c libtwin.a_cflags-$(CONFIG_RENDERER_PIXMAN) += $(shell pkg-config --cflags pixman-1) @@ -156,29 +162,43 @@ demo-$(BACKEND)_ldflags-y := \ $(TARGET_LIBS) endif +# Font editor tool + ifeq ($(CONFIG_TOOLS), y) target-$(CONFIG_TOOL_FONTEDIT) += font-edit font-edit_files-y = \ - tools/font-edit/sfit.c \ - tools/font-edit/font-edit.c + tools/font-edit/sfit.c \ + tools/font-edit/font-edit.c font-edit_includes-y := tools/font-edit font-edit_cflags-y := \ - $(shell pkg-config --cflags cairo) \ - $(shell sdl2-config --cflags) + $(shell pkg-config --cflags cairo) \ + $(shell sdl2-config --cflags) font-edit_ldflags-y := \ - $(shell pkg-config --libs cairo) \ - $(shell sdl2-config --libs) + $(shell pkg-config --libs cairo) \ + $(shell sdl2-config --libs) endif +# Build system integration + CFLAGS += -include config.h -check_goal := $(strip $(MAKECMDGOALS)) -ifneq ($(check_goal), config) +# Only include build rules when not running configuration targets +ifeq ($(filter $(check_goal),config defconfig),) include mk/common.mk endif -# Menuconfig +KCONFIGLIB := tools/kconfig/kconfiglib.py +$(KCONFIGLIB): + git submodule update --init tools/kconfig + +# Load default configuration +.PHONY: defconfig +defconfig: $(KCONFIGLIB) + @tools/kconfig/defconfig.py --kconfig configs/Kconfig configs/defconfig + @tools/kconfig/genconfig.py configs/Kconfig + +# Interactive configuration .PHONY: config -config: configs/Kconfig - @tools/kconfig/menuconfig.py $< - @tools/kconfig/genconfig.py $< +config: $(KCONFIGLIB) configs/Kconfig + @tools/kconfig/menuconfig.py configs/Kconfig + @tools/kconfig/genconfig.py configs/Kconfig diff --git a/configs/Kconfig b/configs/Kconfig index c8c49b39..f69e20f7 100644 --- a/configs/Kconfig +++ b/configs/Kconfig @@ -4,6 +4,19 @@ config CONFIGURED bool default y +# Dependency detection using Kbuild toolchain functions +config HAVE_SDL2 + def_bool $(success,pkg-config --exists sdl2) + +config HAVE_PIXMAN + def_bool $(success,pkg-config --exists pixman-1) + +config HAVE_LIBPNG + def_bool $(success,pkg-config --exists libpng) + +config HAVE_LIBJPEG + def_bool $(success,pkg-config --exists libjpeg) + choice prompt "Backend Selection" default BACKEND_SDL @@ -14,6 +27,7 @@ config BACKEND_FBDEV config BACKEND_SDL bool "SDL video output support" + depends on HAVE_SDL2 config BACKEND_VNC bool "VNC server output support" @@ -28,6 +42,7 @@ config RENDERER_BUILTIN config RENDERER_PIXMAN bool "Pixman based rendering" + depends on HAVE_PIXMAN endchoice @@ -83,10 +98,12 @@ menu "Image Loaders" config LOADER_PNG bool "Enable PNG loader" + depends on HAVE_LIBPNG default y config LOADER_JPEG bool "Enable JPEG loader" + depends on HAVE_LIBJPEG default y config LOADER_GIF @@ -131,7 +148,7 @@ config DEMO_LINE depends on DEMO_APPLICATIONS config DEMO_SPLINE - bool "Build spline demp" + bool "Build spline demo" default y depends on DEMO_APPLICATIONS diff --git a/mk/common.mk b/mk/common.mk index 4bd99bbc..6ffb3c95 100644 --- a/mk/common.mk +++ b/mk/common.mk @@ -678,6 +678,17 @@ clean: __FORCE __FORCE: @true -ifneq "$(MAKECMDGOALS)" "clean" --include $(target-depends) +# Only include dependencies when building known targets +build-goals := all clean $(target-builds) +ifneq ($(MAKECMDGOALS),) + # MAKECMDGOALS is not empty, check if it's a known target + ifneq ($(filter $(MAKECMDGOALS),$(build-goals)),) + # Known target, include dependencies (except for clean) + ifneq "$(MAKECMDGOALS)" "clean" + -include $(target-depends) + endif + endif +else + # Empty MAKECMDGOALS means building 'all', include dependencies + -include $(target-depends) endif diff --git a/tools/kconfig b/tools/kconfig new file mode 160000 index 00000000..e1f15e3d --- /dev/null +++ b/tools/kconfig @@ -0,0 +1 @@ +Subproject commit e1f15e3dc771a1631b7764a2425d9ab2b8243cd0 diff --git a/tools/kconfig/.gitignore b/tools/kconfig/.gitignore deleted file mode 100644 index 4a18d79f..00000000 --- a/tools/kconfig/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -*.py[co] -build/ -*.egg-info/ -dist/ diff --git a/tools/kconfig/LICENSE b/tools/kconfig/LICENSE deleted file mode 100644 index 94fc9772..00000000 --- a/tools/kconfig/LICENSE +++ /dev/null @@ -1,13 +0,0 @@ -Copyright (c) 2011-2019, Ulf Magnusson - -Permission to use, copy, modify, and/or distribute this software for any purpose -with or without fee is hereby granted, provided that the above copyright notice -and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH -REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND -FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, -INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS -OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER -TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF -THIS SOFTWARE. diff --git a/tools/kconfig/README.md b/tools/kconfig/README.md deleted file mode 100644 index 6ff921b7..00000000 --- a/tools/kconfig/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# Kconfiglib - -A flexible Python 2/3 Kconfig implementation and library. - -Taken from https://github.com/ulfalizer/Kconfiglib diff --git a/tools/kconfig/defconfig.py b/tools/kconfig/defconfig.py deleted file mode 100755 index b1792731..00000000 --- a/tools/kconfig/defconfig.py +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env python3 - -# Copyright (c) 2019, Ulf Magnusson -# SPDX-License-Identifier: ISC - -""" -Reads a specified configuration file, then writes a new configuration file. -This can be used to initialize the configuration from e.g. an arch-specific -configuration file. This input configuration file would usually be a minimal -configuration file, as generated by e.g. savedefconfig. - -The default output filename is '.config'. A different filename can be passed in -the KCONFIG_CONFIG environment variable. -""" -import argparse - -import kconfiglib - - -def main(): - parser = argparse.ArgumentParser( - formatter_class=argparse.RawDescriptionHelpFormatter, - description=__doc__) - - parser.add_argument( - "--kconfig", - default="Kconfig", - help="Top-level Kconfig file (default: Kconfig)") - - parser.add_argument( - "config", - metavar="CONFIGURATION", - help="Input configuration file") - - args = parser.parse_args() - - kconf = kconfiglib.Kconfig(args.kconfig, suppress_traceback=True) - print(kconf.load_config(args.config)) - print(kconf.write_config()) - - -if __name__ == "__main__": - main() diff --git a/tools/kconfig/genconfig.py b/tools/kconfig/genconfig.py deleted file mode 100755 index 62f065ba..00000000 --- a/tools/kconfig/genconfig.py +++ /dev/null @@ -1,154 +0,0 @@ -#!/usr/bin/env python3 - -# Copyright (c) 2018-2019, Ulf Magnusson -# SPDX-License-Identifier: ISC - -""" -Generates a header file with #defines from the configuration, matching the -format of include/generated/autoconf.h in the Linux kernel. - -Optionally, also writes the configuration output as a .config file. See ---config-out. - -The --sync-deps, --file-list, and --env-list options generate information that -can be used to avoid needless rebuilds/reconfigurations. - -Before writing a header or configuration file, Kconfiglib compares the old -contents of the file against the new contents. If there's no change, the write -is skipped. This avoids updating file metadata like the modification time, and -might save work depending on your build setup. - -By default, the configuration is generated from '.config'. A different -configuration file can be passed in the KCONFIG_CONFIG environment variable. - -A custom header string can be inserted at the beginning of generated -configuration and header files by setting the KCONFIG_CONFIG_HEADER and -KCONFIG_AUTOHEADER_HEADER environment variables, respectively (this also works -for other scripts). The string is not automatically made a comment (this is by -design, to allow anything to be added), and no trailing newline is added, so -add '/* */', '#', and newlines as appropriate. - -See https://www.gnu.org/software/make/manual/make.html#Multi_002dLine for a -handy way to define multi-line variables in makefiles, for use with custom -headers. Remember to export the variable to the environment. -""" -import argparse -import os -import sys - -import kconfiglib - - -DEFAULT_SYNC_DEPS_PATH = "deps/" - - -def main(): - parser = argparse.ArgumentParser( - formatter_class=argparse.RawDescriptionHelpFormatter, - description=__doc__) - - parser.add_argument( - "--header-path", - metavar="HEADER_FILE", - help=""" -Path to write the generated header file to. If not specified, the path in the -environment variable KCONFIG_AUTOHEADER is used if it is set, and 'config.h' -otherwise. -""") - - parser.add_argument( - "--config-out", - metavar="CONFIG_FILE", - help=""" -Write the configuration to CONFIG_FILE. This is useful if you include .config -files in Makefiles, as the generated configuration file will be a full .config -file even if .config is outdated. The generated configuration matches what -olddefconfig would produce. If you use sync-deps, you can include -deps/auto.conf instead. --config-out is meant for cases where incremental build -information isn't needed. -""") - - parser.add_argument( - "--sync-deps", - metavar="OUTPUT_DIR", - nargs="?", - const=DEFAULT_SYNC_DEPS_PATH, - help=""" -Enable generation of symbol dependency information for incremental builds, -optionally specifying the output directory (default: {}). See the docstring of -Kconfig.sync_deps() in Kconfiglib for more information. -""".format(DEFAULT_SYNC_DEPS_PATH)) - - parser.add_argument( - "--file-list", - metavar="OUTPUT_FILE", - help=""" -Write a list of all Kconfig files to OUTPUT_FILE, with one file per line. The -paths are relative to $srctree (or to the current directory if $srctree is -unset). Files appear in the order they're 'source'd. -""") - - parser.add_argument( - "--env-list", - metavar="OUTPUT_FILE", - help=""" -Write a list of all environment variables referenced in Kconfig files to -OUTPUT_FILE, with one variable per line. Each line has the format NAME=VALUE. -Only environment variables referenced with the preprocessor $(VAR) syntax are -included, and not variables referenced with the older $VAR syntax (which is -only supported for backwards compatibility). -""") - - parser.add_argument( - "kconfig", - metavar="KCONFIG", - nargs="?", - default="Kconfig", - help="Top-level Kconfig file (default: Kconfig)") - - args = parser.parse_args() - - - kconf = kconfiglib.Kconfig(args.kconfig, suppress_traceback=True) - kconf.load_config() - - if args.header_path is None: - if "KCONFIG_AUTOHEADER" in os.environ: - kconf.write_autoconf() - else: - # Kconfiglib defaults to include/generated/autoconf.h to be - # compatible with the C tools. 'config.h' is used here instead for - # backwards compatibility. It's probably a saner default for tools - # as well. - kconf.write_autoconf("config.h") - else: - kconf.write_autoconf(args.header_path) - - if args.config_out is not None: - kconf.write_config(args.config_out, save_old=False) - - if args.sync_deps is not None: - kconf.sync_deps(args.sync_deps) - - if args.file_list is not None: - with _open_write(args.file_list) as f: - for path in kconf.kconfig_filenames: - f.write(path + "\n") - - if args.env_list is not None: - with _open_write(args.env_list) as f: - for env_var in kconf.env_vars: - f.write("{}={}\n".format(env_var, os.environ[env_var])) - - -def _open_write(path): - # Python 2/3 compatibility. io.open() is available on both, but makes - # write() expect 'unicode' strings on Python 2. - - if sys.version_info[0] < 3: - return open(path, "w") - return open(path, "w", encoding="utf-8") - - -if __name__ == "__main__": - main() diff --git a/tools/kconfig/kconfiglib.py b/tools/kconfig/kconfiglib.py deleted file mode 100644 index 9a0aae46..00000000 --- a/tools/kconfig/kconfiglib.py +++ /dev/null @@ -1,7209 +0,0 @@ -# Copyright (c) 2011-2019, Ulf Magnusson -# SPDX-License-Identifier: ISC - -""" -Overview -======== - -Kconfiglib is a Python 2/3 library for scripting and extracting information -from Kconfig (https://www.kernel.org/doc/Documentation/kbuild/kconfig-language.txt) -configuration systems. - -See the homepage at https://github.com/ulfalizer/Kconfiglib for a longer -overview. - -Since Kconfiglib 12.0.0, the library version is available in -kconfiglib.VERSION, which is a (, , ) tuple, e.g. -(12, 0, 0). - - -Using Kconfiglib on the Linux kernel with the Makefile targets -============================================================== - -For the Linux kernel, a handy interface is provided by the -scripts/kconfig/Makefile patch, which can be applied with either 'git am' or -the 'patch' utility: - - $ wget -qO- https://raw.githubusercontent.com/ulfalizer/Kconfiglib/master/makefile.patch | git am - $ wget -qO- https://raw.githubusercontent.com/ulfalizer/Kconfiglib/master/makefile.patch | patch -p1 - -Warning: Not passing -p1 to patch will cause the wrong file to be patched. - -Please tell me if the patch does not apply. It should be trivial to apply -manually, as it's just a block of text that needs to be inserted near the other -*conf: targets in scripts/kconfig/Makefile. - -Look further down for a motivation for the Makefile patch and for instructions -on how you can use Kconfiglib without it. - -If you do not wish to install Kconfiglib via pip, the Makefile patch is set up -so that you can also just clone Kconfiglib into the kernel root: - - $ git clone git://github.com/ulfalizer/Kconfiglib.git - $ git am Kconfiglib/makefile.patch (or 'patch -p1 < Kconfiglib/makefile.patch') - -Warning: The directory name Kconfiglib/ is significant in this case, because -it's added to PYTHONPATH by the new targets in makefile.patch. - -The targets added by the Makefile patch are described in the following -sections. - - -make kmenuconfig ----------------- - -This target runs the curses menuconfig interface with Python 3. As of -Kconfiglib 12.2.0, both Python 2 and Python 3 are supported (previously, only -Python 3 was supported, so this was a backport). - - -make guiconfig --------------- - -This target runs the Tkinter menuconfig interface. Both Python 2 and Python 3 -are supported. To change the Python interpreter used, pass -PYTHONCMD= to 'make'. The default is 'python'. - - -make [ARCH=] iscriptconfig --------------------------------- - -This target gives an interactive Python prompt where a Kconfig instance has -been preloaded and is available in 'kconf'. To change the Python interpreter -used, pass PYTHONCMD= to 'make'. The default is 'python'. - -To get a feel for the API, try evaluating and printing the symbols in -kconf.defined_syms, and explore the MenuNode menu tree starting at -kconf.top_node by following 'next' and 'list' pointers. - -The item contained in a menu node is found in MenuNode.item (note that this can -be one of the constants kconfiglib.MENU and kconfiglib.COMMENT), and all -symbols and choices have a 'nodes' attribute containing their menu nodes -(usually only one). Printing a menu node will print its item, in Kconfig -format. - -If you want to look up a symbol by name, use the kconf.syms dictionary. - - -make scriptconfig SCRIPT=