Adding Patch to an Application ================================= In this section, you are going to learn .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow How to create patches ? .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow How to add patches to an application ? .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow How to add patches using diff and patch commands ? .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow How to add patches using quilt commands ? .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow Topics in this section, * :ref:`Adding Patch to an Application : FAQs ` * :ref:`Adding Patch to an Application : Creating Patches using diff and patch ` * :ref:`Adding Patch to an Application : Adding Patches to an Application using diff and patch ` * :ref:`Adding Patch to an Application : Creating Patches using quilt ` * :ref:`Adding Patch to an Application : Adding Patches to an Application using quilt ` .. _linux_x86_c_add_app_patch_0_1: .. tab-set:: .. tab-item:: Adding Patches to Application : FAQs .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow Let us answer few basic questions .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow What is a patch ? .. dropdown:: See Answer * It is a file or set of changes made to a source code of program to modify or update it. * Used to fix bugs or add new features to existing ones. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow What are the ways to generate and apply patch ? .. dropdown:: See Answer * using diff and patch commands. * using quilt commands. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow What is use of diff command ? .. dropdown:: See Answer * command use to compare two files line by line. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow What is use of patch command ? .. dropdown:: See Answer * applies changes to the source code by reading the diff file. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow What is the command to generate patch file ? .. dropdown:: See Answer .. code-block:: c diff -u helloworld_org.c helloworld.c > add_patch_to_helloworld.diff .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow What is the command to apply the patches to source code ? .. dropdown:: See Answer .. code-block:: c patch helloworld_org.c < add_patch_to_helloworld.diff .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow What is the command to remove the patches from source code ? .. dropdown:: See Answer .. code-block:: c patch -R helloworld_org.c < add_patch_to_helloworld.diff .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow What is quilt ? .. dropdown:: See Answer * Tools used for managing a series of patches applied to the source code repository. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow What quilt init does ? .. dropdown:: See Answer * quilt init command is used to create a new quilt series. .. code-block:: c $ quilt init The quilt meta-data is now initialized. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow What quilt new does ? .. dropdown:: See Answer * quilt new is used to create a patch file. .. code-block:: c * quilt new patch_file_name.patch .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow What quilt add does ? .. dropdown:: See Answer * quilt add is used to add the source code files which needs to be modified. .. code-block :: c quilt add ..... .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow What quilt refresh does ? .. dropdown:: See Answer * quilt refresh is used to update the series with latest modifications. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow What quilt series does ? .. dropdown:: See Answer * quilt series is used to display the name of the patches under that series. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow What quilt push does ? .. dropdown:: See Answer * quilt push is used to apply the patches. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow What is quilt pop does ? .. dropdown:: See Answer * quilt pop is used to unapply the top most patch in the series. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow What quilt top does ? .. dropdown:: See Answer * quilt top is used to display the currently applied patch. * It displays the top most patch present in the series. .. panels:: :container: container pb-4 :column: col-lg-12 p-2 :card: shadow Let us now explore it in depth ! .. _linux_x86_c_add_app_patch_0_2: .. tab-set:: .. tab-item:: Creating Patches using diff and patch * Step 1: Edit the file which needs to be modified. * Step 2: Generate a patch file using the diff command. .. code-block:: c diff -u > * Step 3: Now the patches to the file can be applied using patch command. .. code-block:: c patch < * Now a patch is created and the changes is applied to the file. .. _linux_x86_c_add_app_patch_0_3: .. tab-set:: .. tab-item:: Adding patches to an Application using diff and patch .. tab-set:: .. tab-item:: helloworld_orginal.c .. literalinclude:: app_diff/helloworld_original.c :language: c :linenos: .. tab-set:: .. tab-item:: helloworld_modified.c * Copy the file which needs to be modified to a new file and make the changes required. .. literalinclude:: app_diff/helloworld_modified.c :language: c :linenos: .. tab-set:: .. tab-item:: Generating patch file using diff command. .. code-block:: c $ diff -u helloworld_orginal.c helloworld_modified.c > add_patch_to_helloworld.diff .. tab-set:: .. tab-item:: add_patch_to_helloworld.diff .. literalinclude:: app_diff/add_patch_to_helloworld.diff :language: c :linenos: .. tab-set:: .. tab-item:: Applying patches to the source code using patch command .. code-block:: c $ patch helloworld_orginal.c < add_patch_to_helloworld.diff patching file helloworld_orginal.c .. tab-set:: .. tab-item:: Compiling and Executing the Application .. code-block:: c $ gcc helloworld_orginal.c $ ./a.out Hello-World Patch applied .. _linux_x86_c_add_app_patch_0_4: .. tab-set:: .. tab-item:: Creating Patches using quilt * Step 1: create a new quilt series using quilt init command. .. code-block:: c $ quilt init The quilt meta-data is now initialized. * Step 2: create a patch file using quilt new command. .. code-block :: c $ quilt new add_hello_world_patch.patch Patch patches/add_hello_world_patch.patch is now on top * Step 3: add the file which needs to be modified using quilt add command. .. code-block :: c $ quilt add helloworld.c File helloworld.c added to patch patches/add_hello_world_patch.patch * Step 4: edit the file and make the modifications needed. .. code-block :: c $ vi helloworld.c * Step 5: once the changes is added run quilt refresh to update the series with latest modifications. .. code-block :: c $ quilt refresh Refreshed patch patches/add_hello_world_patch.patch * Now a patch is created and changes has been added to the series. .. _linux_x86_c_add_app_patch_0_5: .. tab-set:: .. tab-item:: Adding Patches to an Application using quilt .. tab-set:: .. tab-item:: helloworld.c .. literalinclude:: app/helloworld.c :language: c :linenos: .. tab-set:: .. tab-item:: Makefile .. literalinclude:: app/Makefile :language: c :linenos: .. tab-set:: .. tab-item:: Adding patches to helloworld.c .. code-block :: c $ quilt init The quilt meta-data is now initialized. $ quilt new add_hello_world_patch.patch Patch patches/add_hello_world_patch.patch is now on top $ quilt add helloworld.c File helloworld.c added to patch patches/add_hello_world_patch.patch $ vi helloworld.c $ quilt refresh Refreshed patch patches/add_hello_world_patch.patch .. tab-set:: .. tab-item:: add_hello_world_patch.patch .. literalinclude:: app/patches/add_hello_world_patch.patch :language: c :linenos: .. tab-set:: .. tab-item:: Compiling the application .. code-block:: c $ make Applying patch patches/add_hello_world_patch.patch patching file helloworld.c Now at patch patches/add_hello_world_patch.patch .. tab-set:: .. tab-item:: Executing the application .. code-block:: c $ ./helloworld Hello World Patches Applied .. card:: See Also * Other topics of linux x86 * :doc:`../add_hello_world_app/add_hello_world_app` * :doc:`../add_static_lib/add_static_lib` * :doc:`../add_shared_lib/add_shared_lib` * :doc:`../add_hello_world_kernel_mod/add_hello_world_kernel_mod` * :doc:`../add_static_lib_patch/add_static_lib_patch` * :doc:`../add_shared_lib_patch/add_shared_lib_patch` * :doc:`../add_kernel_mod_patch/add_kernel_mod_patch` * Current Module * :doc:`../add_application_patch/add_application_patch` * Previous Module * :doc:`../add_hello_world_kernel_mod/add_hello_world_kernel_mod` * Next Module * :doc:`../../../linux_openwrt_rpi/linux_openwrt_rpi_c` * Other Modules * :doc:`../../../linux_rdkb_rpi/linux_rdkb_rpi_c` * :doc:`../../../linux_yocto_rpi/linux_yocto_rpi_c`