Codebase list tigr-glimmer / 8356402 src / c_make.gen
8356402

Tree @8356402 (Download .tar.gz)

c_make.gen @8356402raw · history · blame

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
######################################################################
# $Source: /fs/szdevel/src/cvsroot/GF/Glimmer3/src/c_make.gen,v $
# $Revision: 1.3 $
# $Date: 2006/05/26 14:11:12 $
######################################################################

######################################################################
# Module:
#
#   c_make.gen
#
# Description:
#
#   Generic makefile for C compilation and link
#
# Assumptions:
#
#   This makefile requires the use of GNU make.
#
#   It is assumed that the following working directories exist:
#     <subsystem_level>/src
#     <subsystem_level>/inc
#     <subsystem_level>/obj
#     <subsystem_level>/lib
#     <subsystem_level>/bin
#   (The obj, lib, bin, and inc directories will be created automatically
#   if they do not already exist.)
#
#   All objects created by this makefile will be placed immediately in:
#       <subsystem_level>/obj
#   All libraries created by this makefile will be placed immediately in:
#       <subsystem_level>/lib
#   All executables created by this makefile will be placed immediately in:
#       <subsystem_level>/bin
#   All include files belonging to this subsystem (not necessarily all
#   include files required by this subsystem) are located immediately in:
#       <subsystem_level>/inc
#   Source files (and their associated makefiles) are contained
#   directly or indirectly in <subsystem_level>/src:
#     <subsystem_level>/src
#            or
#     <subsystem_level>/src/<component_level_1>
#            or
#     <subsystem_level>/src/<component_level_1>/.../<component_level_N>
#   A makefile is located in the same directory as all source files
#   that the makefile requires.
#
#   This makefile is to be included at the end of a makefile that
#   provides instance-specific definitions and dependencies, with the
#   directive:
#
#       include $(SEP_PATH)/makefiles/c_make.gen
#
#   Variables defined by the instance-specific makefile:
#   ----------------------------------------------------
#
#     SOURCES = 
#       Lists all sources compiled by this makefile.
#
#     OBJECTS = 
#       Lists all objects compiled by this makefile (i.e., one-to-one
#       with SOURCES). OBJECTS can be listed explicitly or can be
#       specified with the following definition:
#
#          OBJECTS = $(patsubst %.c, %.o, $(SOURCES))
#
#     LIBRARIES = 
#       Lists simple name (in "libx.a" form) of each library that is
#       built by this makefile.
#
#     PROGS = 
#       Lists each executable created by this makefile.
#
#     INC_IMPORT_DIRS +=
#       Lists directories containing header files that must be imported
#       from other subsystems.
#       Format is white-space-separated list of paths.
#
#     LIB_IMPORT_DIRS +=
#       Lists directories containing libraries that must be imported
#       from other subsystems.
#       Format is white-space-separated list of paths.
#       Paths must be absolute (beginning with '/'). Path beginning
#       with $(LOCAL_WORK) will work.
#
#     LOCAL_WORK =
#       Identifies the <subsystem_level> directory (parent of
#       the inc, src, lib, obj, and bin subdirectories) with
#       an absolute path.
#       For a makefile located in
#         <subsystem_level>/src/<component_level_1>
#       the following definition would work:
#          LOCAL_WORK = $(shell cd ../..; pwd)
#
#   Dependencies defined in the instance-specific makefile:
#   -------------------------------------------------------
#
#   (1) Dependencies of OBJECTS on .h files will be automatically
#       computed and the appropriate dependency lines will be
#       automatically included. They need not be specified in
#       the instance-specific makefile.
#   (2) Dependencies of individual PROGS and LIBRARIES on objects
#       and libraries must be explicitly specified. When specifying
#       a dependency on a library, use the "libx.a" form, e.g.:
#                my_target: abc.o def.o libxyz.a
#       Use the simple name of each item on which there is a dependency
#       (including dependencies on imported libraries). However,
#       if a dependence on a standard library is explicitly specified,
#       then the path to that standard library must be specified as
#       part of the INC_IMPORT_DIRS.
#
#   The included make.conf file:
#   ----------------------------
#
#   This makefile attempts to include another makefile, "make.conf"
#   (but will execute correctly whether "make.conf" exists or not).
#   "make.conf" serves two purposes:
#       1. It provides a way to override definitions in this
#          generic makefile.
#       2. It provies a way to specify search paths for include files,
#          objects, and libraries that the instance-specific makefile
#          expects to exist but are "missing." For example, an expected
#          object file might be "missing" from an individual programmer's
#          working directory because the intention was to use an object
#          file that was already compiled in a group working directory
#          or a release directory. The make.conf search variables are:
#            INC_SEARCH_PATH
#              White-space-separated list of paths.
#              Specifies where to look for "missing" header files.
#            OBJ_SEARCH_PATH
#              White-space-separated list of paths.
#              Specifies where to look for "missing" object files that
#              should be made by this makefile but cannot because the
#              source files are "missing."
#            LIB_SEARCH_PATH
#              White-space-separated list of paths.
#              Specifies where to look for "missing" library files.
#   In a completely populated working directory (e.g., a directory
#   from which a release is to be made), the makefile should work
#   correctly without the existence of a make.conf file.
#   It is also possible to redefine the LOCAL_WORK variable in the
#   make.conf file to reflect a working directory depth that differs
#   from the standard.
#
#  Targets defined in this makefile:
#  ---------------------------------
#
#  objs
#  libs
#  progs
#  clean
#  clean_obj
#  clean_lib
#  clean_bin
#  clean_dep
#
#  Compile and link variables/flags:
#  ---------------------------------
#
#  The generic makefile makes use of the following compile and link
#  variables/flags:
#
#    CC               (C compiler)
#    CPPFLAGS         (C preprocessor options [but not -I paths] )
#    CFLAGS           (C compiler options [but not -I paths] )
#    CDEFS            (C compiler defines [ -D ])
#    CXX              (C++ compiler)
#    CXXFLAGS         (C++ compiler options [but not -I paths] )
#    CXXDEFS          (C++ compiler defines [ -D ])
#    AR               (archive program [create binary libraries] )
#    ARFLAGS          (archive program options)
#    LDFLAGS          (linker options [but not -L paths] )
#
#  There are three ways to override the values for these variables:
#
#     1. Assign values on the "make" command line.
#     2. Assign values in the make.conf file (or in a file included
#        by the make.conf file).
#     3. Assign values to these variables in the environment.
#
#  The order of precedence is as follows:
#
#     - Environment variable overrides value in the generic makefile.
#     - Value in make.conf overrrides value on environment.
#     - Value on command line overrides value in make.conf.
#
######################################################################

