graphitemaster / incbin

Include binary files in C/C++
The Unlicense
966 stars 90 forks source link

GCC auto-depends #25

Closed bryceschober closed 6 years ago

bryceschober commented 7 years ago

The one flaw in this otherwise perfect-for-the-job tool is that an INCBIN()ed binary doesn't get included in the gcc auto-dependency-file-generation of " -MMD -MP -MF"". I wonder if there is some kind of way to fake out gcc/g++ to emit a dependency on the binary file?

graphitemaster commented 7 years ago

you could add the incbined binary in your dependeny list manually in make, then add it to a .PHONY target, not ideal but does work. Some way of automating this would be nice.

bryceschober commented 7 years ago

And if your Makefiles are auto-generated by Eclipse CDT, you're really out of luck. ;-)

graphitemaster commented 6 years ago

Was thinking about this problem a bit more. It's actually possible for us to release a tool that parses source files and generates dependency lines like gcc -MD does something like the following:

file.o: file.c /your/bin/files/here

However there's problems with this.

bryceschober commented 6 years ago

Problems? Do you mean just having to edit the default-generated dependency files?

I guess this is really a gcc bug, not emitting all of its dependencies, which .incbin files really should be considered...

graphitemaster commented 6 years ago

One thing you could do is list all your INCBIN() stuff in a single translation unit (e.g resources.c, and add that object file to your Makefile like):

resources.o: FORCE
.PHONY: FORCE
FORCE:

This way it's always required to build it, since the file FORCE is presumed not to exist, so it is always created, so resources.o is always out of date w.r.t it, so resources.o is always compiled. The .PHONY alone won't work though unless it's a static pattern rule. This has more flexibility and can be better integrated into your build process. Really a couple line Makefile change. Though if you have a lot of resources you're potentially really pushing it hard here in terms of the amount of data.

bryceschober commented 6 years ago

I would actually rather use a custom suffix (like *.incbin.cpp) to enable a separate pattern rule that added to the dependency file generation by scanning, which would be logically a lot more cleaner than your proposed method.

-- Bryce Schober Senior Software Engineer Dynon Avionics, Inc. http://www.dynonavionics.com

On Tue, Apr 24, 2018 at 6:22 PM, Dale Weiler notifications@github.com wrote:

One thing you could do is list all your INCBIN() stuff in a single translation unit (e.g resources.c, and add that object file to your Makefile like

resources.o: .FORCE .PHONY: FORCE FORCE:

This way it's always required to build it, since the file .FORCE is presumed not to exist, so it is always created, so resources.o is always out of date w.r.t it, so resources.o is always compiled. The .PHONY along won't work though unless it's a static pattern rule. This has more flexibility can can be better integrated into your build process. Really a couple line Makefile change. Though if you have a lot of resources you're potentially really pushing it hard here in terms of the amount of data.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/graphitemaster/incbin/issues/25#issuecomment-384130613, or mute the thread https://github.com/notifications/unsubscribe-auth/AA4EVjHPUvz2bc-rTyUmZk9v0HpN7b9qks5tr8_MgaJpZM4Ofn7M .

graphitemaster commented 6 years ago

That would also work yes, I wad going for a more elegant solution without having to define another pattern rule. There's no real solution to this that incbin can do tho so I'm closing it.

jamespharvey20 commented 5 years ago

If using cmake, adding something like this to CMakeLists.txt does the trick:

set_property(SOURCE sourceUsingIncbin.cpp
   APPEND PROPERTY OBJECT_DEPENDS "${PROJECT_SOURCE_DIR}/pathTo/binaryFile"
)

Could be worth adding a Makefile and cmake suggestion to the readme.

thomask77 commented 4 years ago

I also did not find a way to generate the correct dependencies.

But this looks promising: https://gcc.gnu.org/onlinedocs/cpp/Pragmas.html#Pragmas

If you add

_Pragma("GCC dependency \"some_file.bin\"")

To the INCBIN macro, GCC will output a warning, if some_file.bin is newer than the C file. For example:

some_c_file.c:35:16: warning: current file is older than some_file.bin
   35 | _Pragma ("GCC dependency \"some_file.bin\"")
      |                ^~~