changeset 522:5183a16c5e0d

Use "Explicit Path Method" to allow build from any directory.
author Oleksandr Gavenko <gavenkoa@gmail.com>
date Tue, 23 Oct 2012 23:51:52 +0300
parents 165b4348e037
children ca2ade61b724 2527a3c1d750
files printarg/Makefile
diffstat 1 files changed, 15 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/printarg/Makefile	Mon Oct 01 10:10:11 2012 +0300
+++ b/printarg/Makefile	Tue Oct 23 23:51:52 2012 +0300
@@ -11,6 +11,9 @@
 # Default target.
 .DEFAULT_GOAL = all
 
+S := $(dir $(abspath $(firstword $(MAKEFILE_LIST))))
+B := $(abspath .)/
+
 ifeq '' '$(prefix)'
   ifneq '' '$(HOME)'
     prefix = $(HOME)/usr
@@ -55,39 +58,37 @@
   EXE_SUFFIX = .exe
 endif
 
-BUILD_SCRIPTS := $(lastword $(MAKEFILE_LIST))
-
-C_FILES = $(wildcard *.c)
-O_FILES = $(C_FILES:.c=.o)
+C_FILES = $(wildcard ${S}*.c)
+O_FILES = $(patsubst ${S}%.c,${B}%.o,$(C_FILES))
 
 APP = printarg$(EXE_SUFFIX)
 
 .PHONY: all
-all: $(APP)
+all: ${B}$(APP)
 
-$(APP): $(O_FILES)
+${B}$(APP): $(O_FILES)
 	$(LD) $(LDFLAGS) -o $@ $^
 ifneq 'yes' '$(DEBUG)'
 	strip $@
 endif
 
-$(O_FILES): %.o: %.c $(BUILD_SCRIPTS)
+$(O_FILES): ${B}%.o: ${S}%.c $(MAKEFILE_LIST)
 	$(CC) $(CFLAGS) -c -o $@ $<
 
 .PHONY: check
-check:
+check: ${B}$(APP)
+	$< hello world
 
 .PHONY: install
-install: $(APP)
+install: ${B}$(APP)
 	[ -d $(bindir) ] || mkdir -p $(bindir)
-	install -m 755 $(APP) $(bindir)
+	install -m 755 ${B}$(APP) $(bindir)
 	[ -d $(man1dir) ] || mkdir -p $(man1dir)
-	install -m 644 printarg.1 $(man1dir)
+	install -m 644 ${S}printarg.1 $(man1dir)
 
 .PHONY: uninstall
 uninstall:
-	for file in \
-		$(bindir)/$(APP) $(man1dir)/printarg.1; do \
+	for file in $(bindir)/$(APP) $(man1dir)/printarg.1; do \
 		[ -e $$file ] && if rm $$file; then :; else echo Unable to delete $$file; exit 1; fi || :; \
 	done
 
@@ -96,4 +97,4 @@
 
 .PHONY: clean
 clean:
-	rm -f $(APP) $(O_FILES)
+	rm -f ${B}$(APP) $(O_FILES)