GNUmakerules 5.51 KB
Newer Older
1
#
2
# Copyright (c) 2000-2012, 2016 University of Utah and the Flux Group.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
# 
# {{{EMULAB-LICENSE
# 
# This file is part of the Emulab network testbed software.
# 
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
# 
# This file 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 Affero General Public
# License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this file.  If not, see <http://www.gnu.org/licenses/>.
# 
# }}}
22 23 24 25 26 27 28 29 30

# Get rid of a bunch of nasty built-in implicit rules,
# to avoid bogus circular dependencies and make things go faster.
# Use the `-r' command line option to make to get even better performance.
.SUFFIXES:

#
# Various install targets.
# 
31 32 33
$(INSTALL_BINDIR)/%: %
	@echo "Installing $<"
	-mkdir -p $(INSTALL_BINDIR)
34
	$(INSTALL_PROGRAM) $< $@
35

36 37 38 39 40
$(INSTALL_SBINDIR)/%: %
	@echo "Installing $<"
	-mkdir -p $(INSTALL_SBINDIR)
	$(INSTALL_PROGRAM) $< $@

41
$(INSTALL_LIBDIR)/%: %
42
	@echo "Installing $<"
43
	-mkdir -p $(INSTALL_LIBDIR)
44
	$(INSTALL_PROGRAM) $< $@
45

46
$(INSTALL_LIBEXECDIR)/%: %
47
	@echo "Installing $<"
48
	-mkdir -p $(INSTALL_LIBEXECDIR)
49
	$(INSTALL_PROGRAM) $< $@
50

51 52 53 54 55
$(INSTALL_ETCDIR)/%: %
	@echo "Installing $<"
	-mkdir -p $(INSTALL_ETCDIR)
	$(INSTALL_DATA) $< $@

56
$(addprefix $(INSTALL_SBINDIR)/, $(SETUID_SBIN_PROGS)): $(INSTALL_SBINDIR)/%: %
57 58 59 60
	echo "Installing (setuid) $<"
	-mkdir -p $(INSTALL_SBINDIR)
	$(SUDO) $(INSTALL) -o root -m 4755 $< $@

61
$(addprefix $(INSTALL_BINDIR)/, $(SETUID_BIN_PROGS)): $(INSTALL_BINDIR)/%: %
62 63 64 65
	echo "Installing (setuid) $<"
	-mkdir -p $(INSTALL_BINDIR)
	$(SUDO) $(INSTALL) -o root -m 4755 $< $@

66
$(addprefix $(INSTALL_LIBEXECDIR)/, $(SETUID_LIBX_PROGS)): $(INSTALL_LIBEXECDIR)/%: %
67 68 69 70
	echo "Installing (setuid) $<"
	-mkdir -p $(INSTALL_LIBEXECDIR)
	$(SUDO) $(INSTALL) -o root -m 4755 $< $@

71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
$(addprefix $(INSTALL_SBINDIR)/, $(SETUID_SBIN_SCRIPTS)): $(INSTALL_SBINDIR)/%: % $(INSTALL_SUIDDIR)/%
	echo "Installing (link to wrapper) $<"
	-mkdir -p $(INSTALL_SBINDIR)
	-rm -f $@
	ln -s $(INSTALL_LIBEXECDIR)/runsuid $@

$(addprefix $(INSTALL_BINDIR)/, $(SETUID_BIN_SCRIPTS)): $(INSTALL_BINDIR)/%: % $(INSTALL_SUIDDIR)/%
	echo "Installing (link to wrapper) $<"
	-mkdir -p $(INSTALL_BINDIR)
	-rm -f $@
	ln -s $(INSTALL_LIBEXECDIR)/runsuid $@

$(addprefix $(INSTALL_LIBEXECDIR)/, $(SETUID_LIBX_SCRIPTS)): $(INSTALL_LIBEXECDIR)/%: % $(INSTALL_SUIDDIR)/%
	echo "Installing (link to wrapper) $<"
	-mkdir -p $(INSTALL_LIBEXECDIR)
	-rm -f $@
	ln -s $(INSTALL_LIBEXECDIR)/runsuid $@

89 90 91 92 93 94 95
# Special libexec rule for scripts invoked by suexec (cannot be a symlink)
$(addprefix $(INSTALL_LIBEXECDIR)/, $(SETUID_SUEXEC_SCRIPTS)): $(INSTALL_LIBEXECDIR)/%: % $(INSTALL_SUIDDIR)/%
	echo "Installing (hard link to wrapper) $<"
	-mkdir -p $(INSTALL_LIBEXECDIR)
	-rm -f $@
	ln $(INSTALL_LIBEXECDIR)/runsuid $@

96 97 98
$(INSTALL_SUIDDIR)/%: %
	echo "Installing (real script) $<"
	-mkdir -p $(INSTALL_SUIDDIR)
