Skip to content

Commit

Permalink
building data vs parallel make for 3.6 revisited
Browse files Browse the repository at this point in the history
Replace "arbitrary" order of the three recently added 'makedefs -s'
dependencies with the specific order used within makedefs.

Guarantee that the three temp files used by 'makedefs -s' have
distinct names just in case the Makefile gets changed to ignore those
extra dependencies and someone runs parallel make.
  • Loading branch information
PatR committed May 11, 2024
1 parent 90d23e8 commit 73c2922
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
18 changes: 10 additions & 8 deletions sys/unix/Makefile.dat
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,20 @@ quest.dat: quest.txt ../util/makedefs
oracles: oracles.txt ../util/makedefs
../util/makedefs -h

# note: 'makedefs -s' constructs three files at once, but traditional 'make'
# doesn't provide any way for a Makefile to indicate that; use arbitrary
# dependencies to prevent parallel make from running multiple instances of
# 'makedefs -s' at the same time; depending upon how 'make' checks timestamps,
# note: 'makedefs -s' constructs three files at once: "epitaph", "engrave",
# and "bogusmon", in that order, but traditional 'make' doesn't provide any
# way for a Makefile to indicate that; make the third depend on the second
# and the second depend on the first so that if someone runs parallel make
# it will be forced to run three instances of 'makedefs -s' sequentially
# rather than simultaneously; depending upon how 'make' checks timestamps,
# this might result in building all three of them three times in a row
# [that will still produce the correct result in the end, and the extra
# overhead of doing it should be negligible; 'gnu make' only runs it once]
engrave: epitaph engrave.txt ../util/makedefs
# overhead of doing it should be negligible]
bogusmon: engrave bogusmon.txt ../util/makedefs
../util/makedefs -s
epitaph: bogusmon epitaph.txt ../util/makedefs
engrave: epitaph engrave.txt ../util/makedefs
../util/makedefs -s
bogusmon: bogusmon.txt ../util/makedefs
epitaph: epitaph.txt ../util/makedefs
../util/makedefs -s

# note: 'options' should have already been made when include/date.h was created
Expand Down
34 changes: 20 additions & 14 deletions util/makedefs.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ static char *FDECL(xcrypt, (const char *));
static unsigned long FDECL(read_rumors_file,
(const char *, int *, long *, unsigned long));
static boolean FDECL(get_gitinfo, (char *, char *));
static void FDECL(do_rnd_access_file, (const char *, const char *));
static void FDECL(do_rnd_access_file,
(const char *, const char *, const char *));
static boolean FDECL(d_filter, (char *));
static boolean FDECL(h_filter, (char *));
static void NDECL(build_savebones_compat_string);
Expand Down Expand Up @@ -366,16 +367,19 @@ char *options;
* post-3.6.5:
* File must not be empty to avoid divide by 0
* in core's rn2(), so provide a default entry.
* [Second argument is used to construct a temporary file name
* without worrying about whether the file name macros from
* global.h have been modified with port-specific punctuation.]
*/
do_rnd_access_file(EPITAPHFILE,
do_rnd_access_file(EPITAPHFILE, "epitaph",
/* default epitaph: parody of the default engraving */
"No matter where I went, here I am.");
do_rnd_access_file(ENGRAVEFILE,
do_rnd_access_file(ENGRAVEFILE, "engrave",
/* default engraving: popularized by "The Adventures of
Buckaroo Bonzai Across the 8th Dimenstion" but predates
that 1984 movie; some attribute it to Confucius */
"No matter where you go, there you are.");
do_rnd_access_file(BOGUSMONFILE,
do_rnd_access_file(BOGUSMONFILE, "bogusmon",
/* default bogusmon: iconic monster that isn't in nethack */
"grue");
break;
Expand Down Expand Up @@ -965,12 +969,13 @@ unsigned long old_rumor_offset;
}

static void
do_rnd_access_file(fname, deflt_content)
const char *fname;
do_rnd_access_file(fname, basefname, deflt_content)
const char *fname, *basefname;
const char *deflt_content;
{
char *line;
char *line, greptmp[8 + 1 + 3 + 1];

Sprintf(greptmp, "grep-%.3s.tmp", basefname);
Sprintf(filename, DATA_IN_TEMPLATE, fname);
Strcat(filename, ".txt");
if (!(ifp = fopen(filename, RDTMODE))) {
Expand All @@ -993,9 +998,9 @@ const char *deflt_content;
more likely to be picked than normal but it's nothing to worry about */
(void) fputs(xcrypt(deflt_content), ofp);

tfp = getfp(DATA_TEMPLATE, "grep-s.tmp", WRTMODE);
tfp = getfp(DATA_TEMPLATE, greptmp, WRTMODE);
grep0(ifp, tfp);
ifp = getfp(DATA_TEMPLATE, "grep-s.tmp", RDTMODE);
ifp = getfp(DATA_TEMPLATE, greptmp, RDTMODE);

while ((line = fgetline(ifp)) != 0) {
if (line[0] != '#' && line[0] != '\n')
Expand All @@ -1005,7 +1010,7 @@ const char *deflt_content;
Fclose(ifp);
Fclose(ofp);

delete_file(DATA_TEMPLATE, "grep-s.tmp");
delete_file(DATA_TEMPLATE, greptmp);
return;
}

Expand Down Expand Up @@ -2273,8 +2278,9 @@ do_oracles()
void
do_dungeon()
{
char *line;
char *line, greptmp[8 + 1 + 3 + 1];

Sprintf(greptmp, "grep-%.3s.tmp", "dun");
Sprintf(filename, DATA_IN_TEMPLATE, DGN_I_FILE);
if (!(ifp = fopen(filename, RDTMODE))) {
perror(filename);
Expand All @@ -2291,9 +2297,9 @@ do_dungeon()
}
Fprintf(ofp, "%s", Dont_Edit_Data);

tfp = getfp(DATA_TEMPLATE, "grep-e.tmp", WRTMODE);
tfp = getfp(DATA_TEMPLATE, greptmp, WRTMODE);
grep0(ifp, tfp);
ifp = getfp(DATA_TEMPLATE, "grep-e.tmp", RDTMODE);
ifp = getfp(DATA_TEMPLATE, greptmp, RDTMODE);

while ((line = fgetline(ifp)) != 0) {
SpinCursor(3);
Expand All @@ -2308,7 +2314,7 @@ do_dungeon()
Fclose(ifp);
Fclose(ofp);

delete_file(DATA_TEMPLATE, "grep-e.tmp");
delete_file(DATA_TEMPLATE, greptmp);
return;
}

Expand Down

0 comments on commit 73c2922

Please sign in to comment.