#### Soft link programs
LINKS_PGM = /cm/cmtools/bin/links.pl

#### Set up paths
LOCAL_INC=$(LOCAL_WORK)/inc
LOCAL_BIN=$(LOCAL_WORK)/bin
LOCAL_LIB=$(LOCAL_WORK)/lib
LOCAL_OBJ=$(LOCAL_WORK)/obj
LOCAL_SYS_INC=$(SEP_PATH)/../SYS/inc

#### Various flags
#### Do not redefine if (a) passed in on command line, or (b)
#### defined in an environment variable.

ifneq "$(origin CC)" "environment"
CC      = cc
endif

ifneq "$(origin CPPFLAGS)" "environment"
CPPFLAGS=
endif

ifneq "$(origin CFLAGS)" "environment"
CFLAGS  =
endif

ifneq "$(origin CDEFS)" "environment"
CDEFS  =
endif

ifneq "$(origin CXX)" "environment"
CXX	= g++
endif

ifneq "$(origin CXXFLAGS)" "environment"
CXXFLAGS=
endif

ifneq "$(origin CXXDEFS)" "environment"
CXXDEFS= -D__cplusplus
endif

ifneq "$(origin AR)" "environment"
AR      = ar
endif

ifneq "$(origin ARFLAGS)" "environment"
ARFLAGS = rvs
endif

ifneq "$(origin LDFLAGS)" "environment"
LDFLAGS =
endif

#### Delete default suffix rules
.SUFFIXES:

#### Include customization of flags and additional search paths
-include make.conf

