aboutsummaryrefslogtreecommitdiff
path: root/composer/Makefile
blob: c2d5e732be17fc90f82495fbf39601841d22c7fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/make

DEBUG?=0
OS := $(shell uname -s)
TCL_VERSION := $(shell echo 'puts $$tcl_version' | tclsh)

ifeq ($(DEBUG),0)
	CFLAGS += -O2
else
	CFLAGS += -O0 -g -ggdb -DDEBUG
endif
ifeq ($(OS),Linux)
  PDSUF = .pd_linux
  PDBUNDLEFLAGS = -shared -rdynamic
  LDSOFLAGS = -lm
endif
ifeq ($(OS),Darwin)
  PDSUF = .pd_darwin
  INCLUDES = -I/Library/Frameworks/Tcl.framework/Headers
  PDBUNDLEFLAGS = -bundle -flat_namespace -undefined dynamic_lookup
  LDSOFLAGS = -lm
endif
ifeq (MINGW,$(findstring MINGW,$(UNAME)))
  PDSUF = .dll
  PDBUNDLEFLAGS = -shared
  LDSOFLAGS = -lm
endif

LIBNAME = composer
INCLUDES =  -I../../pd/src -I/usr/include #-I/usr/include/tcl$(TCL_VERSION)
CFLAGS += -funroll-loops -fno-operator-names -fno-omit-frame-pointer -falign-functions=16
CFLAGS += -Wall -Wno-unused
CFLAGS += -fPIC
CFLAGS += -DPDSUF=\"$(PDSUF)\"
LDSHARED = $(CXX) $(PDBUNDLEFLAGS)

all: autogen_sources $(LIBNAME)$(PDSUF)
	@echo '-----------------------------------------------------------------------------'
	@echo ' $(LIBNAME)$(PDSUF) ('`test $(DEBUG) -eq 1 && echo debug || echo release`' build) '\
		'[size: '`ls -gGh $(LIBNAME)$(PDSUF) | cut -d " " -f 3`']'

clean::
	rm -f $(LIBNAME)$(PDSUF)
	rm -f *.o *~
	rm -f $(AUTOGENERATED_SOURCES)
	rm -f editor_tk.cpp

.SUFFIXES: .cpp .o

SRCS = HasMeta.cpp Song.cpp Pattern.cpp Track.cpp Editor.o PdClasses.cpp
OBJS = ${SRCS:.cpp=.o}
AUTOGENERATED_SOURCES = methods.hpp methods_pd.hpp methods_ed.hpp classsetup.cpp callwrappers_pd.cpp callwrappers_ed.cpp
HasMeta.o: HasMeta.cpp HasMeta.hpp
Song.o: Song.cpp Song.hpp
Pattern.o: Pattern.cpp Pattern.hpp
Track.o: Track.cpp Track.hpp
Editor.o: Editor.cpp Editor.hpp editor_tk.cpp
PdClasses.o: PdClasses.cpp PdClasses.hpp

.cpp.o: Makefile
	$(CXX) $(CFLAGS) $(INCLUDES) -xc++ -c $<

$(LIBNAME)$(PDSUF): Makefile $(OBJS)
	$(LDSHARED) $(LDSOFLAGS) $(CFLAGS) -xnone $(OBJS) -o $(LIBNAME)$(PDSUF)

editor_tk.cpp: editor.tk
	@echo "Generating $@..."
	@( echo 'static const char* editor_tk[] = {'; sed -e 's/\(["\\]\)/\\\1/g' -e 's/^/"/' -e 's/$$/",/' editor.tk; echo '"" };' ) > editor_tk.cpp

autogen_sources: $(AUTOGENERATED_SOURCES)

