diff options
author | Mattias Andrée <maandree@kth.se> | 2023-07-01 09:26:44 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2023-07-01 09:26:44 +0200 |
commit | bd32947e35d5da5747a02f0744730cb16077ba39 (patch) | |
tree | bf9a9b81b4d50e29fc3dbc63261f1dc064b1ed13 | |
parent | Change PREFIX to /usr (diff) | |
download | optimised-true-bd32947e35d5da5747a02f0744730cb16077ba39.tar.gz optimised-true-bd32947e35d5da5747a02f0744730cb16077ba39.tar.bz2 optimised-true-bd32947e35d5da5747a02f0744730cb16077ba39.tar.xz |
Improve makefile
Signed-off-by: Mattias Andrée <maandree@kth.se>
-rw-r--r-- | Makefile | 94 | ||||
-rw-r--r-- | config.mk | 9 | ||||
-rw-r--r-- | generic/build.mk | 7 | ||||
-rw-r--r-- | x86_64/build.mk | 5 |
4 files changed, 73 insertions, 42 deletions
@@ -1,53 +1,63 @@ -PREFIX = /usr -EXEC_PREFIX = $(PREFIX) -BINDIR = $(EXEC_PREFIX)/bin -DATADIR = $(PREFIX)/share -LICENSEDIR = $(DATADIR)/licenses +.POSIX: -PKGNAME = optimised-true +MACHINE != uname -m +MACHINE !=\ + if test -d "$(MACHINE)"; then \ + printf '%s\n' "$(MACHINE)"; \ + else \ + printf '%s\n' "generic"; \ + fi -LD_FLAGS = -s -AS_FLAGS = -CC_FLAGS = -nostdinc -ffreestanding -MACHINE = $(shell uname -m) +CONFIGFILE = config.mk +include $(CONFIGFILE) -ifneq ($(shell test -d $(MACHINE) && echo 0 || echo 1),0) -GENERIC = 1 -LD = $(CC) -endif -ifndef GENERIC -LD_FLAGS += -nodefaultlibs -nostdlib -endif - - -all: true false +BIN = true false +all: $(BIN) true: true.o - $(LD) $(LD_FLAGS) -o $@ $^ false: false.o - $(LD) $(LD_FLAGS) -o $@ $^ - -ifdef GENERIC -%.o: generic/%.c - $(CC) $(CC_FLAGS) -c -o $@ $^ -endif -ifndef GENERIC -%.o: $(MACHINE)/%.s - $(AS) $(AS_FLAGS) -o $@ $^ -endif - -install: true false - mkdir -p -- "$(DESTDIR)$(BINDIR)" - cp true false -- "$(DESTDIR)$(BINDIR)" - chmod 755 -- "$(DESTDIR)$(BINDIR)/true" - chmod 755 -- "$(DESTDIR)$(BINDIR)/false" + +.SUFFIXES: +.SUFFIXES: .o + +include $(MACHINE)/build.mk + +check: $(BIN:=-check) + +true-check: true + ./true + ./true + ./true + ./true + ./true + ./true + ./true + ./true + ./true + ./true + +false-check: false + set +e; ./false; test $$? = 1 || exit 1 + set +e; ./false; test $$? = 1 || exit 1 + set +e; ./false; test $$? = 1 || exit 1 + set +e; ./false; test $$? = 1 || exit 1 + set +e; ./false; test $$? = 1 || exit 1 + set +e; ./false; test $$? = 1 || exit 1 + set +e; ./false; test $$? = 1 || exit 1 + set +e; ./false; test $$? = 1 || exit 1 + set +e; ./false; test $$? = 1 || exit 1 + set +e; ./false; test $$? = 1 || exit 1 + +install: $(BIN) + mkdir -p -- "$(DESTDIR)/$(PREFIX)/bin" + cp -- $(BIN) "$(DESTDIR)/$(PREFIX)/bin" + cd -- "$(DESTDIR)/$(PREFIX)/bin" && chmod -- 755 "$(BIN)" uninstall: - -rm -- "$(DESTDIR)$(BINDIR)/true" - -rm -- "$(DESTDIR)$(BINDIR)/false" - -rmdir -- "$(DESTDIR)$(BINDIR)" + -cd -- "$(DESTDIR)/$(PREFIX)/bin" && rm -f -- $(BIN) + -rmdir -- "$(DESTDIR)/$(PREFIX)/bin" clean: - -rm true.o true false.o false + -rm -f -- *.o *.su $(BIN) -.PHONY: all clean install uninstall +.PHONY: all check true-check false-check install uninstall clean diff --git a/config.mk b/config.mk new file mode 100644 index 0000000..f5d0b4e --- /dev/null +++ b/config.mk @@ -0,0 +1,9 @@ +PREFIX = /usr + +CC = c99 +LD = ld +AS = as + +CFLAGS = -nostdinc -ffreestanding +ASFLAGS = +LDFLAGS = -s diff --git a/generic/build.mk b/generic/build.mk new file mode 100644 index 0000000..0b2f531 --- /dev/null +++ b/generic/build.mk @@ -0,0 +1,7 @@ +CFLAGS = -nostdinc -ffreestanding +LDFLAGS = -s + +LD = $(CC) + +true.o false.o: $(MACHINE)/true.c $(MACHINE)/false.c + $(CC) -c -o $@ $(MACHINE)/$(@:.o=.c) $(CFLAGS) diff --git a/x86_64/build.mk b/x86_64/build.mk new file mode 100644 index 0000000..a3c8d8d --- /dev/null +++ b/x86_64/build.mk @@ -0,0 +1,5 @@ +ASFLAGS = +LDFLAGS = -s -nodefaultlibs -nostdlib + +true.o false.o: $(MACHINE)/true.s $(MACHINE)/false.s + $(AS) -o $@ $(MACHINE)/$(@:.o=.s) $(ASFLAGS) |