00001 # From here all variables are expected to be updated, as first all 00002 # the variables of englobing projects should be set, then only rules 00003 # based on that variables should be defined. 00004 00005 00006 00007 # Now defining the generic rules operating on the variables. 00008 00009 ERL_FILES = $(wildcard *.erl) 00010 00011 # Includes test beams: 00012 BEAM_FILES = $(patsubst %.erl,%.beam,$(ERL_FILES)) 00013 00014 TEST_SOURCES = $(wildcard *_test.erl) 00015 00016 TEST_TARGETS = $(patsubst %.erl,%,$(TEST_SOURCES)) 00017 00018 00019 # Regarding dependency management. 00020 # 00021 # One can just ignore dependencies and rebuild "blindly" every module in 00022 # current subtree. 00023 # One just has not to forget to issue 'make' from a right location, before 00024 # running one's Erlang program. 00025 00026 # Another option is to track dependencies explicitly. 00027 # We found no existing way of managing dependencies automatically, thus 00028 # they have to be declared by hand. 00029 # We want these user-specified dependencies to work with the generic 00030 # rules to build beam files and to run programs. 00031 # For example, 'make MyObject_run' would check MyObject_test.beam 00032 # and its dependencies before running it. 00033 # A generic rule like: '%.beam: %.erl' would not take into account 00034 # dependencies. 00035 # A generic rule like: '%.beam: %.erl %_dependencies' with 00036 # a definition like 'MyObject_dependencies: A.beam moduleB.beam' 00037 # would work (and modules not depending on others could be managed with a 00038 # second generic rule: '%.beam: %.erl'), but generic targets, as 00039 # defined in GNUmakerules.inc, seem to be *always* rebuilt, not depending 00040 # on their .PHONY status. 00041 # In our case, MyObject.beam (and all its 00042 # prerequisites!) would thus always be rebuilt, even if no change at all was 00043 # operated on the corresponding sources, which would not be acceptable. 00044 00045 # Thus we stick from now to the basic strategy: always issue a global 'make' 00046 # at the root of the source before running a program, otherwise be doomed 00047 # (changes not taken into account at run-time, as not recompiled). 00048 00049 00050 .PHONY: all all-parallel-recurse all-recurse \ 00051 test test-recurse doc-recurse build-tests launch \ 00052 install-all install-announce install-ebin install-bin install-src \ 00053 install-include install-examples install-test install-doc \ 00054 info-install \ 00055 help-erl clean clean-erlang clean-database clean-recurse realclean \ 00056 info info-files $(MODULES_DIRS) 00057 00058 00059 00060 # Note: long lines in rules should not be word-wrapped (with \), as their 00061 # displaying on the console would print them, leading to poorly dense outputs, 00062 # that are not pleasing to the eye. 00063 00064 00065 all: all-recurse $(BEAM_FILES) 00066 00067 00068 # This rule is not used by default, as we use the -j option from the root 00069 # makefile, letting then 'make' use its job server for that task: 00070 all-parallel-recurse: 00071 @echo " Building all on parallel over $(CORE_COUNT) cores (in "$(PWD) #`basename $(PWD)` 00072 @for m in $(MODULES_DIRS); do if ! ( if [ -d $$m ] ; then cd $$m && $(MAKE) -s all -j $(CORE_COUNT) CMD_LINE_OPT="${CMD_LINE_OPT}" && cd .. ; else echo " (directory $$m skipped)" ; fi ) ; then exit 1; fi ; done 00073 00074 00075 all-recurse: 00076 @echo " Building all in "$(PWD) #`basename $(PWD)` 00077 @for m in $(MODULES_DIRS); do if ! ( if [ -d $$m ] ; then cd $$m && $(MAKE) -s all CMD_LINE_OPT="${CMD_LINE_OPT}" && cd .. ; else echo " (directory $$m skipped)" ; fi ) ; then exit 1; fi ; done 00078 00079 00080 %.beam: %.erl %.hrl 00081 @echo " Compiling module with header $<" 00082 @$(ERLANG_COMPILER) $(ERLANG_COMPILER_OPT) -o $@ $< 00083 00084 00085 %.beam: %.erl 00086 @echo " Compiling module $<" 00087 @$(ERLANG_COMPILER) $(ERLANG_COMPILER_OPT) -o $@ $< 00088 00089 00090 00091 00092 00093 # Applications are meant to be executed, whereas tests are meant to be run: 00094 # they have different suffixes (_app vs _test) and ways of being launched 00095 # (make X_exec / make X_run) otherwise, for example, my_server_app.erl would 00096 # shadow my_server_test.erl if an ambiguous 'make my_server_run' was issued. 00097 00098 00099 00100 # Application section. 00101 00102 00103 # 'X_exec' becomes 'X_app:exec()': 00104 00105 00106 %_exec: %_app.beam %.beam 00107 @echo " Executing application $^ (first form)" 00108 $(ERL_PARAMETERIZED_LAUNCHER) --ln $@-$$USER --eval `echo $@|sed 's|_exec|_app:exec()|1'` $(INTERNAL_OPTIONS) $(CMD_LINE_OPT) 00109 00110 00111 %_exec: %_app.beam 00112 @echo " Executing application $^ (second form)" 00113 @$(ERL_PARAMETERIZED_LAUNCHER) --ln $@-$$USER --eval `echo $@|sed 's|_exec|_app:exec()|1'` $(INTERNAL_OPTIONS) $(CMD_LINE_OPT) 00114 00115 00116 00117 # To run in the background (somewhat like a daemon): 00118 # Note: the specified long name (with --ln) has its '_background' suffix 00119 # removed so that the node name of an executable does not depend from how 00120 # it is launched, otherwise clients needing to connect to that node would 00121 # themselves depend on that. 00122 00123 %_exec_background: %_app.beam %.beam 00124 @echo " Executing application $^ in the background (first form)" 00125 @$(ERL_PARAMETERIZED_LAUNCHER) --ln `echo $@|sed 's|_background$$||1'`-$$USER --background --eval `echo $@|sed 's|_exec_background|_app:exec()|1'` $(INTERNAL_OPTIONS) $(CMD_LINE_OPT) & 00126 00127 00128 %_exec_background: %_app.beam 00129 @echo " Executing application $^ in the background (second form)" 00130 @$(ERL_PARAMETERIZED_LAUNCHER) --ln `echo $@|sed 's|_background$$||1'`-$$USER --background --eval `echo $@|sed 's|_exec_background|_app:exec()|1'` $(INTERNAL_OPTIONS) $(CMD_LINE_OPT) & 00131 00132 00133 00134 00135 # Test section. 00136 00137 00138 #%_test: %.beam %_test.beam 00139 # @echo " Running test function $(STARTUP_FUNCTION) in module $@" 00140 # @$(ERLANG_INTERPRETER) $(ERLANG_INTERPRETER_OPT) -run $@ $(STARTUP_FUNCTION) 00141 00142 00143 #%_test: %_test.beam 00144 # @echo " Running test function $(STARTUP_FUNCTION) in module $@" 00145 # @$(ERLANG_INTERPRETER) $(ERLANG_INTERPRETER_OPT) -run $@ $(STARTUP_FUNCTION) 00146 00147 00148 00149 %_test: %.beam %_test.beam 00150 @# Even just a comment is needed here, to force rebuild. 00151 00152 00153 %_test: %_test.beam 00154 @# Even just a comment is needed here, to force rebuild. 00155 00156 00157 %_interactive_test: %.beam %_interactive_test.beam 00158 @echo " Executing interactively test function " 00159 "$(STARTUP_FUNCTION) in module $@" 00160 @$(ERLANG_INTERPRETER) $(ERLANG_INTERPRETER_OPT) -run $@ $(STARTUP_FUNCTION) $(INTERNAL_OPTIONS) 00161 00162 00163 %_batch_test: %.beam %_batch_test.beam 00164 @echo " Executing non-interactively test function " 00165 "$(STARTUP_FUNCTION) in module $@" 00166 @$(ERLANG_INTERPRETER) $(ERLANG_INTERPRETER_OPT) -run $@ $(STARTUP_FUNCTION) $(INTERNAL_OPTIONS) 00167 00168 00169 00170 # _integration prefix added not to match instead of the next rule. 00171 # %_integration_dependencies target is a phony target, so that test dependencies 00172 # can be specified. 00173 %_integration_run: %_integration_test.beam %_integration_dependencies 00174 @echo " Running integration test $@ from $^ " 00175 "with $(ERL_PARAMETERIZED_LAUNCHER)" 00176 @$(ERL_PARAMETERIZED_LAUNCHER) --ln $@-$$USER --eval `echo $@|sed 's|_run|_test:run()|1'` $(INTERNAL_OPTIONS) $(CMD_LINE_OPT) 00177 00178 00179 00180 00181 00182 # 'X_run' becomes 'X_test:run()': 00183 00184 00185 %_run: %_test %_test_dependencies 00186 @echo " Running unitary test $@ (first form) from $^, with $(ERL_PARAMETERIZED_LAUNCHER)" 00187 @$(ERL_PARAMETERIZED_LAUNCHER) --ln $@-$$USER --eval `echo $@|sed 's|_run|_test:run()|1'` $(INTERNAL_OPTIONS) $(CMD_LINE_OPT) 00188 00189 00190 %_run: %_test %.beam 00191 @echo " Running unitary test $@ (second form) from $^" 00192 $(ERL_PARAMETERIZED_LAUNCHER) --ln $@-$$USER --eval `echo $@|sed 's|_run|_test:run()|1'` $(INTERNAL_OPTIONS) $(CMD_LINE_OPT) 00193 00194 00195 %_run: %_test 00196 @echo " Running unitary test $@ (third form) from $^" 00197 @$(ERL_PARAMETERIZED_LAUNCHER) --ln $@-$$USER --eval `echo $@|sed 's|_run|_test:run()|1'` $(INTERNAL_OPTIONS) $(CMD_LINE_OPT) 00198 00199 00200 test: all test-recurse 00201 @for t in $(TEST_TARGETS); do if ! $(MAKE) -s `echo $$t|sed 's|_test|_run|1'` CMD_LINE_OPT="${CMD_LINE_OPT} --batch"; then exit 1; fi ; done 00202 00203 00204 test-recurse: 00205 @echo " Testing all in "`basename $(PWD)` 00206 @for m in $(MODULES_DIRS); do if ! ( if [ -d $$m ] ; then cd $$m && $(MAKE) -s test CMD_LINE_OPT="${CMD_LINE_OPT} --batch" && cd .. ; else echo " (directory $$m skipped)" ; fi ) ; then exit 1; fi ; done 00207 00208 00209 # Best placed here rather than in GNUmakerules-docutils.inc: 00210 doc: doc-recurse 00211 00212 doc-recurse: 00213 @echo " Preparing documentation in "$(PWD) #`basename $(PWD)` 00214 @for m in $(MODULES_DIRS); do if ! ( if [ -d $$m ] ; then cd $$m && $(MAKE) -s doc CMD_LINE_OPT="${CMD_LINE_OPT}" && cd .. ; else echo " (directory $$m skipped)" ; fi ) ; then exit 1; fi ; done 00215 00216 00217 00218 # Not used any more now that all beams are always built: 00219 build-tests: $(BEAM_FILES) 00220 @for t in $(TEST_TARGETS); do $(MAKE) -s $$t CMD_LINE_OPT="${CMD_LINE_OPT}"; done 00221 00222 00223 launch: Emakefile 00224 @echo " Launching interpreter with default Ceylan settings" 00225 @${ERL_PARAMETERIZED_LAUNCHER} --ln test_shell-$$USER $(INTERNAL_OPTIONS) $(CMD_LINE_OPT) 00226 00227 00228 00229 00230 # Installation section. 00231 00232 00233 00234 install: all doc install-all 00235 00236 # We do not want to generate documentation in production: 00237 install-prod: all install-prod-all 00238 00239 00240 00241 install-all: install-announce install-bin install-ebin install-src \ 00242 install-include install-examples install-test install-doc 00243 00244 00245 install-prod-all: install-prod-announce install-bin install-ebin \ 00246 install-src install-include install-examples install-test 00247 00248 00249 00250 install-announce: 00251 @echo " Installing package $(PACKAGE_NAME) \ 00252 in $(PACKAGE_INSTALLATION_PREFIX)" 00253 00254 00255 install-prod-announce: 00256 @echo " Installing production package $(PACKAGE_NAME) \ 00257 in $(PACKAGE_INSTALLATION_PREFIX)" 00258 00259 00260 # The -L option for cp is used to force the copy of the file which is pointed to 00261 # by a symbolic link, instead of copying that link, which is generally relative 00262 # and broken if copied in an installation 'as is'. 00263 00264 00265 install-bin: 00266 @if [ -n "$(EXEC_TO_INSTALL)" ] ; then \ 00267 mkdir -p $(PACKAGE_INSTALLATION_PREFIX)/bin ; \ 00268 /bin/cp -L $(EXEC_TO_INSTALL) $(PACKAGE_INSTALLATION_PREFIX)/bin ; fi 00269 00270 00271 install-ebin: 00272 @if [ -n "$(BEAMS_TO_INSTALL)" ] ; then \ 00273 mkdir -p $(PACKAGE_INSTALLATION_PREFIX)/ebin ; \ 00274 /bin/cp -L $(BEAMS_TO_INSTALL) $(PACKAGE_INSTALLATION_PREFIX)/ebin ; fi 00275 00276 00277 install-src: 00278 @if [ -n "$(SOURCES_TO_INSTALL)" ] ; then \ 00279 mkdir -p $(PACKAGE_INSTALLATION_PREFIX)/src ; \ 00280 /bin/cp -L $(SOURCES_TO_INSTALL) $(PACKAGE_INSTALLATION_PREFIX)/src ; fi 00281 00282 00283 install-include: 00284 @if [ -n "$(INCLUDES_TO_INSTALL)" ] ; then \ 00285 mkdir -p $(PACKAGE_INSTALLATION_PREFIX)/include ; \ 00286 /bin/cp -L $(INCLUDES_TO_INSTALL) \ 00287 $(PACKAGE_INSTALLATION_PREFIX)/include ; fi 00288 00289 00290 install-examples: 00291 @if [ -n "$(EXAMPLES_TO_INSTALL_BEAMS)" ] ; then \ 00292 mkdir -p $(PACKAGE_INSTALLATION_PREFIX)/examples/ebin ; \ 00293 /bin/cp -L $(EXAMPLES_TO_INSTALL_BEAMS) \ 00294 $(PACKAGE_INSTALLATION_PREFIX)/examples/ebin ; fi 00295 @if [ -n "$(EXAMPLES_TO_INSTALL_SRC)" ] ; then \ 00296 mkdir -p $(PACKAGE_INSTALLATION_PREFIX)/examples/src ; \ 00297 /bin/cp -L $(EXAMPLES_TO_INSTALL_SRC) \ 00298 $(PACKAGE_INSTALLATION_PREFIX)/examples/src ; fi 00299 00300 00301 install-test: 00302 @if [ -n "$(TESTS_TO_INSTALL_BEAMS)" ] ; then \ 00303 mkdir -p $(PACKAGE_INSTALLATION_PREFIX)/test/ebin ; \ 00304 cp -L $(TESTS_TO_INSTALL_BEAMS) \ 00305 $(PACKAGE_INSTALLATION_PREFIX)/test/ebin ; fi 00306 @if [ -n "$(TESTS_TO_INSTALL_SRC)" ] ; then \ 00307 mkdir -p $(PACKAGE_INSTALLATION_PREFIX)/test/src ; \ 00308 cp -L $(TESTS_TO_INSTALL_SRC) \ 00309 $(PACKAGE_INSTALLATION_PREFIX)/test/src ; fi 00310 00311 00312 install-doc: 00313 @if [ -n "$(DOC_TO_INSTALL)" ] ; then \ 00314 mkdir -p $(PACKAGE_INSTALLATION_PREFIX)/doc ; \ 00315 /bin/cp -r -L $(DOC_TO_INSTALL) $(PACKAGE_INSTALLATION_PREFIX)/doc ; fi 00316 00317 00318 info-install: 00319 @echo "EXEC_TO_INSTALL = $(EXEC_TO_INSTALL)" 00320 @echo "BEAMS_TO_INSTALL = $(BEAMS_TO_INSTALL)" 00321 @echo "SOURCES_TO_INSTALL = $(SOURCES_TO_INSTALL)" 00322 @echo "INCLUDES_TO_INSTALL = $(INCLUDES_TO_INSTALL)" 00323 @echo "EXAMPLES_TO_INSTALL_BEAMS = $(EXAMPLES_TO_INSTALL_BEAMS)" 00324 @echo "EXAMPLES_TO_INSTALL_SRC = $(EXAMPLES_TO_INSTALL_SRC)" 00325 @echo "TESTS_TO_INSTALL_BEAMS = $(TESTS_TO_INSTALL_BEAMS)" 00326 @echo "TESTS_TO_INSTALL_SRC = $(TESTS_TO_INSTALL_SRC)" 00327 @echo "DOC_TO_INSTALL = $(DOC_TO_INSTALL)" 00328 00329 00330 help-erl: 00331 @echo "To test hello.erl: 'erl', then 'c(hello).'," \ 00332 "then 'hello:world().', then CTRL-C CTRL-C" 00333 00334 clean: clean-erlang clean-database clean-override clean-recurse 00335 00336 00337 clean-erlang: 00338 @echo " Cleaning all in "$(PWD) #`basename $(PWD)` 00339 -@/bin/rm -f *.beam *.jam erl_crash.dump 00340 00341 00342 clean-database: 00343 -@/bin/rm -rf Mnesia.*@* 00344 00345 00346 # This target has been added in order to allow the packages making use of 00347 # 'Common' to define their specific cleaning rules. 00348 # They could have defined in their own GNUmakerules.inc something like: 00349 # clean: clean-mypackage 00350 # clean-mypackage: 00351 # -@/bin/rm foo.mypackage 00352 # but then this 'clean' target would become the default one, whereas we expect 00353 # the 'all' default target of 'Common' to be triggered. 00354 # Thus we finally allowed upper packages to make their cleaning thanks to: 00355 # FILES_TO_CLEAN += foo.mypackage in their GNUmakevars.inc 00356 clean-override: 00357 @#echo "FILES_TO_CLEAN = $(FILES_TO_CLEAN)" 00358 -@/bin/rm -f $(FILES_TO_CLEAN) 00359 00360 00361 clean-recurse: 00362 @for m in $(MODULES_DIRS); do if ! ( if [ -d $$m ] ; then \ 00363 cd $$m && $(MAKE) -s clean CMD_LINE_OPT="${CMD_LINE_OPT}" && \ 00364 cd .. ; else echo " (directory $$m skipped)" ; fi ) ; then \ 00365 exit 1; fi ; done 00366 00367 00368 realclean: clean 00369 @echo " Deep cleaning in "`basename $(PWD)` 00370 -@/bin/rm -f Emakefile 00371 00372 00373 info: info-files 00374 @echo "FQDN = $(FQDN)" 00375 @echo "BEAM_DIRS = $(BEAM_DIRS)" 00376 @echo "BEAM_PATH_OPT = $(BEAM_PATH_OPT)" 00377 @echo "ARCHIVE_FILE = $(ARCHIVE_FILE)" 00378 @echo "ERLANG_INTERPRETER = $(ERLANG_INTERPRETER)" 00379 @echo "ERLANG_INTERPRETER_OPT = $(ERLANG_INTERPRETER_OPT)" 00380 @echo "ERLANG_SRC = $(ERLANG_SRC)" 00381 @echo "VM_TEST_NAME = $(VM_TEST_NAME)" 00382 @echo "PROJECT_NAME = $(PROJECT_NAME)" 00383 00384 00385 info-files: 00386 @echo "ERL_FILES = $(ERL_FILES)" 00387 @echo "BEAM_FILES = $(BEAM_FILES)" 00388 @echo "TEST_SOURCES = $(TEST_SOURCES)" 00389 @echo "TEST_TARGETS = $(TEST_TARGETS)" 00390 00391 00392 include $(COMMON_TOP)/doc/GNUmakerules-docutils.inc