1

To start, I had all my data in the same directory as my source code:

.image_01: .incbin "image_01.bin"
.image_02: .incbin "image_02.bin"

This is of course a mess and a bad practice. So I moved my data up a dir and into a data dir:

.image_01: .incbin "../data/image_01.bin"
.image_02: .incbin "../data/image_02.bin"

Now my src dir is nice and clean, but there is a problem here, which is violation of DRY.

Is there any way I can define some sort of variable, ie, DATADIR="../data/" and string concatenate that to the names of my data files? ie, .image_01: .incbin DATADIR + "image_01.bin"?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • Does `-I DIR` on the command-line work for `.incbin`? The manual only documents it working for `.include`. https://sourceware.org/binutils/docs/as/I.html . Another possibility is the C preprocessor (name your files `.S` instead of `.s` and build with `gcc -c`) to paste strings together, e.g. make a macro you can use like `INCBIN_DATADIR("image_01.bin")`. Hopefully with a less ugly name if you can think of one. – Peter Cordes Aug 14 '23 at 22:05
  • [gcc inline assembler incbin doesn't seem to use -I argument](https://stackoverflow.com/q/55540446) confirms that `as -I whatever` *does* work, and `gcc -I whatever -c foo.s` even passes that `-I` on to the assembler. (The querent was probably using relative paths from the wrong build directory different from the source file.) – Peter Cordes Aug 14 '23 at 22:10
  • Possible duplicate of [Provide incbin path as a predefined macro in both NASM and GCC](https://stackoverflow.com/q/56305022) – Peter Cordes Aug 14 '23 at 22:11
  • Perhaps [How to concatenate GNU GAS macro arguments with other tokens to make single label?](https://stackoverflow.com/q/2990413) is related if you wanted to use purely GAS `.macro` stuff, e.g. to make a macro that could do a `.incbin` of a path involving its arg, concatenated with something. But I'm not sure if that Q&A accomplishes that, I haven't done much with GAS .macro – Peter Cordes Aug 14 '23 at 22:32

0 Answers0