Makefile looping in Android.mk

1,996 views
Skip to first unread message

Dan S

unread,
May 1, 2010, 4:11:28 PM5/1/10
to android-ndk
Hi -

I'd like to use a looping construct in my Android.mk. For a list of
targets...

simpleplugins := IOUGens NoiseUGens LFUGens OscUGens BinaryOpUGens
FilterUGens PanUGens MulAddUGens UnaryOpUGens TriggerUGens

...I'd like to substitute them in place of $(1) in the following:

include $(CLEAR_VARS)
LOCAL_MODULE := $(1)
LOCAL_SRC_FILES := Source/plugins/$(1).cpp
LOCAL_C_INCLUDES+= $(LOCAL_PATH)/Headers/plugin_interface
LOCAL_C_INCLUDES+= $(LOCAL_PATH)/Headers/common
LOCAL_C_INCLUDES+= $(LOCAL_PATH)/Headers/server
LOCAL_CFLAGS += -DSC_ANDROID
include $(BUILD_SHARED_LIBRARY)

I've tried using foreach() and call() and it's not working, I get
errors like:

make: *** No rule to make target `IOUGens', needed by `ndk-app-
TestApp'. Stop.

Anyone know a way that might work?

Thanks
Dan

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.

David Turner

unread,
May 1, 2010, 6:03:56 PM5/1/10
to andro...@googlegroups.com
There are two ways to do that. One if to use 'define' and $(eval ..) which is ugly but seldom necessary.
The other one is simpler: include the same Makefile multiple time, changing the definition of a given variable each time.

E.g. put that into $APP/jni/module.mk:

include $(CLEAR_VARS)
LOCAL_MODULE   := $(MY_MODULE)
LOCAL_SRC_FILES := Source/plugins/$(MY_MODULE).cpp

LOCAL_C_INCLUDES+= $(LOCAL_PATH)/Headers/plugin_interface
LOCAL_C_INCLUDES+= $(LOCAL_PATH)/Headers/common
LOCAL_C_INCLUDES+= $(LOCAL_PATH)/Headers/server
LOCAL_CFLAGS    += -DSC_ANDROID
include $(BUILD_SHARED_LIBRARY)

Then, in your Android,mk:

LOCAL_PATH := $(call my-dir)

$(for MY_MODULE in <list-of-modules>,\
  $(eval include $(LOCAL_PATH)/module.mk) \
)

Dan S

unread,
May 2, 2010, 2:23:09 PM5/2/10
to android-ndk
Thanks, this looks neat. It's not quite working for me - I'm getting
this baffling error, baffling because the included file clearly does
define LOCAL_MODULE:

build/core/build-shared-library.mk:24: *** Android NDK: Missing
LOCAL_MODULE before including BUILD_SHARED_LIBRARY in apps/
SuperCollider-Android/jni/Android.mk . Stop.

Any suggestions?

Thanks
Dan
> > android-ndk...@googlegroups.com<android-ndk%2Bunsu...@googlegroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/android-ndk?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups "android-ndk" group.
> To post to this group, send email to andro...@googlegroups.com.
> To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
> For more options, visit this group athttp://groups.google.com/group/android-ndk?hl=en.
Message has been deleted

David Turner

unread,
Mar 8, 2013, 12:27:00 PM3/8/13
to andro...@googlegroups.com
On Sun, May 2, 2010 at 11:23 AM, Dan S <danst...@gmail.com> wrote:
Thanks, this looks neat. It's not quite working for me - I'm getting
this baffling error, baffling because the included file clearly does
define LOCAL_MODULE:

build/core/build-shared-library.mk:24: *** Android NDK: Missing
LOCAL_MODULE before including BUILD_SHARED_LIBRARY in apps/
SuperCollider-Android/jni/Android.mk    .  Stop.

Any suggestions?

Raising a really old thread from the grave. There was a typo in the code I suggested, it should be:

$(foreach MY_MODULE,<list-of-modules>,\
  $(eval include $(LOCAL_PATH)/module.mk))

Where <list-of-modules> is a space-separated list of module names.

David Turner

unread,
Mar 8, 2013, 12:39:02 PM3/8/13
to andro...@googlegroups.com


On Fri, Mar 8, 2013 at 7:31 AM, Bad Design <alex....@gmail.com> wrote:
Have you solved the problem with "make: *** missing rule before commands. Stop." when using a foreach directive?

I have the following swig-generate.mk file and I get the above error and I don't understand what is the cause, any input on this?

You need to escape all dollar signs that you want to preserve in an $(evall $(call ...)) statement.

E.g.

define func1
MODULE := $(FOO)
MODULE2 := $(MODULE)
endef

FOO := bar
MODULE := xxx
MODULE2 := yyy
$(eval $(call func1))

# Now: MODULE='bar' and MODULE2='xxx' !!

The reason for this is that $(call func1) is first expanded into the following text:

  MODULE := bar
  MODULE2 := xxx

Which is then sent to eval, which will modify the variable values.
The correct way to code the function is:

define func1
MODULE := $(FOO)
MODULE2 := $$(MODULE)
endef

Because then, this gets expanded into:

  MODULE := foo
  MODULE2 := $(MODULE)

before being sent to eval.

Generally speaking, only use $() if you want the expansion to happen in the $(call ..), or use $$() if you want it to happen in the eval.


ifndef MY_SWIG_PACKAGES
    $(error MY_SWIG_PACKAGE is not defined.)
endif

# Default SWIG type is C
ifndef MY_SWIG_TYPE
    MY_SWIG_TYPE := c
endif

# Set SWIG mode
ifeq ($(MY_SWIG_TYPE), cpp)
    MY_SWIG_MODE := -c++
else
    MY_SWIG_MODE :=
endif

define generate_wrapper
%_wrap.$(MY_SWIG_TYPE) : %.i
$(call host-mkdir, $(outdir))
swig -java $(MY_SWIG_MODE) -package $(1) -outdir $(2)
$<
endef
 
define generate_code
MY_SWIG_OUTDIRS := $(NDK_PROJECT_PATH)/src/$(subst .,/,$(1))
$(foreach outdir, $(MY_SWIG_OUTDIRS), $(eval $(call generate_wrapper, $(1), $(outdir))));
endef
 
LOCAL_SRC_FILES += $(foreach MY_SWIG_INTERFACE, $(MY_SWIG_INTERFACES), \
    $(basename $(MY_SWIG_INTERFACE))_wrap.$(MY_SWIG_TYPE))
   
$(foreach package, $(MY_SWIG_PACKAGES), $(eval $(call generate_code, $(package))))
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk...@googlegroups.com.

To post to this group, send email to andro...@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages