Makefile 1.22 KB
Newer Older
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
#!/usr/bin/make -f
#
# Makefile to build PHP-based websites statically
# by Remi Denis-Courmont
# $Id: Makefile 4638 2008-08-26 12:52:45Z dionoea $

ifeq ($(ROOT),)
  ROOT := ./
  NEXTROOT := ../
else
  NEXTROOT := ../$(ROOT)
endif

PHPCGI := $(ROOT)bin/php-cgi.sh
STRIP_HEADERS := $(ROOT)bin/strip-headers.sh

all: real-all

include Makefile.inc

ifneq ($(PHP_FILES),)
  PHP_FILES := $(PHP_FILES:%=%.php)
else
  PHP_FILES := $(wildcard *.php)
endif

ifneq ($(PHP_IGNORES),)
  PHP_FILES := $(filter-out $(PHP_IGNORES:%=%.php), $(PHP_FILES))
endif

TARGETS := $(PHP_FILES:%.php=%.html)

real-all: $(TARGETS) all-recursive

clean: clean-recursive
	rm -f $(TARGETS) $(TARGETS:%=%.tmp)

%-recursive:
	@for d in $(SUBDIR) ; do \
		$(MAKE) -f $(NEXTROOT)Makefile -C $$d ROOT=$(NEXTROOT) $* \
			HERE=$(HERE)$$d/ || exit $$? ; \
	done

%.html: %.php $(ROOT)Makefile $(ROOT)/include/*.php $(ROOT)/include/*.php $(ROOT)/include/menu/*
	@echo "Preprocessing $@ ..."
	@rm -f $@.tmp
	@cd $(ROOT) || exit 1 ; \
	if ! DOCUMENT_ROOT=$(ROOT) $(HERE)$(PHPCGI) $(HERE)$< > $(HERE)$@.tmp; then \
		cat $(HERE)$@.tmp | tail -1 ; \
		rm -f $(HERE)$@.tmp ; \
		exit 1 ; \
	fi
	@$(STRIP_HEADERS) < $@.tmp > $@.tmp2
	@mv -v $@.tmp2 $@
	@rm -f $@.tmp $@.tmp2

.PHONY: clean all