summaryrefslogtreecommitdiff
path: root/Makefile.gen.gen
blob: 1a67edf88d1a8214f5c4bfea5dfd28d5ebb6d0fc (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
# -*- Makefile -*-
#
# Copyright 2009 Free Software Foundation, Inc.
# 
# This file is part of GNU Radio
# 
# GNU Radio 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 3, or (at your option)
# any later version.
# 
# GNU Radio 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 GNU Radio; see the file COPYING.  If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
# 

STAMPS += $(DEPDIR)/sources-generate-*

# Ensure parallel make does the right thing.
# http://sources.redhat.com/automake/automake.html#Multiple-Outputs

$(DEPDIR)/sources-generate-stamp: $(gen_sources_deps)
	@rm -f $(DEPDIR)/sources-generate-tmp
	@touch $(DEPDIR)/sources-generate-tmp
	PYTHONPATH=$(top_srcdir)/gnuradio-core/src/python srcdir=$(srcdir) $(PYTHON) $(srcdir)/generate_all.py
	@mv -f $(DEPDIR)/sources-generate-tmp $@

$(gen_sources): $(DEPDIR)/sources-generate-stamp
## Recover from the removal of $@
	@if test -f $@; then :; else \
		trap 'rm -rf $(DEPDIR)/sources-generate-*' 1 2 13 15; \
		if mkdir $(DEPDIR)/sources-generate-lock 2>/dev/null; then \
## This code is being executed by the first process.
			rm -f $(DEPDIR)/sources-generate-stamp; \
			$(MAKE) $(AM_MAKEFLAGS) $(DEPDIR)/sources-generate-stamp; \
			rmdir $(DEPDIR)/sources-generate-lock; \
		else \
## This code is being executed by the follower processes.
## Wait until the first process is done.
			while test -d $(DEPDIR)/sources-generate-lock; do sleep 1; done; \
## Succeed if and only if the first process succeeded.
			test -f $(DEPDIR)/sources-generate-stamp; exit $$?; \
		fi; \
	fi;

## ----------------------------------------------------------------
## Special rule for regenerating the local Makefile.gen

STAMPS += $(DEPDIR)/generate-makefile-generate-*

generate-makefile $(srcdir)/Makefile.gen:
## parallel make protection; can't hurt
	@trap 'rm -rf $(DEPDIR)/Makefile.gen-generate-*' 1 2 13 15; \
	if mkdir $(DEPDIR)/Makefile.gen-generate-lock 2>/dev/null; then \
## This code is being executed by the first process.
		rm -f $(DEPDIR)/Makefile.gen-generate-stamp; \
		rm -f $(DEPDIR)/Makefile.gen-generate-tmp; \
		touch $(DEPDIR)/Makefile.gen-generate-tmp; \
## recreate $(srcdir)/Makefile.gen only if ...
		do_recreate=0; \
		if test -f $(srcdir)/Makefile.gen; then \
## the file exists and can be removed; or ...
			if $(RM) $(srcdir)/Makefile.gen 2>/dev/null; then \
				do_recreate=1; \
			fi; \
		else \
## the file doesn't exist, but can be created (e.g., by touching it).
			if touch $(srcdir)/Makefile.gen 2>/dev/null; then \
				do_recreate=1; \
			fi; \
		fi; \
		if test "$$do_recreate" == "1"; then \
			echo "Regenerating $(srcdir)/Makefile.gen"; \
			PYTHONPATH=$(top_srcdir)/gnuradio-core/src/python srcdir=$(srcdir) do_makefile=1 do_sources=0 $(PYTHON) $(srcdir)/generate_all.py; \
		else \
			echo "Cannot recreate $(srcdir)/Makefile.gen because the directory or file is write-protected."; \
		fi; \
		mv -f $(DEPDIR)/Makefile.gen-generate-tmp $(DEPDIR)/Makefile.gen-generate-stamp; \
		rmdir $(DEPDIR)/Makefile.gen-generate-lock; \
	else \
## This code is being executed by the follower processes.
## Wait until the first process is done.
		while test -d $(DEPDIR)/$@-generate-lock; do sleep 1; done; \
## Succeed if and only if the first process succeeded.
		test -f $(DEPDIR)/$@-generate-stamp; exit $$?; \
	fi;

## ----------------------------------------------------------------

MOSTLYCLEANFILES += $(STAMPS)