|
| 1 | +####################################################################################### |
| 2 | +# |
| 3 | +# Makefile.Clibs |
| 4 | +# |
| 5 | +# This is an extension for Makefile.standard which includes pattern rules for |
| 6 | +# the generation of C-libraries. Basically, it is designed for the compilation |
| 7 | +# of the C-parts of the stdlib but it can be used in any other situation as |
| 8 | +# well. Therefore, the following assumptions are made: |
| 9 | +# |
| 10 | +# If the actual directory contains C-files only (no .sac files!), all .c-files |
| 11 | +# in the directory belong to the same module whose name equals the directory's |
| 12 | +# name. |
| 13 | +# Otherwise, it is assumed that each .c file constitutes its own library whose |
| 14 | +# name equals the .c-file's name. |
| 15 | +# |
| 16 | + |
| 17 | +include $(SACBASE)/Makefiles/Makefile.standard |
| 18 | + |
| 19 | +C_FILES := $(sort $(patsubst %.y, %.tab, \ |
| 20 | + $(patsubst %.l, lex.%, \ |
| 21 | + $(patsubst %.c, %, \ |
| 22 | + $(filter-out $(EXCLUDE_FILES), \ |
| 23 | + $(wildcard *.[cly])))))) |
| 24 | +OBJECTS := $(patsubst %, %.o, $(C_FILES)) |
| 25 | + |
| 26 | +ifneq ($(C_FILES),) |
| 27 | +ifeq ($(SAC_FILES),) |
| 28 | + |
| 29 | +# |
| 30 | +# we assume all .c-files to belong to a single module. |
| 31 | +# Its name equals the last part of the actual directory. |
| 32 | +# |
| 33 | + |
| 34 | +C_MODS := $(notdir $(shell pwd)) |
| 35 | +C_MODTARGETS := $(patsubst %,$(LIBTARGETDIR)/%.a,$(notdir $(shell pwd))) |
| 36 | + |
| 37 | +$(LIBTARGETDIR)/%.a: $(OBJECTS) |
| 38 | + $(MKDIR) $(LIBTARGETDIR) |
| 39 | + $(AR) cr $@ $(OBJECTS) |
| 40 | + ifdef RANLIB |
| 41 | + $(RANLIB) $@ |
| 42 | + endif |
| 43 | + $(CLOCK_SKEW_ELIMINATION) $@ |
| 44 | + |
| 45 | +else |
| 46 | + |
| 47 | +# |
| 48 | +# we assume each file XYZ.c to define a module XYZ.a |
| 49 | +# |
| 50 | + |
| 51 | +C_MODS := $(C_FILES) |
| 52 | +C_MODTARGETS := $(patsubst %,$(LIBTARGETDIR)/%.a, $(C_FILES)) |
| 53 | + |
| 54 | +$(LIBTARGETDIR)/%.a: %.o |
| 55 | + $(MKDIR) $(LIBTARGETDIR) |
| 56 | + $(AR) cr $@ $< |
| 57 | + ifdef RANLIB |
| 58 | + $(RANLIB) $@ |
| 59 | + endif |
| 60 | + $(CLOCK_SKEW_ELIMINATION) $@ |
| 61 | + |
| 62 | +endif |
| 63 | +endif |
| 64 | + |
| 65 | + |
| 66 | +# |
| 67 | +# in case of MAKE_NON_LOCAL_DEPENDENCIES == yes, switch from $(C_MODTARGETS) |
| 68 | +# to dummy-targets .libD in order to get sac-conform output of gmake 8-) |
| 69 | +# |
| 70 | + |
| 71 | +ifeq ("$(MAKE_NON_LOCAL_DEPENDENCIES)", "yes") |
| 72 | + |
| 73 | +C_MODTARGETS_D = $(patsubst %,%.libD, $(C_MODS)) |
| 74 | + |
| 75 | +# |
| 76 | +# default target definition in case of MAKE_NON_LOCAL_DEPENDENCIES == yes: |
| 77 | +# |
| 78 | +standard_all: $(C_MODTARGETS_D) |
| 79 | + |
| 80 | +else |
| 81 | + |
| 82 | +# |
| 83 | +# normal default target definition: |
| 84 | +# |
| 85 | + |
| 86 | +standard_all: $(C_MODTARGETS) |
| 87 | +endif |
| 88 | + |
| 89 | +%.o: %.c |
| 90 | + @if [ "$(@D)" == "." ]; \ |
| 91 | + then $(CC) $(CCFLAGS) $(CCINCLUDES) -o $@ -c $<; \ |
| 92 | + $(CLOCK_SKEW_ELIMINATION) $@; \ |
| 93 | + else $(MAKE) -C $(@D); \ |
| 94 | + fi |
| 95 | + |
| 96 | +%.tab.c %.tab.h: %.y |
| 97 | + $(YACC) $(YFLAGS) $< |
| 98 | + $(CLOCK_SKEW_ELIMINATION) $*.tab.c $*.tab.h |
| 99 | + |
| 100 | +lex.%.c: %.l %.tab.h |
| 101 | + $(LEX) $(LFLAGS) $< |
| 102 | + $(CLOCK_SKEW_ELIMINATION) $@ |
| 103 | + |
| 104 | + |
| 105 | +YACC_H_FILES := $(patsubst %.y, %.tab.h, $(wildcard *.y)) |
| 106 | +# |
| 107 | +# $(YACC_H_FILES) might be included by any .c files. |
| 108 | +# Therefore, bison has to be run before any dependency |
| 109 | +# is generated! |
| 110 | +# |
| 111 | +.%.d: %.c $(YACC_H_FILES) |
| 112 | + @$(ECHO) "$(CC) -M $(CCFLAGS) $(CCINCLUDES) $< > $@" |
| 113 | + @if $(CC) -M $(CCFLAGS) $(CCINCLUDES) $< > $@d ; \ |
| 114 | + then sed 's/\($*\)\.o[ :]*/$*\.o $@\: /' <$@d >$@; \ |
| 115 | + $(RM) $@d ; \ |
| 116 | + else $(RM) $@d ; \ |
| 117 | + exit 1 ; \ |
| 118 | + fi |
| 119 | + $(CLOCK_SKEW_ELIMINATION) $@ |
| 120 | + |
| 121 | +%.libD: |
| 122 | + @ $(MAKE) out2 modname_long=\($(LIBTARGETDIR)/\)$*.a |
| 123 | + @ $(MAKE) $(LIBTARGETDIR)/$*.a |
| 124 | + |
| 125 | +.PRECIOUS: $(OBJECTS) %.tab.c %.tab.h lex.%.c |
| 126 | + |
| 127 | +####################################################################################### |
| 128 | +# |
| 129 | +# automatic dependency updating mechanism: |
| 130 | +# gmake implicitly remakes all files that are included! |
| 131 | +# |
| 132 | + |
| 133 | +C_DEPS = $(patsubst %,.%.d, $(C_FILES)) |
| 134 | + |
| 135 | +ifneq ($(C_DEPS),) |
| 136 | + ifneq ($(TARGET),clean) |
| 137 | + ifneq ($(TARGET),distclean) |
| 138 | + ifneq ($(TARGET),tar) |
| 139 | + ifneq ($(TARGET),untar) |
| 140 | +include $(C_DEPS) |
| 141 | + endif |
| 142 | + endif |
| 143 | + endif |
| 144 | + endif |
| 145 | +endif |
| 146 | + |
| 147 | + |
| 148 | + |
0 commit comments