methods.hpp: PdClasses.hpp
	@echo "Generating $@..."
	@awk ' \
		/^\/\*#end methods\*\/$$/{M=0} \
		{if(M==1) print $$0} \
		/^\/\*#begin methods\*\/$$/{M=1}' \
		PdClasses.hpp \
	| sed \
		-e 's/\> *\(\**\) *\w\+\(,\|)\)/\1\2/g' \
		-e 's/(/( /' -e 's/)/ )/' \
	| awk '{ \
		for(x=1; x<NF; x++) { \
			if(x<=2||x==NF) \
				printf($$x" "); \
			else \
				printf($$x" arg"(x-3)", "); \
		} \
		printf("\n"); \
		}' \
	| sed \
		-e 's/,\( arg[0-9]\+\)/\1/g' \
		-e 's/, $$/);/' \
		-e 's/( /(/' \
	> methods.hpp

methods_pd.hpp: methods.hpp
	@echo "Generating $@..."
	@sed -e 's/\<track_proxy_\w\+\>/\0P/' methods.hpp > methods_pd.hpp

methods_ed.hpp: methods.hpp
	@echo "Generating $@..."
	@sed -e 's/\<track_proxy_\w\+\>/\0E/' methods.hpp > methods_ed.hpp

classsetup.cpp: methods.hpp
	@echo "Generating $@..."
	@sed \
		-e 's/\<track_proxy_\(\w\+\)\>/\0 \1/' \
		-e 's/);$$/, /' \
		-e 's/(t_track_proxy\* arg0,\?//' \
		-e 's/ arg[0-9]\+, / /g' \
		-e 's/\<t_symbol\* int t_atom\>\*/A_GIMME, /g' \
		-e 's/\<t_symbol\>\*/A_SYMBOL, /g' \
		-e 's/\<t_floatarg\>/A_FLOAT, /g' \
		methods.hpp \
	| awk '{ \
		printf("class_addmethod(track_proxy_class, (t_method)%sP, gensym(\"%s\"), ", $$2, $$3); \
		for(i=4; i<=NF; i++) printf("%s ", $$i); \
		printf("A_NULL);\n"); \
		\
		printf("class_addmethod(track_proxy_class, (t_method)%sE, gensym(\"%sE\"), ", $$2, $$3); \
		for(i=4; i<=NF; i++) printf("%s ", $$i); \
		printf("A_NULL);\n"); \
	}' \
	> classsetup.cpp

callwrappers_pd.cpp: methods.hpp
	@echo "Generating $@..."
	@sed \
		-e 's/;$$//' \
		-e 's/^\(.*\)\(\<track_proxy_\w\+\>\)\((.*)\)$$/\1\2P\3 {\n    \2\3;\/\/real call\n    track_proxy_send_result(arg0, 1, 0);\n    return 0;\n}/' \
		methods.hpp \
	| sed \
		-e '/\/\/real call/s/(t_track_proxy\* arg0/(arg0/' \
		-e '/\/\/real call/s/\(arg[0-9]\+, \)[A-Za-z_*]\+ \(arg[0-9]\+\)/\1\2/g' \
		-e '/\/\/real call/s/\(arg[0-9]\+, \)[A-Za-z_*]\+ \(arg[0-9]\+\)/\1\2/g' \
	> callwrappers_pd.cpp

callwrappers_ed.cpp: methods.hpp
	@echo "Generating $@..."
	@sed \
		-e 's/;$$//' \
		-e 's/^\(.*\)\(\<track_proxy_\w\+\>\)\((.*)\)$$/\1\2E\3 {\n    \2\3;\/\/real call\n    track_proxy_send_result(arg0, 0, 1);\n    return 0;\n}/' \
		methods.hpp \
	| sed \
		-e '/\/\/real call/s/(t_track_proxy\* arg0/(arg0/' \
		-e '/\/\/real call/s/\(arg[0-9]\+, \)[A-Za-z_*]\+ \(arg[0-9]\+\)/\1\2/g' \
		-e '/\/\/real call/s/\(arg[0-9]\+, \)[A-Za-z_*]\+ \(arg[0-9]\+\)/\1\2/g' \
	> callwrappers_ed.cpp