Page 1 of 1

Pre- and Post-builds events

Posted: Mon Sep 24, 2018 10:08 am
by gost.404
Hello there,
I'm trying to find out if there is way to implement pre- and post-builds for make without editing $(IDF_PATH)/make/project.mk file.

Re: Pre- and Post-builds events

Posted: Tue Sep 25, 2018 2:52 am
by ESP_Sprite
You can add stuff (e.g. dependencies) to the Makefile of your project, or to a Makefile.projbuild of a component. Perhaps that helps?

Re: Pre- and Post-builds events

Posted: Tue Sep 25, 2018 11:31 am
by gost.404
Could you give some example?

Some details about my question:
I have two shell-scripts prebuild.sh and postbuild.sh.
Expected execution order: prebuild.sh -> main build -> postbuild.sh

Re: Pre- and Post-builds events

Posted: Tue Sep 25, 2018 2:34 pm
by ESP_igrr
Makefiles usually have multiple targets. Do you want these pre- and post- build event to run for all targets, or only for some? For example, targets may be 'all', 'app', 'bootloader', 'menuconfig', 'flash', etc.
Also do you want to run your scripts if the target is already built (i.e. no files have been changed)?

Re: Pre- and Post-builds events

Posted: Tue Sep 25, 2018 2:58 pm
by gost.404
I need this events for targets that change firmware (i.e. 'all', 'menuconfig', 'defconfig', 'app', etc) and only in case when some files was changed.

If speak about my current target - I want add some kind of automatic generation of software version and use it inside in project.
In another my project I use Autorevision + Visual Studio build events.

Re: Pre- and Post-builds events

Posted: Wed Sep 26, 2018 1:27 am
by ESP_Sprite
Gotcha. What you can do for versioning is add a file (say, my_version.h) containing the versioning info your program uses, then tell Make how to generate this. You can do this in the component.mk of e.g. the main component of your project:

Code: Select all

main.o: my_version.h

my_version.h:
	echo "#define BUILD_DATE \""`date`"\"" > my_version.h
Can you also explain why you want to run the post-build script? Maybe we can come up with some useful Makefile snippet to incorporate that as well.

Re: Pre- and Post-builds events

Posted: Wed Sep 26, 2018 8:47 am
by gost.404
About your example: maybe I misunderstood it but I don't generate version manual I use autorevision for this and it generate h-file with set of defines based on git repo information. Also this h-file can be used in many places inside the program.

About post-build scripts: in another project I use it for several targets: generate firmware image for bootloader (maybe not very useful in ESP32 case) and remove h-file generated by autorevision on pre-build state - this is additional protection for case when someone didn't setup environment for autorevision's correct work because project even won't be built.

Re: Pre- and Post-builds events

Posted: Thu Sep 27, 2018 6:50 am
by ESP_Sprite
My guess is that I don't know what your autorevision does: my guess was that it's some script that uses a bunch of version control information to generate a header file? If so, my Makefile snippet can be used to automatically run autorevision: just change my_version.h to whatever autorevision generates and the echo line to an invocation of autorevision.

Re: Pre- and Post-builds events

Posted: Wed Oct 10, 2018 1:42 pm
by gost.404
Thanks for your advices!
I solve this using Makefile.projbuild for component to add particular CPPFLAGS.