#### Make expected directories
define make_expected_directories
if [ ! -e $(LOCAL_BIN) ] ; then mkdir $(LOCAL_BIN) ; fi ; \
if [ ! -e $(LOCAL_OBJ) ] ; then mkdir $(LOCAL_OBJ) ; fi ; \
if [ ! -e $(LOCAL_LIB) ] ; then mkdir $(LOCAL_LIB) ; fi ; \
if [ ! -e $(LOCAL_INC) ] ; then mkdir $(LOCAL_INC) ; fi ;
endef
dummy_expected_directories := $(shell $(make_expected_directories))


#### Set INC_DIRS for finding headers
INC_DIRS = $(patsubst %, -I%, \
    $(strip $(LOCAL_INC) \
            $(LOCAL_SYS_INC) \
            $(INC_IMPORT_DIRS) \
            $(INC_SEARCH_PATH)))

#### Set LD_DIRS for finding libraries
LD_DIRS = $(patsubst %, -L%, \
    $(strip $(LOCAL_LIB) \
            $(LIB_IMPORT_DIRS) \
            $(LIB_SEARCH_PATH)))

#### VPATH
VPATH = $(shell pwd)$(patsubst %, :%, \
    $(strip $(LOCAL_OBJ) \
            $(LOCAL_LIB) \
            $(LOCAL_BIN) \
            $(LIB_IMPORT_DIRS) \
            $(LIB_SEARCH_PATH)))

#### no target, make all!
default_target: all

#### Clean
clean:	clean_obj clean_lib clean_bin clean_dep

clean_dep:
	rm -f $(DEPS)
clean_obj:
	-cd $(LOCAL_OBJ); rm -f $(OBJECTS)
clean_lib:
	-cd $(LOCAL_LIB); rm -f $(LIBRARIES) $(IMPORTED_LIBRARIES)
clean_bin:
	-cd $(LOCAL_BIN); rm -f $(PROGS)

#### Separate source types
C_OBJECTS      := $(patsubst %.c, %.o, $(filter %.c, $(SOURCES)))
CXX_OBJECTS_CC := $(patsubst %.cc, %.o, $(filter %.cc, $(SOURCES)))
CXX_OBJECTS_C  := $(patsubst %.C, %.o, $(filter %.C, $(SOURCES)))
CXX_OBJECTS    := $(CXX_OBJECTS_CC) $(CXX_OBJECTS_C)
OBJECTS        := $(C_OBJECTS) $(CXX_OBJECTS)

C_DEPS         := $(patsubst %.c, %.d, $(filter %.c, $(SOURCES)))
CXX_DEPS_CC    := $(patsubst %.cc, %.d, $(filter %.cc, $(SOURCES)))
CXX_DEPS_CPP   := $(patsubst %.cpp, %.d, $(filter %.cpp, $(SOURCES)))
CXX_DEPS_C     := $(patsubst %.C, %.d, $(filter %.C, $(SOURCES)))
CXX_DEPS       := $(CXX_DEPS_CC) $(CXX_DEPS_C)
DEPS           := $(C_DEPS) $(CXX_DEPS)

#### Generic object, lib, and bin commands

# Check for local pesence of source file to accommodate referencing
# of objects in other working directories.

#### *.c
$(C_OBJECTS): %.o: %.c
	@ echo "@@@@@@@@@@@@@@@@@@@ " $< "@@@@@@@@@@@@@@@@@@@@@";
	@ if [ -e $(notdir $<) ] ; then \
	  $(CC) $(CPPFLAGS) $(CDEFS) $(CFLAGS) -c \
		$(INC_DIRS) -o $(LOCAL_OBJ)/$*.o $< ; \
	else \
	  $(LINKS_PGM) $(LOCAL_OBJ) \
            "$(patsubst %, :%, $(strip $(OBJ_SEARCH_PATH)))" $(notdir $@) ; \
	fi ;

#### *.cc
$(CXX_OBJECTS_CC): %.o: %.cc
	@ echo "@@@@@@@@@@@@@@@@@@@ " $< "@@@@@@@@@@@@@@@@@@@@@";
	@ if [ -e $(notdir $<) ] ; then \
	  $(CXX) $(CPPFLAGS) $(CXXDEFS) $(CXXFLAGS) -c \
		$(INC_DIRS) -o $(LOCAL_OBJ)/$*.o $< ; \
	else \
	  $(LINKS_PGM) $(LOCAL_OBJ) \
            "$(patsubst %, :%, $(strip $(OBJ_SEARCH_PATH)))" $(notdir $@) ; \
	fi ;

