Merged mld/fix_makefile_gen -r10446:10509 to trunk. This cleans up
[debian/gnuradio] / Makefile.gen.gen
1 # -*- Makefile -*-
2 #
3 # Copyright 2009 Free Software Foundation, Inc.
4
5 # This file is part of GNU Radio
6
7 # GNU Radio is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3, or (at your option)
10 # any later version.
11
12 # GNU Radio is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16
17 # You should have received a copy of the GNU General Public License
18 # along with GNU Radio; see the file COPYING.  If not, write to
19 # the Free Software Foundation, Inc., 51 Franklin Street,
20 # Boston, MA 02110-1301, USA.
21
22
23 STAMPS += $(DEPDIR)/sources-generate-*
24
25 # Ensure parallel make does the right thing.
26 # http://sources.redhat.com/automake/automake.html#Multiple-Outputs
27
28 $(DEPDIR)/sources-generate-stamp: $(gen_sources_deps)
29         @rm -f $(DEPDIR)/sources-generate-tmp
30         @touch $(DEPDIR)/sources-generate-tmp
31         PYTHONPATH=$(top_srcdir)/gnuradio-core/src/python srcdir=$(srcdir) $(PYTHON) $(srcdir)/generate_all.py
32         @mv -f $(DEPDIR)/sources-generate-tmp $@
33
34 $(gen_sources): $(DEPDIR)/sources-generate-stamp
35 ## Recover from the removal of $@
36         @if test -f $@; then :; else \
37                 trap 'rm -rf $(DEPDIR)/sources-generate-*' 1 2 13 15; \
38                 if mkdir $(DEPDIR)/sources-generate-lock 2>/dev/null; then \
39 ## This code is being executed by the first process.
40                         rm -f $(DEPDIR)/sources-generate-stamp; \
41                         $(MAKE) $(AM_MAKEFLAGS) $(DEPDIR)/sources-generate-stamp; \
42                         rmdir $(DEPDIR)/sources-generate-lock; \
43                 else \
44 ## This code is being executed by the follower processes.
45 ## Wait until the first process is done.
46                         while test -d $(DEPDIR)/sources-generate-lock; do sleep 1; done; \
47 ## Succeed if and only if the first process succeeded.
48                         test -f $(DEPDIR)/sources-generate-stamp; exit $$?; \
49                 fi; \
50         fi;
51
52 ## ----------------------------------------------------------------
53 ## Special rule for regenerating the local Makefile.gen
54
55 STAMPS += $(DEPDIR)/generate-makefile-generate-*
56
57 generate-makefile $(srcdir)/Makefile.gen:
58 ## parallel make protection; can't hurt
59         @trap 'rm -rf $(DEPDIR)/Makefile.gen-generate-*' 1 2 13 15; \
60         if mkdir $(DEPDIR)/Makefile.gen-generate-lock 2>/dev/null; then \
61 ## This code is being executed by the first process.
62                 rm -f $(DEPDIR)/Makefile.gen-generate-stamp; \
63                 rm -f $(DEPDIR)/Makefile.gen-generate-tmp; \
64                 touch $(DEPDIR)/Makefile.gen-generate-tmp; \
65 ## recreate $(srcdir)/Makefile.gen only if ...
66                 do_recreate=0; \
67                 if test -f $(srcdir)/Makefile.gen; then \
68 ## the file exists and can be removed; or ...
69                         if $(RM) $(srcdir)/Makefile.gen 2>/dev/null; then \
70                                 do_recreate=1; \
71                         fi; \
72                 else \
73 ## the file doesn't exist, but can be created (e.g., by touching it).
74                         if touch $(srcdir)/Makefile.gen 2>/dev/null; then \
75                                 do_recreate=1; \
76                         fi; \
77                 fi; \
78                 if test "$$do_recreate" == "1"; then \
79                         echo "Regenerating $(srcdir)/Makefile.gen"; \
80                         PYTHONPATH=$(top_srcdir)/gnuradio-core/src/python srcdir=$(srcdir) do_makefile=1 do_sources=0 $(PYTHON) $(srcdir)/generate_all.py; \
81                 else \
82                         echo "Cannot recreate $(srcdir)/Makefile.gen because the directory or file is write-protected."; \
83                 fi; \
84                 mv -f $(DEPDIR)/Makefile.gen-generate-tmp $(DEPDIR)/Makefile.gen-generate-stamp; \
85                 rmdir $(DEPDIR)/Makefile.gen-generate-lock; \
86         else \
87 ## This code is being executed by the follower processes.
88 ## Wait until the first process is done.
89                 while test -d $(DEPDIR)/$@-generate-lock; do sleep 1; done; \
90 ## Succeed if and only if the first process succeeded.
91                 test -f $(DEPDIR)/$@-generate-stamp; exit $$?; \
92         fi;
93
94 ## ----------------------------------------------------------------
95
96 MOSTLYCLEANFILES += $(STAMPS)
97