aboutsummaryrefslogtreecommitdiff
blob: cbc9f3bc889526a79604c2706d7f314af22f377b (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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
###############################################
#Please use git log for copyright holder and year information
#
#This file is part of libbash.
#
#libbash is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation, either version 2 of the License, or
#(at your option) any later version.
#
#libbash is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with libbash.  If not, see <http://www.gnu.org/licenses/>.
###############################################
# Makefile.am for libbash
# Author: Nathan Eloe
###############################################
include doc/doxygen.am

ACLOCAL_AMFLAGS = -I m4

TEST_EXTENSIONS= .gunit .bash .ebuild
GUNIT_LOG_COMPILER = $(srcdir)/bashast/gunit/runtests.sh
AM_GUNIT_LOG_FLAGS = @antlr_cp@:.
GUNIT_TESTS = bashast/gunit/arith_main.gunit \
			  bashast/gunit/array.gunit \
			  bashast/gunit/assoc_array.gunit \
			  bashast/gunit/brace.gunit \
			  bashast/gunit/command_sub.gunit \
			  bashast/gunit/comment.gunit \
			  bashast/gunit/compound.gunit \
			  bashast/gunit/cond_main.gunit \
			  bashast/gunit/continued_lines.gunit \
			  bashast/gunit/expansions.gunit \
			  bashast/gunit/fname.gunit \
			  bashast/gunit/function.gunit \
			  bashast/gunit/list.gunit \
			  bashast/gunit/param_main.gunit \
			  bashast/gunit/pipeline.gunit \
			  bashast/gunit/process_substitution.gunit \
			  bashast/gunit/redir.gunit \
			  bashast/gunit/simp_command.gunit \
			  bashast/gunit/simp_prog.gunit

BASH_LOG_COMPILER = $(srcdir)/test/bash_compiler.sh
BASH_TESTS = scripts/var_def.bash \
			 scripts/command_execution.bash \
			 scripts/function_def.bash \
			 scripts/arithmetic_assignment.bash \
			 scripts/var_expansion.bash \
			 scripts/test_expr.bash \
			 scripts/isolated_functions.bash \
			 scripts/compound_command.bash \
			 scripts/binary_arithmetic.bash

EBUILD_LOG_COMPILER = $(srcdir)/test/ebuild_compiler.sh
EBUILD_TESTS = scripts/sunpinyin-2.0.3-r1.ebuild
EBUILD_RESULT = scripts/sunpinyin-2.0.3-r1.ebuild.result

TESTS = $(GUNIT_TESTS) $(BASH_TESTS) $(EBUILD_TESTS)
# these get cleaned so only add autogenerated stuff or modify CLEANFILES
check_JAVA = bashast/java_libbashLexer.java bashast/java_libbashParser.java
AM_JAVACFLAGS = -source 1.4 -classpath @antlr_cp@

AM_CXXFLAGS = -std=c++0x
AM_CPPFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/include

if DEVELOPER_MODE
# -Weffc++ seems to be giving false positives on protected non
# virtual destructors in base classes
AM_CXXFLAGS += -Wall \
			   -Wextra \
			   -Wold-style-cast \
			   -Woverloaded-virtual \
			   -Wsign-promo \
			   -pedantic-errors \
			   -Werror
AM_CPPFLAGS += -D_GLIBCXX_DEBUG
endif

if HAVE_GTEST
TESTS += cppunittests \
		 test/verify_error_output_test.sh \
		 test/ast_printer_test.sh \
		 test/verify_bashs_test.sh \
		 test/verify_here_document.sh \
		 test/bash_result_tests.sh
check_PROGRAMS = cppunittests

cppunittests_SOURCES =  test/run_tests.cpp \
						src/core/tests/symbols_test.cpp \
						src/core/tests/interpreter_test.cpp \
						src/core/tests/bash_ast_test.cpp \
						src/core/tests/bash_condition_test.cpp \
						src/builtins/tests/continue_tests.cpp \
						src/builtins/tests/break_tests.cpp \
						src/builtins/tests/echo_tests.cpp \
						src/builtins/tests/declare_tests.cpp \
						src/builtins/tests/boolean_tests.cpp \
						src/builtins/tests/source_tests.cpp \
						src/builtins/tests/shift_tests.cpp \
						src/builtins/tests/shopt_tests.cpp \
						src/builtins/tests/return_tests.cpp \
						src/builtins/tests/printf_tests.cpp \
						test/test.h \
						test/test.cpp \
						test/post_check.cpp \
						test/api_test.cpp \
						test/walker_test.cpp
cppunittests_LDADD = libbash.la \
					 $(GTEST_LIBS) \
					 $(BOOST_SYSTEM_LIB) \
					 $(BOOST_FILESYSTEM_LIB)
cppunittests_LDFLAGS = -static
cppunittests_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/test/

endif

noinst_LIBRARIES = libmetadata.a

libmetadata_a_SOURCES = utils/metadata.h utils/metadata.cpp
libmetadata_a_CPPFLAGS = $(AM_CPPFLAGS) -Iutils

noinst_PROGRAMS = variable_printer metadata_generator ast_printer instruo bash

variable_printer_SOURCES = utils/variable_printer.cpp
variable_printer_LDADD = libbash.la

bash_SOURCES = utils/bash.cpp test/test.h  test/test.cpp
bash_LDADD = libbash.la
bash_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/test/

metadata_generator_SOURCES = utils/metadata_generator.cpp
metadata_generator_LDADD = libbash.la libmetadata.a
metadata_generator_CPPFLAGS = $(AM_CPPFLAGS) -Iutils

instruo_SOURCES = utils/instruo.cpp \
				  utils/command_line.cpp \
				  utils/command_line.h \
				  test/test.h \
				  test/test.cpp
instruo_LDADD = libbash.la @PALUDIS_LIBS@ libmetadata.a
instruo_CPPFLAGS = $(AM_CPPFLAGS) @PALUDIS_CFLAGS@ -Iutils -I$(top_srcdir)/test/
instruo_CXXFLAGS = $(AM_CXXFLAGS) -Wno-extra -fopenmp

ast_printer_SOURCES = utils/ast_printer.cpp
ast_printer_LDADD = libbash.la $(BOOST_PROGRAM_OPTIONS_LIB)
ast_printer_LDFLAGS = -static
# boost is probably compiled without debug STL so if that is used
# linking will fail
ast_printer_CPPFLAGS = $(AM_CPPFLAGS) -U_GLIBCXX_DEBUG $(BOOST_CPPFLAGS)

GENERATED_LEXER_CPP = libbashLexer.cpp
GENERATED_LEXER_H = libbashLexer.h
GENERATED_PARSER_CPP = libbashParser.cpp
GENERATED_PARSER_H = libbashParser.h
GENERATED_WALKER_CPP = libbashWalker.cpp
GENERATED_WALKER_H = libbashWalker.h
BUILT_SOURCES = $(GENERATED_PARSER_CPP) \
				$(GENERATED_PARSER_H) \
				$(GENERATED_LEXER_CPP) \
				$(GENERATED_LEXER_H) \
				$(GENERATED_WALKER_CPP) \
				$(GENERATED_WALKER_H) \
				$(check_JAVA)
CLEANFILES = $(GENERATED_PARSER_CPP) \
			 $(GENERATED_PARSER_H) \
			 $(GENERATED_LEXER_CPP) \
			 $(GENERATED_LEXER_H) \
			 $(GENERATED_WALKER_CPP) \
			 $(GENERATED_WALKER_H) \
			 $(check_JAVA) \
			 libbash.g \
			 java_libbash.g \
			 libbash.tokens \
			 libbash.tokens.md5 \
			 libbashWalker.h.md5 \
			 bashast/java_libbash.tokens \
			 libbashWalker.tokens \
			 javagrammar.run \
			 cgrammar.run \
			 walker.run \
			 massif.out \
			 callgrind.out

libbash_includedir = $(includedir)/libbash-@PACKAGE_VERSION@/libbash
libbash_include_HEADERS = include/libbash.h \
                          include/common.h \
                          include/divide_by_zero_error.h \
                          include/illegal_argument_exception.h \
                          include/interpreter_exception.h \
                          include/parse_exception.h \
                          include/readonly_exception.h \
                          include/runtime_exception.h \
                          include/unsupported_exception.h \
                          include/exceptions.h

lib_LTLIBRARIES = libbash.la
libbash_la_SOURCES = include/common.h \
					 include/libbash.h \
					 src/libbash.cpp \
					 src/cppbash_builtin.cpp \
					 src/cppbash_builtin.h \
					 src/builtins/continue_builtin.cpp \
					 src/builtins/continue_builtin.h \
					 src/builtins/break_builtin.cpp \
					 src/builtins/break_builtin.h \
					 src/builtins/echo_builtin.cpp \
					 src/builtins/echo_builtin.h \
					 src/builtins/eval_builtin.cpp \
					 src/builtins/eval_builtin.h \
					 src/builtins/export_builtin.cpp \
					 src/builtins/export_builtin.h \
					 src/builtins/local_builtin.cpp \
					 src/builtins/local_builtin.h \
					 src/builtins/declare_builtin.cpp \
					 src/builtins/declare_builtin.h \
					 src/builtins/boolean_builtins.h \
					 src/builtins/source_builtin.h \
					 src/builtins/source_builtin.cpp \
					 src/builtins/shift_builtin.h \
					 src/builtins/shift_builtin.cpp \
					 src/builtins/shopt_builtin.h \
					 src/builtins/shopt_builtin.cpp \
					 src/builtins/return_builtin.h \
					 src/builtins/return_builtin.cpp \
					 src/builtins/printf_builtin.h \
					 src/builtins/printf_builtin.cpp \
					 src/builtins/let_builtin.h \
					 src/builtins/let_builtin.cpp \
					 src/builtins/inherit_builtin.h \
					 src/builtins/inherit_builtin.cpp \
					 src/builtins/unset_builtin.h \
					 src/builtins/unset_builtin.cpp \
					 src/builtins/builtin_exceptions.h \
					 $(GENERATED_PARSER_C) \
					 $(GENERATED_PARSER_H) \
					 include/divide_by_zero_error.h \
					 include/exceptions.h \
					 include/illegal_argument_exception.h \
					 include/interpreter_exception.h \
					 include/parse_exception.h \
					 include/readonly_exception.h \
					 include/runtime_exception.h \
					 include/unsupported_exception.h \
					 src/core/interpreter.cpp \
					 src/core/interpreter.h \
					 src/core/symbols.hpp \
					 src/core/function.h \
					 src/core/function.cpp \
					 src/core/bash_condition.h \
					 src/core/bash_condition.cpp \
					 src/core/bash_ast.cpp \
					 src/core/bash_ast.h

# separate library because we need per file CXXFLAGS
# as antlr generated code does not pass our strict developer
# warning settings
noinst_LTLIBRARIES = libparser.la libwalker.la
libparser_la_SOURCES = $(GENERATED_PARSER_CPP) \
					   $(GENERATED_PARSER_H) \
					   $(GENERATED_LEXER_CPP) \
					   $(GENERATED_LEXER_H)

libparser_la_CXXFLAGS = -std=c++0x \
						-fvisibility=hidden \
						-fvisibility-inlines-hidden

libwalker_la_SOURCES = $(GENERATED_WALKER_CPP) \
					   $(GENERATED_WALKER_H)

libwalker_la_CXXFLAGS = -std=c++0x \
						-fvisibility=hidden \
						-fvisibility-inlines-hidden

libbash_la_CXXFLAGS = $(AM_CXXFLAGS) \
						 -fvisibility=hidden \
						 -fvisibility-inlines-hidden
if DEVELOPER_MODE
# Paludis cannot get compiled with these flags.
# So we only turn them on for our library.
libbash_la_CXXFLAGS += -Wconversion -Wsign-conversion
endif
libbash_la_CFLAGS = $(AM_CFLAGS) -fvisibility=hidden
libbash_la_LIBADD = libparser.la libwalker.la
libbash_la_LDFLAGS = -version-info $(LIBBASH_SO_VERSION)

EXTRA_DIST = bashast/bashast.g \
			 bashast/libbashWalker.g \
			 bashast/features_script/features.sh \
			 bashast/features_script/features.sh.ast \
			 bashast/features_script/features.sh.tokens \
			 bashast/features_script/features.sh.walker.tokens \
			 test/ast_printer_test.sh \
			 test/verify_bashs_test.sh \
			 test/verify_error_output_test.sh \
			 test/verify_here_document.sh \
			 test/bash_result_tests.sh \
			 scripts/naughty_tests \
			 scripts/naughty_tests.result \
			 scripts/here_document.ast \
			 scripts/here_document.sh \
			 scripts/source_false.sh \
			 scripts/source_true.sh \
			 scripts/source_return.sh \
			 scripts/illegal_script.sh \
			 scripts/illegal_script.sh.tokens \
			 scripts/foo.eclass \
			 scripts/bar.eclass \
			 utils/metadata_diff.sh \
			 utils/isolated-functions.sh \
			 test/test_coverage.sh \
			 autogen.sh \
			 $(BASH_TESTS) \
			 $(EBUILD_TESTS) \
			 $(EBUILD_RESULT) \
			 $(GUNIT_TESTS) \
			 $(GUNIT_LOG_COMPILER) \
			 $(BASH_LOG_COMPILER) \
			 $(EBUILD_LOG_COMPILER)

pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libbash.pc

coding_standard.pdf: coding_standard/coding_standard.tex
	$(AM_V_GEN)@PDFLATEX@ coding_standard/coding_standard.tex 2&>1 > /dev/null

ANTLR = @JAVA@ -classpath @antlr_cp@ org.antlr.Tool $(ANTLRFLAGS)

cgrammar.run: libbash.g
	$(AM_V_at)touch $@.tmp
	$(AM_V_GEN)$(ANTLR) -fo . $<
	$(AM_V_at)mv libbashParser.{c,cpp}
	$(AM_V_at)mv libbashLexer.{c,cpp}
	$(AM_V_at)mv $@.tmp $@

libbash.g: bashast/bashast.g
	$(AM_V_at)$(CC) -E -x c++ -D OUTPUT_C $< > $@
	$(AM_V_at)sed -i '/^#.*/d' $@
	$(AM_V_at)sed -i 's/C_INCLUDE \(.*\)/\1/' $@

# http://www.kolpackov.net/pipermail/notes/2004-September.txt
libbash.tokens.md5: libbash.tokens
	$(AM_V_at)md5sum $< | cmp -s $@ -; if test $$? -ne 0; then md5sum $< > $@; fi

# Avoid initializing C++ type to NULL by sed, variables whose name
# starts with libbash_ will be stripped
# The date information is removed from libbashWalker.h in order to make the md5 trick working
walker.run: bashast/libbashWalker.g libbash.tokens.md5
	$(AM_V_at)touch $@.tmp
	$(AM_V_at)if test -a libbashWalker.h; then mv libbashWalker.h libbashWalker.h.bak; fi
	$(AM_V_GEN)$(ANTLR) -fo . $<
	$(AM_V_at)sed -i '/ *     -                            On/d' libbashWalker.h
	$(AM_V_at)md5sum libbashWalker.h | cmp -s libbashWalker.h.md5 -; \
		if test $$? -ne 0; then \
			md5sum libbashWalker.h > libbashWalker.h.md5; \
		elif test -a libbashWalker.h.bak; then \
			mv libbashWalker.h.bak libbashWalker.h; \
		fi
	$(AM_V_at)sed -i -e 's/\(libbash_.*\) = NULL/\1/' libbashWalker.c
	$(AM_V_at)mv libbashWalker.{c,cpp}
	$(AM_V_at)mv $@.tmp $@

$(GENERATED_PARSER_CPP): cgrammar.run
$(GENERATED_PARSER_H): cgrammar.run
$(GENERATED_LEXER_CPP): cgrammar.run
$(GENERATED_LEXER_H): cgrammar.run
libbash.tokens: cgrammar.run

$(GENERATED_WALKER_CPP): walker.run
$(GENERATED_WALKER_H): walker.run

java_libbash.g: bashast/bashast.g
	$(AM_V_at)$(CC) -E -x c++ -D OUTPUT_JAVA $< > $@
	$(AM_V_at)sed -i '/^#.*/d' $@

javagrammar.run: java_libbash.g
	$(AM_V_at)touch $@.tmp
	$(AM_V_GEN)$(ANTLR) -fo bashast $<
	$(AM_V_at)mv $@.tmp $@

$(check_JAVA): javagrammar.run

massif.out: ast_printer
		libtool --mode=execute valgrind \
		--tool=massif --massif-out-file=massif.out \
		./ast_printer -nsf /usr/portage/eclass/versionator.eclass

massif: massif.out
	ms_print --threshold=10 $<

callgrind.out: ast_printer
	libtool --mode=execute valgrind \
		--tool=callgrind --callgrind-out-file=callgrind.out \
		./instruo -D /usr/portage/ --output-dir metadata_output

benchmark_parser: callgrind.out
	callgrind_annotate callgrind.out

test_coverage: dist
	MAKE=$(MAKE) DIST_ARCHIVES=$(DIST_ARCHIVES) test/test_coverage.sh
	rm $(DIST_ARCHIVES)