99
	$(SUDO) $(INSTALL_PROGRAM) $< $@	
100

101 102
CFLAGS += $(LOCALCFLAGS)

103 104
clean:

105 106 107 108
# This is to avoid warnings about duplicate targets. 
distclean: default-clean

default-clean:
109 110
	rm -f GNUmakefile

111
# This is to avoid warnings about duplicate targets.
112
default-install-notusing:
113
ifeq ($(ISMAINSITE),1)
114
ifeq ($(TBROOT),/usr/testbed)
115
	(cd $(SRCDIR) ; \
116
	  git status --porcelain -s -b | head -1 | grep -q -s current)
117 118 119 120 121 122 123
else
	/usr/bin/true
endif
else
	/usr/bin/true
endif

124
#install:	default-install
125

126 127 128 129 130 131
#
# Where to find source files.
# Using specific patterns instead of the catch-all VPATH variable
# avoids hitting miscellaneous wrong targets in other directories
# when configuring in the source directory.
#
Leigh Stoller's avatar
Leigh Stoller committed
132 133 134 135
vpath %.in  $(SRCDIR) $(MOSTLY_SRCDIRS)
vpath %.c   $(SRCDIR) $(MOSTLY_SRCDIRS)
vpath %.cc  $(SRCDIR) $(MOSTLY_SRCDIRS)
vpath %     $(SRCDIR) $(MOSTLY_SRCDIRS)
136 137 138 139 140 141 142

#
# Define rules which we blew away with .SUFFIXES
# 
%.o: %.c
	$(CC) -c -o $@ $(CFLAGS) $<

143 144 145
%.o: %.cc
	$(CXX) -c -o $@ $(CXXFLAGS) $<

Timothy Stack's avatar
Timothy Stack committed
146 147 148
%.o: %.C
	$(CXX) -c -o $@ $(CXXFLAGS) $<

Timothy Stack's avatar
Timothy Stack committed
149 150 151 152 153 154
%_xdr.h: %.x
	rpcgen -h $< > $@

%_xdr.c: %.x %_xdr.h
	rpcgen -c $< > $@

Timothy Stack's avatar
Timothy Stack committed
155
%: %-debug
156
	$(STRIP) -o $@$(EXE) $<$(EXE)
Timothy Stack's avatar
Timothy Stack committed
157

Timothy Stack's avatar
Timothy Stack committed
158 159 160
%-version.c:
	echo >$@ "char build_info[] = \"Built on `date` by `id -nu`@`hostname | sed 's/\..*//'`:`pwd`\";"

161 162 163
#
# Rules to regen configure written files.
#
164
%: %.in $(OBJDIR)/config.status
165
	@echo "Regenerating $@"
166
	cd $(OBJDIR) && CONFIG_FILES=$(SUBDIR)/$@ ./config.status
Timothy Stack's avatar
Timothy Stack committed
167 168 169 170 171

ifeq ($(TESTS),)
.PHONY: check
else
check: $(TESTS)
Timothy Stack's avatar
Timothy Stack committed
172
	@export SRCDIR=${SRCDIR}; for tst in $^; do \
Timothy Stack's avatar
Timothy Stack committed
173 174 175 176 177
		if test `basename $$tst .sh` != `basename $$tst`; then \
			tst="sh $$tst"; \
		fi; \
		if $$tst; then \
			echo "PASS: $$tst"; \
Timothy Stack's avatar
Timothy Stack committed
178 179 180
		else \
			echo "FAIL: $$tst"; \
			exit 1; \
Timothy Stack's avatar
Timothy Stack committed
181 182 183
		fi \
	done
endif
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205

ifeq ($(MERGE_BUILD),1)
.PRECIOUS: ${SRCDIR}/*

#
# I really want to say something like:
#   ${TESTBED_SRCDIR}/.merged: $(wildcard ${OBJDIR}/${MERGE_BUILD_SANDBOX}/${SUBDIR}/*)
# but that causes problems if one the prereq. has a rule for it (such
# as when both GNUmakefile and GNUmakefile.in exist in the source tree),
# thus I do the equivalent manually
#
newest=$(shell ls -rtd "${OBJDIR}/${MERGE_BUILD_SANDBOX}/${SUBDIR}/"* "${TESTBED_SRCDIR}/.merged" | tail -n 1)
ifneq ($(newest),${TESTBED_SRCDIR}/.merged)
${TESTBED_SRCDIR}/.merged:
	cd ${TESTBED_SRCDIR} && utils/merge-build sync
.PHONY: ${TESTBED_SRCDIR}/.merged
else
${TESTBED_SRCDIR}/.merged:
endif

${SRCDIR}/*: ${TESTBED_SRCDIR}/.merged
endif