Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] building externals for android #63

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
67 changes: 60 additions & 7 deletions Makefile.pdlibbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,9 @@ target.triplet := $(subst -, ,$(shell $(CC) -dumpmachine))
ifneq ($(filter linux gnu% kfreebsd, $(target.triplet)),)
system = Linux
endif
ifneq ($(filter android%, $(target.triplet)),)
system = Android
endif

ifneq ($(filter darwin%, $(target.triplet)),)
system = Darwin
Expand Down Expand Up @@ -497,6 +500,31 @@ ifeq ($(system), Linux)
endif


#=== flags and paths for Android ===============================================
ifeq ($(system), Android)
prefix = /usr/local
libdir := $(prefix)/lib
pkglibdir = $(libdir)/pd-externals
pdincludepath := $(wildcard /usr/include/pd)
extension = so
cpp.flags := -DUNIX
c.flags :=
c.ldflags := -rdynamic -shared -Wl,-rpath,"\$$ORIGIN",--enable-new-dtags
c.ldlibs := -lc -lm
cxx.flags := -fcheck-new
cxx.ldflags := -rdynamic -shared -Wl,-rpath,"\$$ORIGIN",--enable-new-dtags
cxx.ldlibs := -lc -lm -lstdc++
shared.extension = so
shared.ldflags = -rdynamic -shared -Wl,-soname,$(shared.lib)
# on Android, dlopen()ed files must have the form 'lib<name>.so'.
# also, the name must not include a '~', so Pd replaces it with a '_tilde'
# when searching for a library.
classname-mangler = $(addprefix lib, $(patsubst %~,%_tilde,$1))
endif




#=== flags and paths for Darwin ================================================


Expand Down Expand Up @@ -695,8 +723,33 @@ endef

$(foreach v, $(class.sources), $(eval $(add-class-source)))

# Mangle the names of the classes
# If a function 'classname-mangler' is defined, it is applied to all output files
# effectively renaming the filename for the externals
# This is necessary for building externals for Android, which requires dlopen()ed
# files to have a specific name.
# the 'classname-mangler' function takes a single argument (the classname,
# e.g. 'foo~'), and returns a mangled version (e.g. 'libfoo_tilde').
# file extensions are handled separately via the 'extension' variable.
# See the 'system==Android' section for an example.
define eval-classname-mangler =
$(call classname-mangler,$1).class.sources := $$($(1).class.sources)
undefine $(1).class.sources
sourcevariables += $(call classname-mangler,$1).class.sources
endef

# only mangle the names if a 'classname-mangler' function is defined
ifdef classname-mangler
sourcevariables :=
$(foreach v, $(filter %.class.sources, $(.VARIABLES)), $(eval $(call eval-classname-mangler,$(basename $(basename $v)))))
lib.executable = $(call classname-mangler,$(lib.name)).$(extension)
else
sourcevariables := $(filter %.class.sources, $(.VARIABLES))
classname-mangler = $1
lib.executable = $(lib.name).$(extension)
endif

# derive class names from <classname>.class.sources variables
sourcevariables := $(filter %.class.sources, $(.VARIABLES))
classes := $(basename $(basename $(sourcevariables)))

