checking in the recent efforts at optimizing clam
[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 makefile after the variables
7 #  have been initialized appropriately for the particular project being
8 #  created.  The user 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 ca not 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_SCRIPTS)/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_SCRIPTS)/exit_make.sh
34
35 # Provides a time-stamp in the make log.
36 show_date.%:
37         $(HIDER)echo "{$(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 directory $*)"; \
49   fi \
50 else \
51   echo Skipping missing directory [$*]; \
52 fi'
53 #hmmm: maybe convert above to a script also.
54
55 # always run the exes listed in RUN_TARGETS.
56 .PHONY: run_targets
57
58 # "all" is the first target to execute in any makefile.  we capture it and
59 # use it to produce the requested actions.
60 all: start $(ACTUAL_FIRST_TARGETS) $(ACTUAL_TARGETS) $(ACTUAL_LAST_TARGETS) run_targets finish 
61
62 # "start" announces the beginning of compilation.
63 start:
64         $(HIDESH) -c '\
65 if [ ! -d "$(CLAM_TMP)" ]; then \
66   mkdir "$(CLAM_TMP)"; \
67 fi'
68 ifeq "$(QUIET)" ""
69         $(HIDER)echo Project $(PROJECT) [$(shell echo $(CURRENT_DIR) | sed -e 's/.*\/\([^\/]*\)\/\([^\/]*\)/\1\/\2/')] v. $(major).$(minor).$(revision).$(build)
70 endif
71         $(HIDER)rm -f $(FLAG_FILES)
72
73 # "finish" announces the end of compilation.  if there are targets to
74 # run, then they are executed here.
75 finish:
76 ifeq "$(QUIET)" ""
77         $(HIDER)echo Finished $(PROJECT).
78 endif
79         $(HIDER)rm -f $(FLAG_FILES) $(SUB_FLAG_FILES)
80 ifeq "$(NOT_FIRST_MAKE)" ""
81         $(HIDESH) -c '\
82 if [ ! -f "$(FAILURE_FILE)" ]; then \
83   $(SHELL) $(FEISTY_MEOW_SCRIPTS)/multimedia/sound_play.sh $(CLAM_FINISH_SOUND); \
84 fi'
85 endif
86 # toss the flag files so we do not see them again.
87         $(HIDER)rm -f "$(DIRTY_FILE)" "$(SUBMAKE_FLAG)"
88
89 # runs the programs specified in the RUN_TARGETS variable.
90 run_targets:
91         $(HIDESH)"$(CLAM_SCRIPTS)/target_runner.sh"
92
93 # "make_subdirs" travels down each subdirectory and builds using make.
94 make_subdirs:
95         $(HIDESH)$(CLAM_SCRIPTS)/make_subdirs.sh
96
97 # "clean" is a default target that removes object files, libs, executable
98 # files and such that were created by the project.  it invokes the makefile
99 # again with the CLEAN variable defined so that this can be passed down into
100 # all subsequent makes.
101 clean: establish_cleanup_variable $(OTHER_CLEANS) scratch_other_cleans clean_subdirs add_to_cleanups_variable ready_to_clean
102         @# no code here.
103
104 establish_cleanup_variable:
105         $(eval CLEAN := true)
106
107 scratch_other_cleans:
108         $(eval OTHER_CLEANS := )
109
110 # add late breaking items to the cleanup list.  this is mainly the actual
111 # targets to build, since those are not specified until the user makefile
112 # is included.  we take a liberty here and also add different versions of
113 # the file suffixes so we can clean all versions of the targets.
114 add_to_cleanups_variable: $(SUPPLEMENTAL_CLEANUP_TARGETS)
115         $(eval CLEANUPS = $(ACTUAL_TARGETS) $(CLEANUPS) )
116 #       $(eval CLEANUPS = $(ACTUAL_TARGETS) $(ACTUAL_TARGETS:%.exe=%) $(ACTUAL_TARGETS:%.dll=%.so) $(ACTUAL_TARGETS:%.so=%.dll) $(CLEANUPS) )
117 #       echo "new CLEANUPS variable: $(CLEANUPS)"
118
119 # main cleaning task.
120 ready_to_clean:
121 ifneq "$(CLEANUPS)" ""
122         @echo Whacking [$(notdir $(CLEANUPS))]
123 endif
124         $(HIDESH) -c '\
125 if [ ! -z "$(CLEANUPS)" ]; then \
126   for spork19 in $(CLEANUPS) nonexistentishfileforlist; do \
127     rm -rf "$$spork19"; \
128   done \
129 fi'
130
131 ############################################################################
132
133 # "clean_subdirs" travels down each subdirectory and cleans using make.
134 clean_subdirs:
135         $(HIDESH)$(CLAM_SCRIPTS)/clean_subdirs.sh
136
137 # "rm_links" removes the files in the current directory that are links
138 # to other files.  this is only useful in a unix environment.
139 rm_links:
140         $(HIDESH) -c '\
141 for gujira26 in *; do \
142   if [ -h "$$gujira26" ]; then \
143     /bin/rm -f "$$gujira26"; \
144   fi \
145 done; \
146 exit 0'
147