Skip to content

Commit 87b53d4

Browse files
authored
Merge pull request #364 from rustcoreutils/make-merge
Make merge
2 parents f957698 + a7d0eaf commit 87b53d4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+4447
-2
lines changed

Cargo.lock

Lines changed: 62 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ members = [
1010
"file",
1111
"fs",
1212
"ftw",
13+
"make",
1314
"m4",
1415
"m4/test-manager",
1516
"gettext-rs",

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ Because it is a FAQ, the major differences between this project and uutils are:
8484
- [x] join
8585
- [x] link
8686
- [x] ls
87+
- [x] make
8788
- [x] m4
8889
- [x] mkdir
8990
- [x] mv
@@ -212,7 +213,6 @@ Because it is a FAQ, the major differences between this project and uutils are:
212213
### Misc. category
213214
- [ ] lp
214215
- [ ] mailx
215-
- [ ] make (status: in progress)
216216
- [ ] man (status: in progress)
217217
- [ ] more
218218
- [ ] patch (status: in progress)

TODO.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@
1818

1919
## Other items
2020

21-
The `find` test `find_mtime_test` is hardcoded to use a specific
21+
**find**: The `find` test `find_mtime_test` is hardcoded to use a specific
2222
date offset. This was increased to 7000 days to temporarily avoid
2323
test failure. The test should be improved.
2424

25+
**make**: posixutils' standard is to _not_ use the src/ directory that
26+
is standard for Rust binaries. Update `make` to remove the src/
27+
directory by moving files within the repo.
28+

make/Cargo.toml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[package]
2+
name = "posixutils-make"
3+
version = "0.1.0"
4+
edition = "2021"
5+
authors = ["Jeff Garzik"]
6+
license = "MIT"
7+
repository = "https://github.com/rustcoreutils/posixutils-rs.git"
8+
9+
[dependencies]
10+
plib = { path = "../plib" }
11+
clap.workspace = true
12+
libc.workspace = true
13+
gettext-rs.workspace = true
14+
const_format = "0.2"
15+
rowan = "0.15"
16+
17+
[[bin]]
18+
name = "make"
19+
path = "src/main.rs"

make/src/config.rs

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
//
2+
// Copyright (c) 2024 Hemi Labs, Inc.
3+
//
4+
// This file is part of the posixutils-rs project covered under
5+
// the MIT License. For the full license text, please see the LICENSE
6+
// file in the root directory of this project.
7+
// SPDX-License-Identifier: MIT
8+
//
9+
10+
use std::collections::{BTreeMap, BTreeSet};
11+
12+
/// Represents the configuration of the make utility
13+
#[derive(Debug, Clone, PartialEq, Eq)]
14+
pub struct Config {
15+
/// Whether to ignore the errors in the rule
16+
pub ignore: bool,
17+
/// Whether to execute commands or print to stdout
18+
pub dry_run: bool,
19+
/// Whether to print recipe lines
20+
pub silent: bool,
21+
/// Whether to touch targets on execution
22+
pub touch: bool,
23+
/// Whether to replace macros within makefiles with envs
24+
pub env_macros: bool,
25+
/// Whether to quit without build
26+
pub quit: bool,
27+
/// Whether to keep going build targets and write info about errors stderr
28+
pub keep_going: bool,
29+
/// Whether to terminate on error
30+
pub terminate: bool,
31+
/// Whether to clear default_rules
32+
pub clear: bool,
33+
/// Whether to print macro definitions and target descriptions.
34+
pub print: bool,
35+
/// Whether to not delete interrupted files on async events.
36+
pub precious: bool,
37+
38+
pub rules: BTreeMap<String, BTreeSet<String>>,
39+
}
40+
41+
impl Default for Config {
42+
fn default() -> Self {
43+
Self {
44+
ignore: false,
45+
dry_run: false,
46+
silent: false,
47+
touch: false,
48+
env_macros: false,
49+
keep_going: false,
50+
quit: false,
51+
clear: false,
52+
print: false,
53+
precious: false,
54+
terminate: true,
55+
rules: BTreeMap::from([
56+
(
57+
".SUFFIXES".to_string(),
58+
vec![
59+
".o", ".c", ".y", ".l", ".a", ".sh", ".c~", ".y~", ".l~", ".sh~",
60+
]
61+
.into_iter()
62+
.map(String::from)
63+
.collect(),
64+
),
65+
(
66+
".SCCS_GET".to_string(),
67+
BTreeSet::from([String::from("sccs $(SCCSFLAGS) get $(SCCSGETFLAGS) $@")]),
68+
),
69+
(
70+
".MACROS".to_string(),
71+
vec![
72+
"AR=ar",
73+
"ARFLAGS=-rv",
74+
"YACC=yacc",
75+
"YFLAGS=",
76+
"LEX=lex",
77+
"LFLAGS=",
78+
"LDFLAGS=",
79+
"CC=c17",
80+
"CFLAGS=-O 1",
81+
"XSI GET=get",
82+
"GFLAGS=",
83+
"SCCSFLAGS=",
84+
"SCCSGETFLAGS=-s",
85+
]
86+
.into_iter()
87+
.map(String::from)
88+
.collect(),
89+
),
90+
(
91+
"SUFFIX RULES".to_string(),
92+
[
93+
// Single-Suffix Rules
94+
".c: $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $<",
95+
".sh: cp $< $@",
96+
".sh: chmod a+x $@",
97+
98+
// Double-Suffix Rules
99+
".c.o: $(CC) $(CFLAGS) -c $<",
100+
".y.o: $(YACC) $(YFLAGS) $<; $(CC) $(CFLAGS) -c y.tab.c; rm -f y.tab.c; mv y.tab.o $@",
101+
".l.o: $(LEX) $(LFLAGS) $<; $(CC) $(CFLAGS) -c lex.yy.c; rm -f lex.yy.c; mv lex.yy.o $@",
102+
".y.c: $(YACC) $(YFLAGS) $<; mv y.tab.c $@",
103+
".l.c: $(LEX) $(LFLAGS) $<; mv lex.yy.c $@",
104+
"XSI .c~.o: $(GET) $(GFLAGS) -p $< > $*.c; $(CC) $(CFLAGS) -c $*.c",
105+
".y~.o: $(GET) $(GFLAGS) -p $< > $*.y; $(YACC) $(YFLAGS) $*.y; $(CC) $(CFLAGS) -c y.tab.c; rm -f y.tab.c; mv y.tab.o $@",
106+
".l~.o: $(GET) $(GFLAGS) -p $< > $*.l; $(LEX) $(LFLAGS) $*.l; $(CC) $(CFLAGS) -c lex.yy.c; rm -f lex.yy.c; mv lex.yy.o $@",
107+
".y~.c: $(GET) $(GFLAGS) -p $< > $*.y; $(YACC) $(YFLAGS) $*.y; mv y.tab.c $@",
108+
".l~.c: $(GET) $(GFLAGS) -p $< > $*.l; $(LEX) $(LFLAGS) $*.l; mv lex.yy.c $@",
109+
".c.a: $(CC) -c $(CFLAGS) $<; $(AR) $(ARFLAGS) $@ $*.o; rm -f $*.o",
110+
]
111+
.into_iter()
112+
.map(String::from)
113+
.collect::<BTreeSet<String>>(),
114+
)
115+
]),
116+
}
117+
}
118+
}
119+
120+
impl Config {
121+
/// Adds a new suffix to the `.SUFFIXES` rule.
122+
pub fn add_suffix(&mut self, new_suffix: &str) {
123+
self.rules
124+
.entry(".SUFFIXES".to_string())
125+
.or_default()
126+
.insert(new_suffix.to_string());
127+
}
128+
}

0 commit comments

Comments
 (0)