1 | #------------------------------------------------------------------------------ |
---|
2 | # Make rules for producing a library module. |
---|
3 | # |
---|
4 | # This file is intended for use in Makefile via the include directive, e.g. |
---|
5 | # |
---|
6 | # include $(BUILD_DIR)/library_rules.mk |
---|
7 | # |
---|
8 | # It is assumed that the environment has been set by sourcing the build |
---|
9 | # resource file (buildrc). |
---|
10 | # |
---|
11 | # This file defines the following rules for library modules: |
---|
12 | # |
---|
13 | # all, lib, archive, linked_lib, utest, exe, clean, clean_lib, |
---|
14 | # clean_depend, depend. |
---|
15 | # |
---|
16 | # Copyright (C) 2001, WSI Corporation |
---|
17 | #------------------------------------------------------------------------------ |
---|
18 | # |
---|
19 | # For portability, use the Bourne shell within Makefiles. |
---|
20 | # There have been problems using the C-shell under Linux. |
---|
21 | # |
---|
22 | SHELL=/bin/sh |
---|
23 | MAKE=make |
---|
24 | |
---|
25 | # |
---|
26 | # RULES that can be passed through to subdirectories. |
---|
27 | # |
---|
28 | # Each of these rules executes the rule on this directory, then executes |
---|
29 | # the same rule on each subdirectory specified in SUB_DIRS. |
---|
30 | # |
---|
31 | # The rules for this directory are specified as thisdir_<rulename> in |
---|
32 | # this file, e.g. "thisdir_all" implements "make all" for this directory. |
---|
33 | # |
---|
34 | # The SUB_DIRS variable only needs to be set if building of subdirectories |
---|
35 | # is desired. In this case, the list of subdirectories ($$s) is set to the |
---|
36 | # no-op value of "foobar" to prevent the shell for seeing errors in the |
---|
37 | # subsequent for loop when SUB_DIRS is not set. |
---|
38 | # |
---|
39 | all lib archive linked_lib clean depend clean_depend clean_lib: |
---|
40 | @s="$(SUB_DIRS)" ; \ |
---|
41 | if [ -z "$${s}" ]; then \ |
---|
42 | s="foobar" ;\ |
---|
43 | fi; \ |
---|
44 | for d in $$s ; do \ |
---|
45 | if [ "$$d" = "foobar" ]; then\ |
---|
46 | continue ;\ |
---|
47 | fi ; \ |
---|
48 | if [ ! -d "$$d" ]; then \ |
---|
49 | echo " Error: subdir $$d is NOT a directory!"; \ |
---|
50 | contiuue ;\ |
---|
51 | fi ; \ |
---|
52 | if [ ! -r "$$d/Makefile" ]; then\ |
---|
53 | echo " Error: subdir $$d does NOT contain a Makefile!"; \ |
---|
54 | continue ;\ |
---|
55 | fi ; \ |
---|
56 | echo " Doing make $@ on library subdirectory $$d" ;\ |
---|
57 | cd $$d ; \ |
---|
58 | $(MAKE) $@;\ |
---|
59 | cd ..; \ |
---|
60 | done; \ |
---|
61 | $(MAKE) thisdir_$@ |
---|
62 | |
---|
63 | clean_exe: |
---|
64 | @echo "make clean_exe does nothing for library modules" |
---|
65 | |
---|
66 | thisdir_all: thisdir_linked_lib config |
---|
67 | |
---|
68 | # |
---|
69 | # Include the RULES for compilation and installing config files |
---|
70 | # |
---|
71 | include $(BUILD_DIR)/compile_rules.mk |
---|
72 | include $(BUILD_DIR)/config_rules.mk |
---|
73 | |
---|
74 | # |
---|
75 | # RULES for building a library. |
---|
76 | # |
---|
77 | # - 'lib' builds the library as a shared library. |
---|
78 | # - 'archive' builds the library as an archive library. |
---|
79 | # - 'linked_lib' builds the library as a shared library (if necessary), and |
---|
80 | # links the shared library to its dependent libraries. |
---|
81 | # - Specific library names are built depending on the update status of the |
---|
82 | # library of the same name installed in $(LIB_DEST). |
---|
83 | # - Libraries are built depending on the status of its object files (OBJS) |
---|
84 | # |
---|
85 | # NOTE: Shared libraries are linked against the libraries upon which they |
---|
86 | # depend. This is not possible with archive libraries. |
---|
87 | # |
---|
88 | thisdir_lib: lib$(LIB_NAME).$(LIB_EXT) |
---|
89 | |
---|
90 | lib$(LIB_NAME).$(LIB_EXT): $(LIB_DEST)/lib$(LIB_NAME).$(LIB_EXT) |
---|
91 | |
---|
92 | $(LIB_DEST)/lib$(LIB_NAME).$(LIB_EXT): $(OBJS) |
---|
93 | $(CXX) $(LIB_FLAGS) -o $@ $(OBJS) |
---|
94 | |
---|
95 | thisdir_linked_lib: $(OBJS) |
---|
96 | $(CXX) $(LIB_FLAGS) -o $(LIB_DEST)/lib$(LIB_NAME).$(LIB_EXT) $(OBJS) $(DEP_LIBS) |
---|
97 | @if [ `echo $(LIB_NAME) | grep Pkg` ] ; then \ |
---|
98 | pwd = `pwd` ; \ |
---|
99 | cd $(LIB_DEST) ; \ |
---|
100 | echo " Creating tcl package index in $(MOD_DEST)" ;\ |
---|
101 | exec echo "pkg_mkIndex . \*Pkg.so \*.tcl" | tclsh;\ |
---|
102 | cd "$$(pwd)"; \ |
---|
103 | fi |
---|
104 | |
---|
105 | thisdir_archive: $(OBJS) .FORCE |
---|
106 | ar $(ARFLAGS) $(LIB_DEST)/lib$(LIB_NAME).a $(OBJS) |
---|
107 | |
---|
108 | #thisdir_archive: lib$(LIB_NAME).a .FORCE |
---|
109 | # |
---|
110 | #lib$(LIB_NAME).a: $(LIB_DEST)/lib$(LIB_NAME).a .FORCE |
---|
111 | # |
---|
112 | #$(LIB_DEST)/lib$(LIB_NAME).a: .FORCE $(OBJS) |
---|
113 | # ar cruv $@ $(OBJS) |
---|
114 | |
---|
115 | # |
---|
116 | # RULE for building unit test programs. |
---|
117 | # |
---|
118 | |
---|
119 | utest: .FORCE |
---|
120 | @if [ -d utest ] ; then \ |
---|
121 | echo "Making unit tests for `pwd`"; \ |
---|
122 | cd utest; \ |
---|
123 | make; \ |
---|
124 | cd ..; \ |
---|
125 | fi |
---|
126 | |
---|
127 | .FORCE: |
---|
128 | |
---|
129 | # |
---|
130 | # RULE for building an executable. |
---|
131 | # |
---|
132 | # For library modules, these do nothing, but we define one so that make exe |
---|
133 | # can be passed down to all source directories. |
---|
134 | # |
---|
135 | exe: |
---|
136 | @echo "make exe does nothing for library modules" |
---|
137 | |
---|
138 | # |
---|
139 | # RULES for cleaning up derived files. |
---|
140 | # |
---|
141 | # 'clean' removes all objects produced by this file, as well as other |
---|
142 | # extraneous artifacts of compiling and building libraries. |
---|
143 | # |
---|
144 | # A subsequent make will both recompile the source code and recreate |
---|
145 | # the shared library. clean also removes files core files and other |
---|
146 | # auxilliary files created during compilation. |
---|
147 | # |
---|
148 | # 'clean_lib' removes only the libraries, both shared and archive. |
---|
149 | # |
---|
150 | # A subsequent make will recreate the shared library from the compiled |
---|
151 | # object files. |
---|
152 | # |
---|
153 | thisdir_clean: thisdir_clean_lib |
---|
154 | @/bin/rm -f *.o *.mod *.f90 core so_locations Makefile.bak *~ #*# |
---|
155 | @/bin/rm -fr ii_files |
---|
156 | @if [ -d utest ] ; then \ |
---|
157 | echo " Doing make clean on utest subdirectory"; \ |
---|
158 | cd utest; \ |
---|
159 | make clean; \ |
---|
160 | cd ..; \ |
---|
161 | fi |
---|
162 | |
---|
163 | thisdir_clean_lib: |
---|
164 | @/bin/rm -f $(LIB_DEST)/lib$(LIB_NAME).* |
---|
165 | |
---|
166 | # |
---|
167 | # RULES for creating the include dependencies. |
---|
168 | # |
---|
169 | # 'depend' creates the dependencies and appends them to the end of this file. |
---|
170 | # Depend uses some customized logic to determine the name of the source |
---|
171 | # code file associated with each object file in OBJS. This means that we |
---|
172 | # can mix source code extensions in the same library (e.g. use C and C++ |
---|
173 | # source interchangeably). See compile_rules.mk for supported file name |
---|
174 | # extensions. |
---|
175 | # |
---|
176 | # 'clean_depend' removes the dependencies from this file, which makes the |
---|
177 | # Makefile much smaller. make clean_depend should be done before |
---|
178 | # checking a Makefile into revision control. |
---|
179 | # |
---|
180 | thisdir_clean_depend: generic_clean_depend |
---|
181 | @if [ -d utest ] ; then \ |
---|
182 | echo " Doing make clean_depend on utest subdirectory"; \ |
---|
183 | cd utest; \ |
---|
184 | $(MAKE) clean_depend; \ |
---|
185 | cd ..; \ |
---|
186 | fi |
---|
187 | |
---|
188 | thisdir_depend: generic_depend |
---|
189 | @if [ -d utest ] ; then \ |
---|
190 | echo " Doing make depend on utest subdirectory"; \ |
---|
191 | cd utest; \ |
---|
192 | $(MAKE) depend; \ |
---|
193 | cd ..; \ |
---|
194 | fi |
---|
195 | |
---|
196 | include $(BUILD_DIR)/depend_rules.mk |
---|
197 | |
---|