#### *.C
$(CXX_OBJECTS_C): %.o: %.C
	@ echo "@@@@@@@@@@@@@@@@@@@ " $< "@@@@@@@@@@@@@@@@@@@@@";
	@ if [ -e $(notdir $<) ] ; then \
	  $(CXX) $(CPPFLAGS) $(CXXDEFS) $(CXXFLAGS) -c \
		$(INC_DIRS) -o $(LOCAL_OBJ)/$*.o $< ; \
	else \
	  $(LINKS_PGM) $(LOCAL_OBJ) \
            "$(patsubst %, :%, $(strip $(OBJ_SEARCH_PATH)))" $(notdir $@) ; \
	fi ;

#### To accommodate referencing of objects in other working directories.
$(SOURCES):
	@echo $@ not present

$(LIBRARIES):
	@ echo "################### " $@ "#####################";
	@ cd $(LOCAL_OBJ); \
	  $(AR) $(ARFLAGS) $(LOCAL_LIB)/$(notdir $@) $+ 

$(PROGS):
	@ echo "++++++++++++++++++++ " $@ "++++++++++++++++++++++";
	@ if [ -z "$(filter $(CXX_OBJECTS), $(notdir $+))" ] ; then \
	  cd $(LOCAL_OBJ); \
	    if $(CC) -o $(LOCAL_BIN)/$(notdir $@) $(LDFLAGS) \
               $(LD_DIRS) $(filter-out lib%.a, $+) \
	       $(patsubst lib%.a, -l%, $(filter lib%.a, $+)) ; then \
			true; else rm -f $(LOCAL_BIN)/$(notdir $@); fi; \
	else \
	  cd $(LOCAL_OBJ); \
	    if $(CXX) -o $(LOCAL_BIN)/$(notdir $@) $(LDFLAGS) \
               $(LD_DIRS) $(filter-out lib%.a, $+) \
	       $(patsubst lib%.a, -l%, $(filter lib%.a, $+)) ; then \
			true; else rm -f $(LOCAL_BIN)/$(notdir $@); fi; \
	fi ;

#### For making dependencies
$(C_DEPS): %.d: %.c
	@ if [ -e $(notdir $<) ] ; then \
	  $(SHELL) -ec '$(CC) -M $(CPPFLAGS) $(INC_DIRS) $< \
	    | sed '\''s/$*\\.o[ :]*/& $@/g'\'' > $@' ; \
        fi ;

$(CXX_DEPS_CC): %.d: %.cc
	@ if [ -e $(notdir $<) ] ; then \
	  $(SHELL) -ec '$(CXX) -M $(CPPFLAGS) $(INC_DIRS) $< \
	    | sed '\''s/$*\\.o[ :]*/& $@/g'\'' > $@' ; \
        fi ;

$(CXX_DEPS_C): %.d: %.C
	@ if [ -e $(notdir $<) ] ; then \
	  $(SHELL) -ec '$(CXX) -M $(CPPFLAGS) $(INC_DIRS) $< \
	    | sed '\''s/$*\\.o[ :]*/& $@/g'\'' > $@' ; \
        fi ;

$(CXX_DEPS_CPP): %.d: %.cpp
	@ if [ -e $(notdir $<) ] ; then \
	  $(SHELL) -ec '$(CC) -M $(CPPFLAGS) $(INC_DIRS) $< \
	    | sed '\''s/$*\\.o[ :]*/& $@/g'\'' > $@' ; \
        fi ;

-include $(DEPS)

#### Specific target to make objects
objs: $(OBJECTS)

#### Specific target to make libraries
libs: $(LIBRARIES)

#### Specific target to make progs
progs: $(PROGS)

#### Specific target to make objects
#incs:

#### Phony
.PHONY: all clean clean_obj clean_lib clean_bin


# The following recurses the subdirectories that exist
define dosubdirs
echo "* Make Target is " $(TGT);
for i in $(SUBDIRS);\
  do \
    if [ -d $$i ]; then \
      cd $$i;\
      echo "#####    Making Directory " `pwd` " " $(TGT) " #####";\
      $(MAKE) $(TGT);\
      cd ..;\
    fi; \
  done;
endef