aboutsummaryrefslogtreecommitdiff
path: root/Makefile.common
diff options
context:
space:
mode:
Diffstat (limited to 'Makefile.common')
-rw-r--r--Makefile.common285
1 files changed, 285 insertions, 0 deletions
diff --git a/Makefile.common b/Makefile.common
new file mode 100644
index 0000000..3db7717
--- /dev/null
+++ b/Makefile.common
@@ -0,0 +1,285 @@
+# next line has to be edited manually
+PD_DIR = $(ROOT_DIR)/../pd/src
+
+OS_NAME = $(shell uname -s)
+ifneq ($(OS_NAME),Linux)
+ifneq ($(OS_NAME),Darwin)
+# FIXME
+endif
+endif
+
+TILDE = ~
+
+-include Makefile.dirs
+include Makefile.sources
+include Makefile.objects
+
+CC = gcc
+
+default: define_build all
+
+SHARED_DIR = $(ROOT_DIR)/shared
+OBJ_DIR = .
+OUT_DIR = $(ROOT_DIR)/bin
+
+BASE_DIR = $(shell basename `pwd`)
+BASE_NAME = $(shell basename `pwd` | awk -F - '{print $$1}')
+
+# CX: control external's main file
+# AX: audio (tilde) external's main file
+# LX: symlink external's main file
+# (if symlink external is tilde-only, use OTHER_SOURCES and AX_CLASSES)
+
+CX_NAMES = $(notdir $(CX_SOURCES))
+AX_NAMES = $(notdir $(AX_SOURCES))
+LX_NAMES = $(notdir $(LX_SOURCES))
+TYPES_NAMES = $(notdir $($1_SOURCES))
+
+CX_DIR = $(dir $(firstword $(CX_SOURCES)))
+AX_DIR = $(dir $(firstword $(AX_SOURCES)))
+TYPES_DIR = $(dir $(firstword $($1_SOURCES)))
+
+TYPES_EXTERNS = \
+ $(patsubst %.c,%$($1_TILDE).$(X_SUFFIX),$(call TYPES_NAMES,$1))
+
+SOURCES = $(CX_SOURCES) $(AX_SOURCES) $(LX_SOURCES) $(OTHER_SOURCES) \
+ $(foreach type,$(TYPES),$($(type)_SOURCES))
+
+INCLUDES = -I. -I$(PD_DIR) -I$(SHARED_DIR)
+
+ifeq ($(OS_NAME),Linux)
+X_SUFFIX = pd_linux
+DEFINES = -DUNIX
+OPT_CFLAGS = -O6 -funroll-loops -fomit-frame-pointer
+LFLAGS = -export_dynamic -shared
+endif
+
+ifeq ($(OS_NAME),Darwin)
+X_SUFFIX = pd_darwin
+DEFINES = -DUNIX -DMACOSX
+OPT_CFLAGS = -O2 -funroll-loops -fomit-frame-pointer
+# -private_bundle is a guess, LATER check this
+LFLAGS = -bundle -undefined suppress -flat_namespace
+endif
+
+WARN_CFLAGS = -Wall -W -Wstrict-prototypes -Werror \
+ -Wno-unused -Wno-parentheses -Wno-switch
+DBG_CFLAGS =
+CFLAGS = $(WARN_CFLAGS) $(OPT_CFLAGS) $(DEFINES) $(INCLUDES)
+
+EXTERNS = $(foreach fn,$(CX_NAMES:.c=.$(X_SUFFIX)),$(OUT_DIR)/$(fn)) \
+ $(foreach fn,$(AX_NAMES:.c=~.$(X_SUFFIX)),$(OUT_DIR)/$(fn)) \
+ $(foreach fn,$(LX_SOURCES:.c=.$(X_SUFFIX)),$(OUT_DIR)/$(fn)) \
+ $(foreach fn,$(CX_CLASSES:=.$(X_SUFFIX)),$(OUT_DIR)/$(fn)) \
+ $(foreach fn,$(AX_CLASSES:=~.$(X_SUFFIX)),$(OUT_DIR)/$(fn)) \
+ $(foreach type,$(TYPES),\
+ $(foreach fn,$(call TYPES_EXTERNS,$(type)),$(OUT_DIR)/$(fn)))
+
+TYPES_RULE = $(foreach fn,$(call TYPES_EXTERNS,$1),$(OUT_DIR)/$(fn)): \
+ $(OUT_DIR)/%$($1_TILDE).$(X_SUFFIX) \
+ : $(call TYPES_DIR,$1)%.o $($1_PRIVATEOBJECTS) \
+ $(foreach obj,$($1_OBJECTS),$(SHARED_DIR)/$(obj)) \
+ ; $(CC) -o $$@ $(CFLAGS) $(LFLAGS) $$+
+
+# LATER find a better way...
+$(if $(word 1,$(TYPES)),$(call TYPES_RULE,$(word 1,$(TYPES))))
+$(if $(word 2,$(TYPES)),$(call TYPES_RULE,$(word 2,$(TYPES))))
+$(if $(word 3,$(TYPES)),$(call TYPES_RULE,$(word 3,$(TYPES))))
+$(if $(word 4,$(TYPES)),$(call TYPES_RULE,$(word 4,$(TYPES))))
+$(if $(word 5,$(TYPES)),$(call TYPES_RULE,$(word 5,$(TYPES))))
+$(if $(word 6,$(TYPES)),$(call TYPES_RULE,$(word 6,$(TYPES))))
+$(if $(word 7,$(TYPES)),$(call TYPES_RULE,$(word 7,$(TYPES))))
+$(if $(word 8,$(TYPES)),$(call TYPES_RULE,$(word 8,$(TYPES))))
+$(if $(word 9,$(TYPES)),$(call TYPES_RULE,$(word 9,$(TYPES))))
+$(if $(word 10,$(TYPES)),$(call TYPES_RULE,$(word 10,$(TYPES))))
+$(if $(word 11,$(TYPES)),$(call TYPES_RULE,$(word 11,$(TYPES))))
+$(if $(word 12,$(TYPES)),$(call TYPES_RULE,$(word 12,$(TYPES))))
+$(if $(word 13,$(TYPES)),$(call TYPES_RULE,$(word 13,$(TYPES))))
+$(if $(word 14,$(TYPES)),$(call TYPES_RULE,$(word 14,$(TYPES))))
+$(if $(word 15,$(TYPES)),$(call TYPES_RULE,$(word 15,$(TYPES))))
+$(if $(word 16,$(TYPES)),$(call TYPES_RULE,$(word 16,$(TYPES))))
+$(if $(word 17,$(TYPES)),$(call TYPES_RULE,$(word 17,$(TYPES))))
+$(if $(word 18,$(TYPES)),$(call TYPES_RULE,$(word 18,$(TYPES))))
+$(if $(word 19,$(TYPES)),$(call TYPES_RULE,$(word 19,$(TYPES))))
+$(if $(word 20,$(TYPES)),$(call TYPES_RULE,$(word 20,$(TYPES))))
+$(if $(word 21,$(TYPES)),$(call TYPES_RULE,$(word 21,$(TYPES))))
+$(if $(word 22,$(TYPES)),$(call TYPES_RULE,$(word 22,$(TYPES))))
+$(if $(word 23,$(TYPES)),$(call TYPES_RULE,$(word 23,$(TYPES))))
+$(if $(word 24,$(TYPES)),$(call TYPES_RULE,$(word 24,$(TYPES))))
+
+OBJECTS = $(foreach fn,$(OTHER_SOURCES:.c=.o),$(OBJ_DIR)/$(fn)) \
+ $(foreach fn,$(LX_SOURCES:.c=.o),$(OBJ_DIR)/$(fn)) \
+ $(foreach fn,$(SHARED_OBJECTS),$(SHARED_DIR)/$(fn))
+
+# lame...
+.PRECIOUS: %.o
+
+# rules for symlink externals must precede generic extern rules
+$(OUT_DIR)/$(BASE_NAME)_%~.$(X_SUFFIX): $(OUT_DIR)/$(BASE_NAME).$(X_SUFFIX)
+ -ln -sf $(BASE_NAME).$(X_SUFFIX) $@
+$(OUT_DIR)/$(BASE_NAME)_%.$(X_SUFFIX): $(OUT_DIR)/$(BASE_NAME).$(X_SUFFIX)
+ -ln -sf $(BASE_NAME).$(X_SUFFIX) $@
+
+# library stub
+# if not equal BASE_NAME, it has to be declared explicitly in BASE_DIR/Makefile
+$(OUT_DIR)/$(LX_STUB)_%~.$(X_SUFFIX): $(OUT_DIR)/$(BASE_NAME).$(X_SUFFIX)
+ -ln -sf $(BASE_NAME).$(X_SUFFIX) $@
+$(OUT_DIR)/$(LX_STUB)_%.$(X_SUFFIX): $(OUT_DIR)/$(BASE_NAME).$(X_SUFFIX)
+ -ln -sf $(BASE_NAME).$(X_SUFFIX) $@
+$(OUT_DIR)/$(LX_STUB).$(X_SUFFIX): $(OUT_DIR)/$(BASE_NAME).$(X_SUFFIX)
+ -ln -sf $(BASE_NAME).$(X_SUFFIX) $@
+
+# generic rule for audio externals
+$(OUT_DIR)/%~.$(X_SUFFIX): $(AX_DIR)%.c $(OBJECTS)
+ $(CC) -o $@ $(CFLAGS) $(LFLAGS) $(OBJECTS) $<
+
+# generic rule for control externals
+$(OUT_DIR)/%.$(X_SUFFIX): $(CX_DIR)%.c $(OBJECTS)
+ $(CC) -o $@ $(CFLAGS) $(LFLAGS) $(OBJECTS) $<
+
+SUBDIRS = @for i in $(MIXED_DIRS) and_in_case_it_is_null ; \
+ do ( if [ -d $$i ] ; then \
+ cd $$i; $(MAKE) $@ ; fi ) ; done
+
+SUBDIRS_DEFAULT = @for i in $(MIXED_DIRS) and_in_case_it_is_null ; \
+ do ( if [ -d $$i ] ; then \
+ cd $$i; $(MAKE) ; fi ) ; done
+
+define_build:
+ @if [[ -f build_counter && \
+ `date -r build_counter +%j` != `date +%j` ]] ; then \
+ mv build_counter build_counter~ ; \
+ echo -n 'increment build counter (y/n)? [n]' ; read doit ; \
+ if [ $$doit ] && [ $$doit == 'y' ] ; then \
+ cat build_counter~ | \
+ awk '{if (index($$2,"BUILD")) print $$1, $$2, $$3+1; else print}' \
+ > build_counter ; \
+ cat build_counter | \
+ awk 'BEGIN {printf toupper("$(BASE_NAME)_VERSION = ")} \
+ {gsub("\"","",$$3); printf $$3; if (NR==1) printf "-"} \
+ END {printf "\r\n" }' > $(ROOT_DIR)/ViCious/$(BASE_DIR)/version ; \
+ else cat build_counter~ > build_counter ; fi \
+ fi
+
+all$(BASE_NAME)s.c: Makefile.sources
+ $(ROOT_DIR)/dumpsetups > $@
+
+all: $(EXTERNS)
+ $(SUBDIRS_DEFAULT)
+
+clean: emptydeps
+# remove all objects and externs that are contained in current directory
+ -rm -f *.o *.$(X_SUFFIX)
+ $(SUBDIRS)
+
+cleanall: clean
+# remove default target externs
+ -rm -f $(EXTERNS)
+
+OLDROOT_DIR = $(shell ls -d -1 ../../Mixed-* | tail -1)
+
+diff:
+ @echo -n > diff.out ; \
+ for f in {*.h,*.c} ; do \
+ if [ -f $$f ] ; then \
+ diff -u $(OLDROOT_DIR)/$(BASE_DIR)/$$f $$f >> diff.out ; \
+ fi \
+ done
+
+VERSION = $(shell awk \
+ '{if (index($$2,"VERSION")) print substr($$3,2,length($$3)-2)}' \
+ build_counter)
+RELEASE = $(shell awk \
+ '{if (index($$2,"RELEASE")) print substr($$3,2,length($$3)-2)}' \
+ build_counter)
+BUILD = $(shell awk '{if (index($$2,"BUILD")) print $$3}' build_counter)
+
+RELEASE_STUB = release/$(BASE_NAME)-$(VERSION)-$(RELEASE)$(BUILD)
+SRC_TAR = $(RELEASE_STUB)-src.tar
+BIN_TAR = $(RELEASE_STUB)-bin.tar
+LIB_TAR = $(RELEASE_STUB)-lib.tar
+DOC_TAR = $(RELEASE_STUB)-doc.tar
+ALL_TAR = $(RELEASE_STUB)-all.tar
+REL_BINDIR = bin
+
+REL_LIBNAMES = $(foreach fn,$(RELEASE_LIBS:=.$(X_SUFFIX)),$(REL_BINDIR)/$(fn))
+
+REL_EXTERNS = $(foreach fn,$(CX_NAMES:.c=.$(X_SUFFIX)),$(REL_BINDIR)/$(fn)) \
+ $(foreach fn,$(AX_NAMES:.c=~.$(X_SUFFIX)),$(REL_BINDIR)/$(fn)) \
+ $(REL_LIBNAMES) $(REL_BINDIR)/$(RELEASE_APPS) \
+ $(foreach type,$(TYPES),\
+ $(foreach fn,$(call TYPES_EXTERNS,$(type)),$(REL_BINDIR)/$(fn)))
+
+REL_ROOTSRC = LICENSE.txt Makefile.common dumpsetups
+
+srelease: emptydeps define_build
+ cd $(ROOT_DIR)/shared; $(MAKE) emptydeps
+ cd $(ROOT_DIR); tar -X $(BASE_DIR)/$(BASE_NAME)-all.exclude -cf \
+ $(SRC_TAR) $(BASE_DIR)/* $(REL_ROOTSRC)
+ cd $(ROOT_DIR); tar -T $(BASE_DIR)/$(BASE_NAME)-shared.include -rf \
+ $(SRC_TAR)
+ cd $(ROOT_DIR); gzip -f $(SRC_TAR)
+
+stestrelease: emptydeps define_build
+ cd $(ROOT_DIR)/shared; $(MAKE) emptydeps
+ cd $(ROOT_DIR); tar -X $(BASE_DIR)/$(BASE_NAME)-all.exclude -cf \
+ $(SRC_TAR) $(BASE_DIR)/* $(REL_ROOTSRC)
+ cd $(ROOT_DIR); tar -T $(BASE_DIR)/$(BASE_NAME)-shared.include -rf \
+ $(SRC_TAR)
+ cd $(ROOT_DIR); tar -X $(BASE_DIR)/$(BASE_NAME)-test.exclude -rf \
+ $(SRC_TAR) test/$(BASE_NAME)/*
+ cd $(ROOT_DIR); tar -X $(BASE_DIR)/$(BASE_NAME)-vicious.exclude -rf \
+ $(SRC_TAR) ViCious/$(BASE_DIR)/*
+ cd $(ROOT_DIR); gzip -f $(SRC_TAR)
+
+brelease: define_build
+ cd $(ROOT_DIR); tar zcf \
+ $(BIN_TAR).gz $(REL_EXTERNS)
+
+rellibs:
+ cd $(ROOT_DIR); tar zcf \
+ $(LIB_TAR).gz $(REL_LIBNAMES)
+
+drelease: define_build
+ cd $(ROOT_DIR); tar -X $(BASE_DIR)/$(BASE_NAME)-doc.exclude -zcf \
+ $(DOC_TAR).gz doc/examples/$(BASE_NAME)/*
+
+release: srelease brelease drelease
+ cd $(ROOT_DIR); tar -X $(BASE_DIR)/$(BASE_NAME)-all.exclude -cf \
+ $(ALL_TAR) $(BASE_DIR)/* $(REL_ROOTSRC) $(REL_EXTERNS)
+ cd $(ROOT_DIR); tar -T $(BASE_DIR)/$(BASE_NAME)-shared.include -rf \
+ $(ALL_TAR)
+ cd $(ROOT_DIR); tar -X $(BASE_DIR)/$(BASE_NAME)-doc.exclude -rf \
+ $(ALL_TAR) doc/examples/$(BASE_NAME)/*
+ cd $(ROOT_DIR); gzip -f $(ALL_TAR)
+
+testrelease: stestrelease brelease
+ cd $(ROOT_DIR); tar -X $(BASE_DIR)/$(BASE_NAME)-all.exclude -cf \
+ $(ALL_TAR) $(BASE_DIR)/* $(REL_ROOTSRC) $(REL_EXTERNS)
+ cd $(ROOT_DIR); tar -T $(BASE_DIR)/$(BASE_NAME)-shared.include -rf \
+ $(ALL_TAR)
+ cd $(ROOT_DIR); tar -X $(BASE_DIR)/$(BASE_NAME)-test.exclude -rf \
+ $(ALL_TAR) test/$(BASE_NAME)/*
+ cd $(ROOT_DIR); tar -X $(BASE_DIR)/$(BASE_NAME)-vicious.exclude -rf \
+ $(ALL_TAR) ViCious/$(BASE_DIR)/*
+ cd $(ROOT_DIR); gzip -f $(ALL_TAR)
+
+snap: emptyalldeps testrelease rellibs
+
+depend:
+ $(CC) $(CFLAGS) -M $(SOURCES) > Makefile.deps
+ $(SUBDIRS)
+
+emptydeps:
+ -rm -f Makefile.deps
+ touch Makefile.deps
+ chmod 666 Makefile.deps
+
+emptyalldeps: emptydeps
+ $(SUBDIRS)
+
+Makefile.deps:
+ touch Makefile.deps
+ chmod 666 Makefile.deps
+
+-include Makefile.deps