How to keep build_dir source even with make clean?

Hi everyone! I am using openwrt 19.07 sdk.

I wanna keep my changes with build_dir/target-... sources, but all the time I run "make <specific package>/clean", the directory just gone forever. To keep my changes, which one and how should I edit? I guess include/package.mk? but I even edited clean section of the file, it doesn't work.

This is my changes,

 339 force-clean-build: FORCE
 340   make -C $(PKG_BUILD_DIR) clean
 341 
 342 clean-build: $(if $(wildcard $(PKG_BUILD_DIR)/.autoremove),force-clean-build)
 343 
 344 clean: force-clean-build
 345   $(CleanStaging)
 346   $(call Build/UninstallDev,$(STAGING_DIR),$(STAGING_DIR_HOST))
 347   $(Build/Clean)
 348   rm -f $(STAGING_DIR)/packages/$(STAGING_FILES_LIST) $(STAGING_DIR_HOST)/packages/$(STAGING_FILES_LIST)

Do I need anything more?

Thank you in advance.

The patching system would be used for this. Most OpenWrt packages that are based on third-party code have patch files in their make directory. When the package is built clean first the build directory is erased. Then the original source code is downloaded (or extracted from a cache if already downloaded) into the build directory. Then patches are applied and the code is compiled.

This page is a summary of how to make a new patch. There is another page somewhere in the wiki with more details.
https://openwrt.org/docs/guide-developer/helloworld/chapter8

The basic workflow is:

  • Do make prepare to start with an unmodified source in build_dir.
    **unmodified in the sense that it will be ready for OpenWrt build with the existing patches applied.
  • Register the files you want to change with the quilt system.
    ** This creates a copy of the unmodified file named _orig it will later run diff against.
  • Edit the source files in the build_dir
  • Optionally test build (do not clean though or your changes will be lost)
  • Commit your changes to patches, which are stored in the make directory.
  • You can now make clean and the code will be patched every time.

Also you have a way to archive or distribute your changes as a patch file.

4 Likes

https://openwrt.org/docs/guide-developer/build-system/use-patches-with-buildsystem

1 Like