Skip to content

Make merge #364

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ members = [
"file",
"fs",
"ftw",
"make",
"m4",
"m4/test-manager",
"gettext-rs",
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ Because it is a FAQ, the major differences between this project and uutils are:
- [x] join
- [x] link
- [x] ls
- [x] make
- [x] m4
- [x] mkdir
- [x] mv
Expand Down Expand Up @@ -212,7 +213,6 @@ Because it is a FAQ, the major differences between this project and uutils are:
### Misc. category
- [ ] lp
- [ ] mailx
- [ ] make (status: in progress)
- [ ] man (status: in progress)
- [ ] more
- [ ] patch (status: in progress)
Expand Down
6 changes: 5 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@

## Other items

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

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

19 changes: 19 additions & 0 deletions make/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "posixutils-make"
version = "0.1.0"
edition = "2021"
authors = ["Jeff Garzik"]
license = "MIT"
repository = "https://github.com/rustcoreutils/posixutils-rs.git"

[dependencies]
plib = { path = "../plib" }
clap.workspace = true
libc.workspace = true
gettext-rs.workspace = true
const_format = "0.2"
rowan = "0.15"

[[bin]]
name = "make"
path = "src/main.rs"
128 changes: 128 additions & 0 deletions make/src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
//
// Copyright (c) 2024 Hemi Labs, Inc.
//
// This file is part of the posixutils-rs project covered under
// the MIT License. For the full license text, please see the LICENSE
// file in the root directory of this project.
// SPDX-License-Identifier: MIT
//

use std::collections::{BTreeMap, BTreeSet};

/// Represents the configuration of the make utility
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Config {
/// Whether to ignore the errors in the rule
pub ignore: bool,
/// Whether to execute commands or print to stdout
pub dry_run: bool,
/// Whether to print recipe lines
pub silent: bool,
/// Whether to touch targets on execution
pub touch: bool,
/// Whether to replace macros within makefiles with envs
pub env_macros: bool,
/// Whether to quit without build
pub quit: bool,
/// Whether to keep going build targets and write info about errors stderr
pub keep_going: bool,
/// Whether to terminate on error
pub terminate: bool,
/// Whether to clear default_rules
pub clear: bool,
/// Whether to print macro definitions and target descriptions.
pub print: bool,
/// Whether to not delete interrupted files on async events.
pub precious: bool,

pub rules: BTreeMap<String, BTreeSet<String>>,
}

impl Default for Config {
fn default() -> Self {
Self {
ignore: false,
dry_run: false,
silent: false,
touch: false,
env_macros: false,
keep_going: false,
quit: false,
clear: false,
print: false,
precious: false,
terminate: true,
rules: BTreeMap::from([
(
".SUFFIXES".to_string(),
vec![
".o", ".c", ".y", ".l", ".a", ".sh", ".c~", ".y~", ".l~", ".sh~",
]
.into_iter()
.map(String::from)
.collect(),
),
(
".SCCS_GET".to_string(),
BTreeSet::from([String::from("sccs $(SCCSFLAGS) get $(SCCSGETFLAGS) $@")]),
),
(
".MACROS".to_string(),
vec![
"AR=ar",
"ARFLAGS=-rv",
"YACC=yacc",
"YFLAGS=",
"LEX=lex",
"LFLAGS=",
"LDFLAGS=",
"CC=c17",
"CFLAGS=-O 1",
"XSI GET=get",
"GFLAGS=",
"SCCSFLAGS=",
"SCCSGETFLAGS=-s",
]
.into_iter()
.map(String::from)
.collect(),
),
(
"SUFFIX RULES".to_string(),
[
// Single-Suffix Rules
".c: $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $<",
".sh: cp $< $@",
".sh: chmod a+x $@",

// Double-Suffix Rules
".c.o: $(CC) $(CFLAGS) -c $<",
".y.o: $(YACC) $(YFLAGS) $<; $(CC) $(CFLAGS) -c y.tab.c; rm -f y.tab.c; mv y.tab.o $@",
".l.o: $(LEX) $(LFLAGS) $<; $(CC) $(CFLAGS) -c lex.yy.c; rm -f lex.yy.c; mv lex.yy.o $@",
".y.c: $(YACC) $(YFLAGS) $<; mv y.tab.c $@",
".l.c: $(LEX) $(LFLAGS) $<; mv lex.yy.c $@",
"XSI .c~.o: $(GET) $(GFLAGS) -p $< > $*.c; $(CC) $(CFLAGS) -c $*.c",
".y~.o: $(GET) $(GFLAGS) -p $< > $*.y; $(YACC) $(YFLAGS) $*.y; $(CC) $(CFLAGS) -c y.tab.c; rm -f y.tab.c; mv y.tab.o $@",
".l~.o: $(GET) $(GFLAGS) -p $< > $*.l; $(LEX) $(LFLAGS) $*.l; $(CC) $(CFLAGS) -c lex.yy.c; rm -f lex.yy.c; mv lex.yy.o $@",
".y~.c: $(GET) $(GFLAGS) -p $< > $*.y; $(YACC) $(YFLAGS) $*.y; mv y.tab.c $@",
".l~.c: $(GET) $(GFLAGS) -p $< > $*.l; $(LEX) $(LFLAGS) $*.l; mv lex.yy.c $@",
".c.a: $(CC) -c $(CFLAGS) $<; $(AR) $(ARFLAGS) $@ $*.o; rm -f $*.o",
]
.into_iter()
.map(String::from)
.collect::<BTreeSet<String>>(),
)
]),
}
}
}

impl Config {
/// Adds a new suffix to the `.SUFFIXES` rule.
pub fn add_suffix(&mut self, new_suffix: &str) {
self.rules
.entry(".SUFFIXES".to_string())
.or_default()
.insert(new_suffix.to_string());
}
}
Loading