updated filename with hopefully close to right cygwin and msys path munging, couldn...
[feisty_meow.git] / scripts / clam / rules.def
1 # CLAM System default rule and target definitions.
2
3 ###############################################################################
4
5 #  This file contains composite macros and rules for creating objects.
6 #  This file should be included in the user's makefile after the variables
7 #  have been initialized appropriately for the particular project being
8 #  created.  The user's own targets should be placed after the include
9 #  directive that specifies this file.
10
11 ###############################################################################
12
13 # This ensures that any of other projects required by this one (defined through
14 # BUILD_BEFORE) get created before the real work in this project is done.
15 ifneq "$(BUILD_BEFORE)" ""
16   FIRST_TARGETS += $(BUILD_BEFORE:%=%.make)
17 endif
18 ifneq "$(BUILD_AFTER)" ""
19   LAST_TARGETS += $(BUILD_AFTER:%=%.make)
20 endif
21
22 # Make the default action be an error stop if we can't find an appropriate rule.
23 .DEFAULT:
24         $(HIDER)echo
25         $(HIDER)echo [$@] is missing files or has a makefile problem.
26         $(HIDER)echo
27         $(HIDESH)$(CLAM_DIR)/exit_make.sh
28
29 # This rule halts make for some supposedly devastating reason.  More
30 # information should be printed out by the cause of the halt.
31 %.halt:
32         @echo CLAM execution halted, the cause being: $@
33         $(HIDESH)$(CLAM_DIR)/exit_make.sh
34
35 # Provides a time-stamp in the make log.
36 show_date.%:
37         $(HIDER)echo "The time right now is $(shell date)"
38
39 # The .make rule changes to the directory with the same first part of the
40 # pattern and makes whatever projects are there.  This is used by the build
41 # before procedure.
42 %.make:
43         $(HIDESH) -c '\
44 if [ -d $* ]; then \
45   if [ -f "$*/$(MAKEFILE_NAME)" ]; then \
46     $(MAKE) --silent -f "$(MAKEFILE_NAME)" NOT_FIRST_MAKE=t -C "$*"; \
47   else \
48     echo Skipping makefile-less directory [$*]; \
49   fi \
50 else \
51   echo Skipping missing directory [$*]; \
52 fi'
53
54 # always run the targets.  if they don't exist, that's an error.
55 .PHONY: run_targets
56
57 # "all" is the first target to execute in any makefile.  we capture it and
58 # use it to produce the requested actions.
59 all: start $(ACTUAL_FIRST_TARGETS) $(ACTUAL_TARGETS) $(ACTUAL_LAST_TARGETS) $(RUN_TARGETS:%=run_targets) finish 
60
61 # "start" announces the beginning of compilation.
62 start:
63         $(HIDESH) -c '\
64 if [ ! -d "$(CLAM_TMP)" ]; then \
65   mkdir "$(CLAM_TMP)"; \
66 fi'
67 ifeq "$(QUIET)" ""
68         $(HIDER)echo Project $(PROJECT) [$(shell basename $(shell dirname $(shell pwd) ) )/$(shell basename $(shell pwd) )] v. $(major).$(minor).$(revision).$(build)
69 endif
70         $(HIDER)rm -f $(FLAG_FILES)
71
72 # "finish" announces the end of compilation.  if there are targets to
73 # run, then they are executed here.
74 finish:
75 ifeq "$(QUIET)" ""
76         $(HIDER)echo Finished $(PROJECT).
77 endif
78         $(HIDER)rm -f $(FLAG_FILES) $(SUB_FLAG_FILES)
79 ifeq "$(NOT_FIRST_MAKE)" ""
80         $(HIDESH) -c '\
81 if [ ! -f "$(FAILURE_FILE)" ]; then \
82   $(SHELL) $(CLAM_DIR)/sound_play.sh $(CLAM_FINISH_SOUND); \
83 fi'
84 endif
85 # toss the flag files so we do not see them again.
86         $(HIDER)rm -f "$(DIRTY_FILE)" "$(SUBMAKE_FLAG)"
87
88 # runs the programs specified in the RUN_TARGETS variable.
89 run_targets:
90         $(HIDESH) -c '\
91 if [ ! -z "$(RUN_TARGETS)" ]; then \
92   if [ -f "$(DIRTY_FILE)" -o -f "$(SUBMAKE_FLAG)" ]; then \
93     total_exitval=0; \
94     for program_name in $(RUN_TARGETS); do \
95       base=`basename $$program_name`; \
96       "$$program_name"; \
97       exitval=$$?; \
98       if [ $$exitval -ne 0 ]; then \
99         echo -e "ERROR: $$program_name at `date`"; \
100         total_exitval=$$(($$total_exitval + 1)); \
101       fi; \
102     done; \
103     if [ $$total_exitval -ne 0 ]; then \
104       echo "FAILURE: errors occurred in RUN_TARGETS."; \
105       echo yep >"$(FAILURE_FILE)"; \
106       exit 1; \
107     fi; \
108   fi; \
109 fi'
110
111 # "make_subdirs" travels down each subdirectory and builds using make.
112 make_subdirs:
113         $(HIDESH) -c '\
114 for i in *; do \
115   if [ -d $$i ]; then \
116     if [ -f $$i/$(MAKEFILE_NAME) -a ! $$i -ef `pwd` ]; then \
117       echo; \
118       (cd $$i; $(MAKE) --silent NOT_FIRST_MAKE=t -f $(MAKEFILE_NAME) ); \
119     else \
120       echo Skipping makefile-less directory $$i...; \
121       echo; \
122     fi \
123   fi \
124 done; \
125 exit 0'
126
127 # "clean" is a default target that removes object files, libs, executable
128 # files and such that were created by the project.  it invokes the makefile
129 # again with the CLEAN variable defined so that this can be passed down into
130 # all subsequent makes.
131 clean: 
132         $(HIDER)$(MAKE) --silent CLEAN=t ready_to_clean
133
134 ready_to_clean: $(OTHER_CLEANS) clean_subdirs
135         @echo Whacking [$(CLEANUPS)]
136         $(HIDESH) -c '\
137 echo the other cleans were: $(OTHER_CLEANS); \
138 echo the clean list is: $(CLEANUPS); \
139 if [ ! -z "$(CLEANUPS)" ]; then \
140   for i in $(CLEANUPS) nonexistentishfileforlist; do \
141     rm -rf "$$i"; \
142   done \
143 fi'
144
145 # "clean_subdirs" travels down each subdirectory and cleans using make.
146 clean_subdirs:
147         $(HIDESH) -c '\
148 for i in *; do \
149   if [ -d "$$i" ]; then \
150     if [ -f "$$i/$(MAKEFILE_NAME)" -a ! "$$i" -ef `pwd` ]; then \
151       (cd "$$i"; $(MAKE) --silent NOT_FIRST_MAKE=t -f $(MAKEFILE_NAME) clean); \
152     else \
153       echo "Skipping makefile-less directory $$i..."; \
154     fi \
155   fi \
156 done; \
157 exit 0'
158 ###echo Cleaning "$$i" now...; 
159
160 # "rm_links" removes the files in the current directory that are links
161 # to other files.  this is only useful in a unix environment.
162 rm_links:
163         $(HIDESH) -c '\
164 for i in *; do \
165   if [ -h "$$i" ]; then \
166     /bin/rm -f "$$i"; \
167   fi \
168 done; \
169 exit 0'
170