#
# GNU Makefile generated by appmake.
#
# Copyright (C) 2008-2009 Takahiko Funakubo, Japan.
# All Rights Reserved.
#

project   := appmake
version   := 0.0.1
proj_ver  := $(project)-$(version)

#CROSS     := powerpc-linux-gnu-
CROSS     :=
CC        := $(CROSS)gcc
LD        := $(CROSS)ld
PREFIX    := /usr/local/
PREFIXX   := $(if $(filter $(PREFIX),$(dir $(PREFIX))),$(PREFIX),$(PREFIX)/)
CFLAGS    := -g -fno-strict-aliasing -I include/ -I /usr/include/cutter -DPREFIX=\"$(PREFIXX)\" -D_GNU_SOURCE 
CXXFLAGS  := $(CFLAGS)
LDFLAGS   :=
ARFLAGS   := ur
YACCFLAGS :=
LEXFLAGS  :=

#### DO NOT CHANGE THE BELOW LINES ####

# init variables
all_targets   :=
all_depends   :=
all_objects   :=
all_sources   :=
all_bin_objects :=
all_buildfiles:= $(shell find . -name Build.mk)
install_no    :=
install_bin   :=
install_lib   :=
install_etc   :=

# useful variables
comma := ,
Q     := @
quiet := quiet_
PHONY :=

ifdef V
  ifeq ("$(origin V)", "command line")
    quiet :=
  endif
  $(warning build files : $(all_buildfiles))
endif

include Buildscripts/Makefile.funcs

#
# dummy target
#
all: 

#
# include all Makefiles in subdirs!
#
define include-subdirs
    $(eval include Buildscripts/Makefile.pre)
    $(eval include $1)
    $(eval include Buildscripts/Makefile.post)
endef
$(foreach i,$(all_buildfiles),$(eval $(call include-subdirs,$i)))

# make config.h rules
ifneq ("$(all_bin_objects)","")
$(eval $(call make-config-rules,$(patsubst %.o,%.bin,$(all_bin_objects))))
endif

all: ./config.h $(all_targets) 

define move-clean
	@cd $(if $1,$1,.); echo $(all_targets) $(all_depends) $(all_objects) $(all_sources) | xargs rm -rf
endef
PHONY += clean
clean:
	$(move-clean)
	@rm -rf ./config.h

define move-distclean
	@cd $(if $1,$1,.); find -regex ".*~$$\|.*TAGS$$" | xargs rm -rf
endef
PHONY += distclean
distclean: clean
	$(move-distclean)

PHONY += dist
dist:
	@rm -rf _tmp
	@mkdir -p _tmp/$(proj_ver)
	@for i in `find . -type f | grep -v "/_tmp/\|/\.svn/\|\.o$$"` ; do cp --parents $$i _tmp/$(proj_ver); done
	$(call move-clean,_tmp/$(proj_ver))
	$(call move-distclean,_tmp/$(proj_ver))
	@tar czf $(proj_ver).tar.gz -C _tmp/ $(proj_ver)
	@rm -rf _tmp

PHONY += tags
tags:
	find -regex '.*\.h$$\|.*\.c$$' | xargs etags

PHONY += install
install: all
	$(if $(install_bin), install -d $(PREFIX)bin/ ; install -D -s -m 755 $(install_bin)  $(PREFIX)bin/,)
	$(if $(install_sbin),install -d $(PREFIX)sbin/; install -D -s -m 755 $(install_sbin) $(PREFIX)sbin/,)
	$(if $(install_lib), install -d $(PREFIX)lib/ ; install -D -m 755    $(install_lib)  $(PREFIX)lib/,)
	$(if $(install_etc), install -d $(PREFIX)etc/ ; install -D -m 644    $(install_etc)  $(PREFIX)etc/,)

.PHONY: $(PHONY)

#
# include dependencies
#
ifeq ("", "$(filter $(PHONY), $(MAKECMDGOALS))")
    -include $(all_depends)
endif

