mszabc
mszabc

Reputation: 535

Makefile - include path in separate file

I would like to store all paths to headers in separate file. I'm going to generate file with paths dynamically, to avoid re-creating Makefile whenever paths change. Is that possible?

Upvotes: 2

Views: 810

Answers (2)

Eldar Abusalimov
Eldar Abusalimov

Reputation: 25483

Makefile

paths_mk := paths.mk
-include $(paths_mk)
$(paths_mk) :
    # Rule to generate paths.mk

include_flags = $(include_paths:%=-I%)

CPPFLAGS += $(include_flags)

%.o : %.c
    $(CC) $(CPPFLAGS) $(CFLAGS) -o $@ -c $<

paths.mk

# Auto-generated file.
include_paths := ...

Upvotes: 2

piokuc
piokuc

Reputation: 26164

Yes, you can generate the file, let's call it paths.inc, so it looks like, for example:

INCLUDEPATH=path1:path2

and then include the file in your main Makefile

include paths.inc

and use the variable defined in it: ${INCLUDEPATH}

Upvotes: 3

Related Questions