From 6cd5f7028647a88935ec1f7776a08b51eb0fb1c8 Mon Sep 17 00:00:00 2001 From: illiliti Date: Wed, 1 Jun 2022 07:43:09 +0300 Subject: Makefile: POSIXify Makefile now compatible with gmake, bmake, smake and pdpmake. --- .gitignore | 3 ++- Makefile | 53 ++++++++++++++++++++++------------------------------- README | 10 ++++------ minic/mcc | 2 +- tools/abifuzz.sh | 2 +- tools/cra.sh | 2 +- tools/test.sh | 4 ++-- 7 files changed, 33 insertions(+), 43 deletions(-) diff --git a/.gitignore b/.gitignore index c466bca..afd08d7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ -obj +*.o +qbe config.h .comfile *.out diff --git a/Makefile b/Makefile index 3738a5f..090f5cb 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ -BIN = qbe +.POSIX: +.SUFFIXES: .o .c -V = @ -OBJDIR = obj -PREFIX ?= /usr/local +PREFIX = /usr/local +BINDIR = $(PREFIX)/bin SRC = main.c util.c parse.c cfg.c mem.c ssa.c alias.c load.c copy.c \ fold.c live.c spill.c rega.c gas.c @@ -11,33 +11,24 @@ ARM64SRC = arm64/targ.c arm64/abi.c arm64/isel.c arm64/emit.c RV64SRC = rv64/targ.c rv64/abi.c rv64/isel.c rv64/emit.c SRCALL = $(SRC) $(AMD64SRC) $(ARM64SRC) $(RV64SRC) -AMD64OBJ = $(AMD64SRC:%.c=$(OBJDIR)/%.o) -ARM64OBJ = $(ARM64SRC:%.c=$(OBJDIR)/%.o) -RV64OBJ = $(RV64SRC:%.c=$(OBJDIR)/%.o) -OBJ = $(SRC:%.c=$(OBJDIR)/%.o) $(AMD64OBJ) $(ARM64OBJ) $(RV64OBJ) +AMD64OBJ = $(AMD64SRC:.c=.o) +ARM64OBJ = $(ARM64SRC:.c=.o) +RV64OBJ = $(RV64SRC:.c=.o) +OBJ = $(SRC:.c=.o) $(AMD64OBJ) $(ARM64OBJ) $(RV64OBJ) -CFLAGS += -Wall -Wextra -std=c99 -g -pedantic +CFLAGS = $(CPPFLAGS) -Wall -Wextra -std=c99 -g -Wpedantic -$(OBJDIR)/$(BIN): $(OBJ) $(OBJDIR)/timestamp - @test -z "$(V)" || echo "ld $@" - $(V)$(CC) $(LDFLAGS) $(OBJ) -o $@ +qbe: $(OBJ) + $(CC) $(LDFLAGS) $(OBJ) -o $@ -$(OBJDIR)/%.o: %.c $(OBJDIR)/timestamp - @test -z "$(V)" || echo "cc $<" - $(V)$(CC) $(CFLAGS) -c $< -o $@ - -$(OBJDIR)/timestamp: - @mkdir -p $(OBJDIR) - @mkdir -p $(OBJDIR)/amd64 - @mkdir -p $(OBJDIR)/arm64 - @mkdir -p $(OBJDIR)/rv64 - @touch $@ +.c.o: + $(CC) $(CFLAGS) -c $< -o $@ $(OBJ): all.h ops.h $(AMD64OBJ): amd64/all.h $(ARM64OBJ): arm64/all.h $(RV64OBJ): rv64/all.h -$(OBJDIR)/main.o: config.h +main.o: config.h config.h: @case `uname` in \ @@ -61,26 +52,26 @@ config.h: ;; \ esac > $@ -install: $(OBJDIR)/$(BIN) - mkdir -p "$(DESTDIR)/$(PREFIX)/bin/" - cp $< "$(DESTDIR)/$(PREFIX)/bin/" +install: qbe + mkdir -p "$(DESTDIR)/$(BINDIR)" + cp qbe "$(DESTDIR)/$(BINDIR)/qbe" uninstall: - rm -f "$(DESTDIR)/$(PREFIX)/bin/$(BIN)" + rm -f "$(DESTDIR)/$(BINDIR)/qbe" clean: - rm -fr $(OBJDIR) + rm -f *.o */*.o qbe clean-gen: clean rm -f config.h -check: $(OBJDIR)/$(BIN) +check: qbe tools/test.sh all -check-arm64: $(OBJDIR)/$(BIN) +check-arm64: qbe TARGET=arm64 tools/test.sh all -check-rv64: $(OBJDIR)/$(BIN) +check-rv64: qbe TARGET=rv64 tools/test.sh all src: diff --git a/README b/README index bc8a65e..69d0aa9 100644 --- a/README +++ b/README @@ -12,9 +12,7 @@ The LICENSE file applies to all files distributed. - Compilation and Installation -Invoke GNU make in this directory to create the executable -file obj/qbe. On some systems (BSD) you might have to use -'gmake' instead of 'make'. Install using 'make install', -the standard DESTDIR and PREFIX environment variables are -supported. Alternatively, you may simply copy the obj/qbe -binary manually. +Invoke make in this directory to create the executable +file qbe. Install using 'make install', the standard +DESTDIR and PREFIX environment variables are supported. +Alternatively, you may simply copy the qbe binary manually. diff --git a/minic/mcc b/minic/mcc index 77d3d33..492947e 100755 --- a/minic/mcc +++ b/minic/mcc @@ -1,7 +1,7 @@ #!/bin/sh DIR=`cd $(dirname $0); pwd` -QBE=$DIR/../obj/qbe +QBE=$DIR/../qbe usage() { diff --git a/tools/abifuzz.sh b/tools/abifuzz.sh index e715b3d..add56eb 100755 --- a/tools/abifuzz.sh +++ b/tools/abifuzz.sh @@ -2,7 +2,7 @@ OCAMLC=${OCAMLC:-/usr/bin/ocamlc} DIR=`cd $(dirname "$0"); pwd` -QBE=$DIR/../obj/qbe +QBE=$DIR/../qbe failure() { echo "Failure at stage:" $1 >&2 diff --git a/tools/cra.sh b/tools/cra.sh index 762ab76..5988267 100755 --- a/tools/cra.sh +++ b/tools/cra.sh @@ -1,7 +1,7 @@ #!/bin/sh DIR=`cd $(dirname "$0"); pwd` -QBE=$DIR/../obj/qbe +QBE=$DIR/../qbe BUGF=/tmp/bug.id FIND=$1 FIND=${FIND:-afl-find} diff --git a/tools/test.sh b/tools/test.sh index 15cff88..536d240 100755 --- a/tools/test.sh +++ b/tools/test.sh @@ -1,8 +1,8 @@ #!/bin/sh dir=`cd $(dirname "$0"); pwd` -bin=$dir/../obj/qbe -binref=$dir/../obj/qbe.ref +bin=$dir/../qbe +binref=$dir/../qbe.ref tmp=/tmp/qbe.zzzz -- cgit 1.4.1