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 | $(RANLIB) $(LIB_DEST)/lib$(LIB_NAME).a |
---|
108 | |
---|
109 | # |
---|
110 | # RULE for building unit test programs. |
---|
111 | # |
---|
112 | |
---|
113 | utest: .FORCE |
---|
114 | @if [ -d utest ] ; then \ |
---|
115 | echo "Making unit tests for `pwd`"; \ |
---|
116 | cd utest; \ |
---|
117 | make; \ |
---|
118 | cd ..; \ |
---|
119 | fi |
---|
120 | |
---|
121 | .FORCE: |
---|
122 | |
---|
123 | # |
---|
124 | # RULE for building an executable. |
---|
125 | # |
---|
126 | # For library modules, these do nothing, but we define one so that make exe |
---|
127 | # can be passed down to all source directories. |
---|
128 | # |
---|
129 | exe: |
---|
130 | @echo "make exe does nothing for library modules" |
---|
131 | |
---|
132 | # |
---|
133 | # RULES for cleaning up derived files. |
---|
134 | # |
---|
135 | # 'clean' removes all objects produced by this file, as well as other |
---|
136 | # extraneous artifacts of compiling and building libraries. |
---|
137 | # |
---|
138 | # A subsequent make will both recompile the source code and recreate |
---|
139 | # the shared library. clean also removes files core files and other |
---|
140 | # auxilliary files created during compilation. |
---|
141 | # |
---|
142 | # 'clean_lib' removes only the libraries, both shared and archive. |
---|
143 | # |
---|
144 | # A subsequent make will recreate the shared library from the compiled |
---|
145 | # object files. |
---|
146 | # |
---|
147 | thisdir_clean: thisdir_clean_lib |
---|
148 | @/bin/rm -f *.o *.mod *.f90 core so_locations Makefile.bak *~ #*# |
---|
149 | @/bin/rm -fr ii_files |
---|
150 | @if [ -d utest ] ; then \ |
---|
151 | echo " Doing make clean on utest subdirectory"; \ |
---|
152 | cd utest; \ |
---|
153 | make clean; \ |
---|
154 | cd ..; \ |
---|
155 | fi |
---|
156 | |
---|
157 | thisdir_clean_lib: |
---|
158 | @/bin/rm -f $(LIB_DEST)/lib$(LIB_NAME).* |
---|
159 | |
---|
160 | # |
---|
161 | # RULES for creating the include dependencies. |
---|
162 | # |
---|
163 | # 'depend' creates the dependencies and appends them to the end of this file. |
---|
164 | # Depend uses some customized logic to determine the name of the source |
---|
165 | # code file associated with each object file in OBJS. This means that we |
---|
166 | # can mix source code extensions in the same library (e.g. use C and C++ |
---|
167 | # source interchangeably). See compile_rules.mk for supported file name |
---|
168 | # extensions. |
---|
169 | # |
---|
170 | # 'clean_depend' removes the dependencies from this file, which makes the |
---|
171 | # Makefile much smaller. make clean_depend should be done before |
---|
172 | # checking a Makefile into revision control. |
---|
173 | # |
---|
174 | thisdir_clean_depend: generic_clean_depend |
---|
175 | @if [ -d utest ] ; then \ |
---|
176 | echo " Doing make clean_depend on utest subdirectory"; \ |
---|
177 | cd utest; \ |
---|
178 | $(MAKE) clean_depend; \ |
---|
179 | cd ..; \ |
---|
180 | fi |
---|
181 | |
---|
182 | thisdir_depend: generic_depend |
---|
183 | @if [ -d utest ] ; then \ |
---|
184 | echo " Doing make depend on utest subdirectory"; \ |
---|
185 | cd utest; \ |
---|
186 | $(MAKE) depend; \ |
---|
187 | cd ..; \ |
---|
188 | fi |
---|
189 | |
---|
190 | include $(BUILD_DIR)/depend_rules.mk |
---|
191 | |
---|