Was bedeutet obj-y += etwas/ im Linux-Kernel-Makefile?

Lesezeit: 2 Minuten

Ich verstehe die Bedeutung von

obj-$(CONFIG_USB)       += usb.o

wenn CONFIG_USB y ist, wird usb.o kompiliert. So, jetzt, wie man das versteht

obj-y               += something/

Kernel-Makefiles sind Teil der kbuild System, zum Beispiel an verschiedenen Stellen im Internet dokumentiert http://lwn.net/Articles/21835/. Den entsprechenden Auszug finden Sie hier:

--- 3.1 Goal definitions

Zieldefinitionen sind der Hauptteil (das Herz) des kbuild-Makefiles. Diese Zeilen definieren die zu erstellenden Dateien, alle speziellen Kompilierungsoptionen und alle Unterverzeichnisse, die rekursiv eingegeben werden sollen.

Das einfachste kbuild-Makefile enthält eine Zeile:

Beispiel: obj-y += foo.o

Dies teilt kbuild mit, dass es in diesem Verzeichnis ein Objekt namens foo.o gibt. foo.o wird aus foo.c oder foo.S erstellt.

Wenn foo.o als Modul gebaut werden soll, wird die Variable obj-m verwendet. Daher wird häufig folgendes Muster verwendet:

Beispiel: obj-$(CONFIG_FOO) += foo.o

$(CONFIG_FOO) ergibt entweder y (für eingebaut) oder m (für Modul). Wenn CONFIG_FOO weder y noch m ist, wird die Datei weder kompiliert noch gelinkt.

So m bedeutet Modul, y bedeutet built-in (steht für yes im Kernel-Konfigurationsprozess), und $(CONFIG_FOO) zieht die richtige Antwort aus dem normalen Konfigurationsprozess.

obj-y += etwas/

Das bedeutet, dass kbuild in das Verzeichnis “something” gehen sollte. Sobald es sich in dieses Verzeichnis bewegt, schaut es sich das Makefile in “etwas” an, um zu entscheiden, welche Objekte gebaut werden sollen.

Es ist analog zu sagen: Gehe in das Verzeichnis “something” und führe “make” aus.

Ihre Frage scheint zu sein, warum ein ganzes Verzeichnis als Ziel hinzugefügt wird. Der relevante Teil der KConfig-Dokumentation lautet:

--- 3.6 Descending down in directories

    A Makefile is only responsible for building objects in its own
    directory. Files in subdirectories should be taken care of by
    Makefiles in these subdirs. The build system will automatically
    invoke make recursively in subdirectories, provided you let it know of
    them.

    To do so obj-y and obj-m are used.
    ext2 lives in a separate directory, and the Makefile present in fs/
    tells kbuild to descend down using the following assignment.

    Example:
        #fs/Makefile
        obj-$(CONfIG_EXT2_FS) += ext2/

    If CONFIG_EXT2_FS is set to either 'y' (built-in) or 'm' (modular)
    the corresponding obj- variable will be set, and kbuild will descend
    down in the ext2 directory.
    Kbuild only uses this information to decide that it needs to visit
    the directory, it is the Makefile in the subdirectory that
    specifies what is modules and what is built-in.

    It is good practice to use a CONFIG_ variable when assigning directory
    names. This allows kbuild to totally skip the directory if the
    corresponding CONFIG_ option is neither 'y' nor 'm'.

  • Übrigens, wo werden sie nach dem Hinzufügen aller .o-Dateien in der obj-y-Variablen tatsächlich kompiliert? Ich meine, wo in einem der vielen Makefiles im Kernelbaum?

    – Chan-Kim

    10. März 2017 um 0:42 Uhr

1433530cookie-checkWas bedeutet obj-y += etwas/ im Linux-Kernel-Makefile?

This website is using cookies to improve the user-friendliness. You agree by using the website further.

Privacy policy