Skip to content

Commit d3ff017

Browse files
committed
Add several fixes to Makefiles of demos and tuts
1 parent 3a3a004 commit d3ff017

5 files changed

Lines changed: 168 additions & 21 deletions

File tree

Makefiles/Makefile.Clibs

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
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+

Makefiles/Makefile.Config

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#
1010
OS := `uname -s`
1111
OSREV := `uname -r`
12-
ARCH := `arch`
12+
ARCH := `uname -m`
1313

1414
SHELL := /bin/sh
1515

@@ -24,10 +24,9 @@ endif
2424
#
2525
# set specific compiler flags
2626
#
27-
override CCFLAGS += -Wall -std=c99
27+
override CCFLAGS += -Wall -std=c99
2828
LDFLAGS := -Wl,-multiply_defined,suppress $(LDFLAGS)
29-
30-
29+
CCINCLUDES := $(shell $(SAC2C) -CSACINCLUDES)
3130

3231
ECHO = echo
3332
NAWK = awk
@@ -46,13 +45,14 @@ DATE_TIME = date
4645
ZIP = gzip -f
4746
UNZIP = gunzip -f
4847
NOOP = sleep 1
48+
CLOCK_SKEW_ELIMINATION = $(TOUCH) -a -c -d '-2 seconds'
4949

5050
UUENCODE = uuencode
5151
UUDECODE = uudecode
5252

5353
ifndef MEASURE
54-
MEASURE = timemult -i -h $(HOSTMACHINE) -l $(HOSTLOGIN) -r 4
55-
# MEASURE = time
54+
#MEASURE = timemult -i -h $(HOSTMACHINE) -l $(HOSTLOGIN) -r 4
55+
MEASURE = time
5656
endif
5757

5858
ifndef HOSTMACHINE

Makefiles/Makefile.standard

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#######################################################################################
3333
#
3434
# make sure that Makefile.standard is not included more than once!
35-
# ( necessary since Makefile.time and Makefile.check both include
35+
# ( necessary since Makefile.time and Makefile.check both include
3636
# Makefile.standard but can be included from a single Makefile )
3737
#
3838

@@ -130,7 +130,7 @@ $(TARGETDIR)/%_mt: %.sac
130130
@ $(MKDIR) $(TARGETDIR)
131131
-$(SAC2C) $(SAC2CFLAGS) -target mt_pth -o $@ $<
132132
$(RM) $(TARGETDIR)/$*_mt.c
133-
@ $(ECHO) "$(SAC2C) $(SAC2CFLAGS) -mt -o $@ $<" >.$*_mt$(LF_EXT)
133+
@ $(ECHO) "$(SAC2C) $(SAC2CFLAGS) -t mt_pth -o $@ $<" >.$*_mt$(LF_EXT)
134134
@ $(SAC2C) -V >> .$*_mt$(LF_EXT)
135135

136136

@@ -157,7 +157,7 @@ clean_local:
157157
-$(RM) $(DEPS) $(C_DEPS) $(VERS)
158158
-$(RM) $(CLOG_FILES) $(RES_FILES)
159159

160-
# Don't call 'make' after clean_local has been made! Otherwise, $(DEPS), $(C_DEPS),
160+
# Don't call 'make' after clean_local has been made! Otherwise, $(DEPS), $(C_DEPS),
161161
# and $(VERS) will be created again!
162162

163163

@@ -168,11 +168,11 @@ cleancheck_local:
168168
-$(RM) $(CLOG_FILES) $(addsuffix .base,$(CLOG_FILES))
169169
-$(RM) $(RES_FILES) $(addsuffix .base,$(RES_FILES))
170170

171-
std_clean_propogate:
171+
std_clean_propogate:
172172
$(MAKE) subdirs TARGET="clean"
173173
$(MAKE) clean_local
174174

175-
clean:
175+
clean:
176176
$(MAKE) subdirs TARGET="clean"
177177
$(MAKE) clean_local
178178

@@ -218,6 +218,3 @@ subdirs:
218218
fi
219219

220220
endif # ifndef STDMKFILE
221-
222-
223-

Makefiles/Makefile.versions

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ standard_all: $(VERSIONTARGETS)
8080
# for which a XYZ.vers file is present, the version rules are created and written
8181
# into a file .XYZ.v. This is achieved by means of the following pattern rule:
8282
#
83+
# NOTE: echo on GNU/Linux and BSD is inconsistent with whne it'll expand `\' characters
84+
# like `\n' or `\t' - as such below literal <TAB> characters have been inserted.
8385

8486
.%.v: %.sac %.vers
8587
@ $(ECHO) "creating $@ from $*.vers"
@@ -95,10 +97,10 @@ standard_all: $(VERSIONTARGETS)
9597
fi; \
9698
vflags=`echo $${v} | $(NAWK) -F: '{print $$2}'`; \
9799
$(ECHO) '$$(TARGETDIR)/'$${vname}': $*.sac .$*.v' >>$@; \
98-
$(ECHO) '\t@ $$(MKDIR) $$(TARGETDIR)' >>$@; \
99-
$(ECHO) '\t-$$(SAC2C) $$(SAC2CFLAGS) '$${vflags}' -o $$@ $$<' >>$@; \
100-
$(ECHO) '\t$$(RM) [email protected]' >>$@; \
101-
$(ECHO) '\t@ $$(ECHO) '\"'$$(SAC2C) $$(SAC2CFLAGS) '$${vflags}' -o $$@' \
100+
$(ECHO) ' @ $$(MKDIR) $$(TARGETDIR)' >>$@; \
101+
$(ECHO) ' -$$(SAC2C) $$(SAC2CFLAGS) '$${vflags}' -o $$@ $$<' >>$@; \
102+
$(ECHO) ' $$(RM) [email protected]' >>$@; \
103+
$(ECHO) ' @ $$(ECHO) '\"'$$(SAC2C) $$(SAC2CFLAGS) '$${vflags}' -o $$@' \
102104
'$$<'\"' >.'$${vname}'$$(LF_EXT)' >>$@; \
103105
$(ECHO) >>$@; \
104106
done < $*.vers;

Makefiles/Makefile_template.prg

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ endif
2424
# LIBTARGETDIR = .
2525
# INCTARGETDIR = .
2626
# LIBSRCDIR = .
27-
# SUBDIRS =
27+
# SUBDIRS =
2828
# MAKE_NON_LOCAL_DEPENDENCIES = yes
2929

3030
#
@@ -39,7 +39,7 @@ endif
3939
#
4040
# CHECKLOGFILE = $(HOME)/sac/CHECKLOG
4141
# CHECKDIR = .checkdir
42-
# RT_FLAGS =
42+
# RT_FLAGS =
4343
# INPSDIR = .
4444
#
4545
#######################################################################################
@@ -59,6 +59,6 @@ include $(SACBASE)/Makefiles/Makefile.versions
5959
ifndef CHECKLOGFILE
6060
#CHECKLOGFILE = $(HOME)/sac/CHECKLOG
6161
endif
62-
62+
6363
#include $(SACBASE)/stdlib/Makefiles/Makefile.check
6464

0 commit comments

Comments
 (0)