0

How can I add prerequisite rule for all source files (c/cpp)? It would be simple if entire make file was done by me, but I use android build system that hides most of the stuff from me.

The reason I want to do it: I added a rule to generate my header file which is included by some c/cpp files. It works well as long as dependencies are already generated. However, with a clean project there is no dependency info available before compilation and as a result make won't run my rule for a clean project because it doesn't know that certain cpp file depends on a header file that doesn't exist yet. That's why I need to add some kind of rule to ensure that my prerequisite rule runs before any compilation takes place.

So far, I did this:

include $(CLEAR_VARS)

.PHONY: ForceRule
MyHeader.h: ForceRule
ForceRule: CreateHeader.sh
    $(shell CreateHeader.sh MyHeader.h)

# below is standard android way to build shared lib from cpp files:
LOCAL_SRC_FILES: File1.cpp File2.cpp
LOCAL_PATH := $(CURDIR)

include $(BUILD_SHARED_LIBRARY)
Pavel P
  • 15,789
  • 11
  • 79
  • 128
  • This is unclear. Do you want all object file targets to have `MyHeader.h` as a prerequisite? Or only some of them? – Beta Jan 09 '13 at 00:06
  • @Beta Yes, basically how do I force ALL compilation (all objects) to depend on a rule (or a header file). This dependecy has to be enforced from makefile without using generated dependencies (that come from compiler). – Pavel P Jan 09 '13 at 18:17
  • Here's similar quesition, but in my case I use android buildsystem and I don't control compilation rules, they are hidden somewhere inside, so I need to add that dependency somehow. – Pavel P Jan 09 '13 at 18:27

1 Answers1

0

It's hard to be sure with black-box makefiles (and I think your approach is wrong), but you could try this:

MyHeader.h: CreateHeader.sh
    $(shell CreateHeader.sh MyHeader.h)

%.o: %.cpp MyHeader.h
Beta
  • 96,650
  • 16
  • 149
  • 150
  • It doesn't work this way, I've tried that. Why do you think my approach is wrong? I think I can cook something up using $(eval ...) and adding late-expand parameter to LOCAL_C_FLAGS, something similar to: http://stackoverflow.com/questions/1612278/pre-build-step-in-makefile – Pavel P Jan 09 '13 at 23:40