Pre- and Post-builds events

User avatar
gost.404
Posts: 19
Joined: Sat Jul 01, 2017 5:48 pm

Pre- and Post-builds events

Postby gost.404 » Mon Sep 24, 2018 10:08 am

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.

ESP_Sprite
Posts: 9766
Joined: Thu Nov 26, 2015 4:08 am

Re: Pre- and Post-builds events

Postby ESP_Sprite » Tue Sep 25, 2018 2:52 am

You can add stuff (e.g. dependencies) to the Makefile of your project, or to a Makefile.projbuild of a component. Perhaps that helps?

User avatar
gost.404
Posts: 19
Joined: Sat Jul 01, 2017 5:48 pm

Re: Pre- and Post-builds events

Postby gost.404 » Tue Sep 25, 2018 11:31 am

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

ESP_igrr
Posts: 2072
Joined: Tue Dec 01, 2015 8:37 am

Re: Pre- and Post-builds events

Postby ESP_igrr » Tue Sep 25, 2018 2:34 pm

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)?

User avatar
gost.404
Posts: 19
Joined: Sat Jul 01, 2017 5:48 pm

Re: Pre- and Post-builds events

Postby gost.404 » Tue Sep 25, 2018 2:58 pm

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.

ESP_Sprite
Posts: 9766
Joined: Thu Nov 26, 2015 4:08 am

Re: Pre- and Post-builds events

Postby ESP_Sprite » Wed Sep 26, 2018 1:27 am

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.

User avatar
gost.404
Posts: 19
Joined: Sat Jul 01, 2017 5:48 pm

Re: Pre- and Post-builds events

Postby gost.404 » Wed Sep 26, 2018 8:47 am

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.

ESP_Sprite
Posts: 9766
Joined: Thu Nov 26, 2015 4:08 am

Re: Pre- and Post-builds events

Postby ESP_Sprite » Thu Sep 27, 2018 6:50 am

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.

User avatar
gost.404
Posts: 19
Joined: Sat Jul 01, 2017 5:48 pm

Re: Pre- and Post-builds events

Postby gost.404 » Wed Oct 10, 2018 1:42 pm

Thanks for your advices!
I solve this using Makefile.projbuild for component to add particular CPPFLAGS.

Who is online

Users browsing this forum: abbas1375, Baidu [Spider], snutw_, 快乐的小尾巴 and 94 guests