first check-in of feisty meow codebase. many things broken still due to recent
[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 #used to include message for first case: echo "Entering directory [$*]"; 
54
55 # "all" is the first target to execute in any makefile.  we capture it and
56 # use it to produce the requested actions.
57 all: start $(ACTUAL_FIRST_TARGETS) $(ACTUAL_TARGETS) $(ACTUAL_LAST_TARGETS) $(RUN_TARGETS:%=run_targets) finish 
58
59 # "start" announces the beginning of compilation.
60 start:
61         $(HIDESH) -c '\
62 if [ ! -d "$(CLAM_TMP)" ]; then \
63   mkdir "$(CLAM_TMP)"; \
64 fi'
65 ifeq "$(QUIET)" ""
66         $(HIDER)echo Project $(PROJECT) [$(shell basename $(shell dirname $(shell pwd) ) )/$(shell basename $(shell pwd) )] v. $(major).$(minor).$(revision).$(build).
67 endif
68         $(HIDER)rm -f $(FLAG_FILES)
69
70 # "finish" announces the end of compilation.  if there are targets to
71 # run, then they are executed here.
72 finish:
73 ifeq "$(QUIET)" ""
74         $(HIDER)echo Finished $(PROJECT).
75 endif
76         $(HIDER)rm -f $(FLAG_FILES) $(SUB_FLAG_FILES)
77 ifeq "$(NOT_FIRST_MAKE)" ""
78         $(HIDESH) -c '\
79 if [ ! -f "$(FAILURE_FILE)" ]; then \
80   $(SHELL) $(CLAM_DIR)/sound_play.sh $(CLAM_FINISH_SOUND); \
81 fi'
82 endif
83 # toss the flag files so we do not see them again.
84         $(HIDER)rm -f "$(DIRTY_FILE)" "$(SUBMAKE_FLAG)"
85
86 # runs the programs specified in the RUN_TARGETS variable.
87 run_targets:
88         $(HIDESH) -c '\
89 if [ ! -z "$(RUN_TARGETS)" ]; then \
90   if [ -f "$(DIRTY_FILE)" -o -f "$(SUBMAKE_FLAG)" ]; then \
91     total_exitval=0; \
92     for program_name in $(RUN_TARGETS); do \
93       base=`basename $$program_name`; \
94       "$$program_name"; \
95       exitval=$$?; \
96       if [ $$exitval -ne 0 ]; then \
97         echo -e "ERROR: $$program_name at `date`"; \
98         total_exitval=$$(($$total_exitval + 1)); \
99       fi; \
100     done; \
101     if [ $$total_exitval -ne 0 ]; then \
102       echo "FAILURE: errors occurred in RUN_TARGETS."; \
103     fi; \
104   fi; \
105 fi'
106 #hmmm: run targets needs to work on a hierarchy.
107 #hmmm: old idea?    exit $$total_exitval; \
108
109 # "make_subdirs" travels down each subdirectory and builds using make.
110 make_subdirs:
111         $(HIDESH) -c '\
112 for i in *; do \
113   if [ -d $$i ]; then \
114     if [ -f $$i/$(MAKEFILE_NAME) -a ! $$i -ef `pwd` ]; then \
115       echo; \
116       (cd $$i; $(MAKE) --silent NOT_FIRST_MAKE=t -f $(MAKEFILE_NAME) ); \
117     else \
118       echo Skipping makefile-less directory $$i...; \
119       echo; \
120     fi \
121   fi \
122 done; \
123 exit 0'
124 ##echo Entering $$i now...; 
125
126 # "clean" is a default target that removes object files, libs, executable
127 # files and such that were created by the project.  it invokes the makefile
128 # again with the CLEAN variable defined so that this can be passed down into
129 # all subsequent makes.
130 clean: 
131         $(HIDER)$(MAKE) --silent CLEAN=t ready_to_clean
132
133 ready_to_clean: $(OTHER_CLEANS) clean_subdirs
134         @echo Whacking [$(CLEANUPS)].
135         $(HIDESH) -c '\
136 echo the other cleans were: $(OTHER_CLEANS); \
137 echo the clean list is: $(CLEANUPS); \
138 if [ ! -z "$(CLEANUPS)" ]; then \
139   for i in $(CLEANUPS) nonexistentishfileforlist; do \
140     rm -rf "$$i"; \
141   done \
142 fi'
143
144 # "clean_subdirs" travels down each subdirectory and cleans using make.
145 clean_subdirs:
146         $(HIDESH) -c '\
147 for i in *; do \
148   if [ -d "$$i" ]; then \
149     if [ -f "$$i/$(MAKEFILE_NAME)" -a ! "$$i" -ef `pwd` ]; then \
150       (cd "$$i"; $(MAKE) --silent NOT_FIRST_MAKE=t -f $(MAKEFILE_NAME) clean); \
151     else \
152       echo "Skipping makefile-less directory $$i..."; \
153     fi \
154   fi \
155 done; \
156 exit 0'
157 ###echo Cleaning "$$i" now...; 
158
159 # "rm_links" removes the files in the current directory that are links
160 # to other files.  this is only useful in a unix environment.
161 rm_links:
162         $(HIDESH) -c '\
163 for i in *; do \
164   if [ -h "$$i" ]; then \
165     /bin/rm -f "$$i"; \
166   fi \
167 done; \
168 exit 0'
169