# accumulate all source files specified in makefile
Expand Down Expand Up @@ -818,7 +871,7 @@ $(if $(filter install install-lib, $(goals)), $(info ++++ info: \
ifeq ($(make-lib-executable),yes)
$(if $(lib.setup.sources), ,\
$(error Can not build library blob because lib.setup.sources is undefined))
executables := $(lib.name).$(extension)
executables := $(lib.executable)
else
executables := $(classes.executables) $(shared.lib)
endif
Expand Down Expand Up @@ -891,22 +944,22 @@ endef


# build all classes into single executable
build-lib: $(lib.name).$(extension)
$(info ++++ info: library blob $(lib.name).$(extension) completed)
build-lib: $(lib.executable)
$(info ++++ info: library blob $(lib.executable) completed)

# recipe for linking objects in lib executable
# argument $1 = compiler type (c or cxx)
define link-lib
$(compile-$1) \
$($1.ldflags) $(lib.ldflags) \
-o $(lib.name).$(extension) $(all.objects) \
-o $(lib.executable) $(all.objects) \
$($1.ldlibs) $(lib.ldlibs)
endef

# rule for linking objects in lib executable
# declared conditionally to avoid name clashes
ifeq ($(make-lib-executable),yes)
$(lib.name).$(extension): $(all.objects)
$(lib.executable): $(all.objects)
$(if $(filter %.cc %.cpp, $(all.sources)), \
$(call link-lib,cxx), \
$(call link-lib,c))
Expand Down Expand Up @@ -1186,7 +1239,7 @@ $(DISTDIR):
# delete build products from build tree
clean:
rm -f $(all.objects)
rm -f $(classes.executables) $(lib.name).$(extension) $(shared.lib)
rm -f $(classes.executables) $(lib.executable) $(shared.lib)
rm -f *.pre *.lst

# remove distribution directories and tarballs from build tree
Expand Down
7 changes: 5 additions & 2 deletions tests/_template_/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ PDLIBBUILDER_DIR=../..
include $(PDLIBBUILDER_DIR)/Makefile.pdlibbuilder

# simplistic tests whether all expected files have been produced/installed
ifeq ($(system), Android)
classprefix=lib
endif
buildcheck: all
test -e _template_.$(extension)
test -e $(classprefix)_template_.$(extension)
installcheck: install
test -e $(installpath)/_template_.$(extension)
test -e $(installpath)/$(classprefix)_template_.$(extension)
14 changes: 10 additions & 4 deletions tests/multifor/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ endef
define forWindows
class.sources += multiforB.c
endef
define forAndroid
class.sources += multiforB.c
endef

# all extra files to be included in binary distribution of the library
datafiles = multifor-help.pd multifor-meta.pd
Expand All @@ -29,11 +32,14 @@ PDLIBBUILDER_DIR=../..
include $(PDLIBBUILDER_DIR)/Makefile.pdlibbuilder

# simplistic tests whether all expected files have been produced/installed
ifeq ($(system), Android)
classprefix=lib
endif
buildcheck: all
test -e multiforA.$(extension)
test -e multiforB.$(extension)
test -e $(classprefix)multiforA.$(extension)
test -e $(classprefix)multiforB.$(extension)
installcheck: install
test -e $(installpath)/multiforA.$(extension)
test -e $(installpath)/multiforB.$(extension)
test -e $(installpath)/$(classprefix)multiforA.$(extension)
test -e $(installpath)/$(classprefix)multiforB.$(extension)
test -e $(installpath)/multifor-help.pd
test -e $(installpath)/multifor-meta.pd
7 changes: 5 additions & 2 deletions tests/multilib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ include $(PDLIBBUILDER_DIR)/Makefile.pdlibbuilder


# simplistic tests whether all expected files have been produced/installed
ifeq ($(system), Android)
classprefix=lib
endif
buildcheck: all
test -e multilib.$(extension)
test -e $(classprefix)multilib.$(extension)
installcheck: install
test -e $(installpath)/multilib.$(extension)
test -e $(installpath)/$(classprefix)multilib.$(extension)
test -e $(installpath)/multilib-help.pd
test -e $(installpath)/multilib-meta.pd
11 changes: 7 additions & 4 deletions tests/multiple/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ PDLIBBUILDER_DIR=../..
include $(PDLIBBUILDER_DIR)/Makefile.pdlibbuilder

# simplistic tests whether all expected files have been produced/installed
ifeq ($(system), Android)
classprefix=lib
endif
buildcheck: all
test -e multipleA.$(extension)
test -e multipleB.$(extension)
test -e $(classprefix)multipleA.$(extension)
test -e $(classprefix)multipleB.$(extension)
installcheck: install
test -e $(installpath)/multipleA.$(extension)
test -e $(installpath)/multipleB.$(extension)
test -e $(installpath)/$(classprefix)multipleA.$(extension)
test -e $(installpath)/$(classprefix)multipleB.$(extension)
test -e $(installpath)/multiple-help.pd
test -e $(installpath)/multiple-meta.pd
11 changes: 7 additions & 4 deletions tests/multiplexx/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ PDLIBBUILDER_DIR=../..
include $(PDLIBBUILDER_DIR)/Makefile.pdlibbuilder

# simplistic tests whether all expected files have been produced/installed
ifeq ($(system), Android)
classprefix=lib
endif
buildcheck: all
test -e multiplexxA.$(extension)
test -e multiplexxB.$(extension)
test -e $(classprefix)multiplexxA.$(extension)
test -e $(classprefix)multiplexxB.$(extension)
installcheck: install
test -e $(installpath)/multiplexxA.$(extension)
test -e $(installpath)/multiplexxB.$(extension)
test -e $(installpath)/$(classprefix)multiplexxA.$(extension)
test -e $(installpath)/$(classprefix)multiplexxB.$(extension)
test -e $(installpath)/multiplexx-help.pd
test -e $(installpath)/multiplexx-meta.pd
11 changes: 7 additions & 4 deletions tests/multishared/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,24 @@ PDLIBBUILDER_DIR=../..
include $(PDLIBBUILDER_DIR)/Makefile.pdlibbuilder

# simplistic tests whether all expected files have been produced/installed
ifeq ($(system), Android)
classprefix=lib
endif
buildcheck: all
ifeq ($(shared.extension), $(extension))
test -e lib$(lib.name).$(shared.extension)
else
test -e lib$(lib.name).$(extension).$(shared.extension)
endif
test -e multisharedA.$(extension)
test -e multisharedB.$(extension)
test -e $(classprefix)multisharedA.$(extension)
test -e $(classprefix)multisharedB.$(extension)
installcheck: install
ifeq ($(shared.extension), $(extension))
test -e $(installpath)/lib$(lib.name).$(shared.extension)
else
test -e $(installpath)/lib$(lib.name).$(extension).$(shared.extension)
endif
test -e $(installpath)/multisharedA.$(extension)
test -e $(installpath)/multisharedB.$(extension)
test -e $(installpath)/$(classprefix)multisharedA.$(extension)
test -e $(installpath)/$(classprefix)multisharedB.$(extension)
test -e $(installpath)/multishared-help.pd
test -e $(installpath)/multishared-meta.pd
7 changes: 5 additions & 2 deletions tests/single/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ PDLIBBUILDER_DIR=../..
include $(PDLIBBUILDER_DIR)/Makefile.pdlibbuilder

# simplistic tests whether all expected files have been produced/installed
ifeq ($(system), Android)
classprefix=lib
endif
buildcheck: all
test -e single.$(extension)
test -e $(classprefix)single.$(extension)
installcheck: install
test -e $(installpath)/single.$(extension)
test -e $(installpath)/$(classprefix)single.$(extension)
14 changes: 10 additions & 4 deletions tests/subdir/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,15 @@ PDLIBBUILDER_DIR=../..
include $(PDLIBBUILDER_DIR)/Makefile.pdlibbuilder

# simplistic tests whether all expected files have been produced/installed
ifeq ($(system), Android)
classprefix=lib
tilde=_tilde
else
tilde=~
endif
buildcheck: all
test -e subdir.$(extension)
test -e subdir~.$(extension)
test -e $(classprefix)subdir.$(extension)
test -e $(classprefix)subdir$(tilde).$(extension)
installcheck: install
test -e $(installpath)/subdir.$(extension)
test -e $(installpath)/subdir~.$(extension)
test -e $(installpath)/$(classprefix)subdir.$(extension)
test -e $(installpath)/$(classprefix)subdir$(tilde).$(extension)