summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlejandro Colomar <alx.manpages@gmail.com>2022-08-30 15:59:11 +0200
committerAlejandro Colomar <alx.manpages@gmail.com>2022-08-30 15:59:11 +0200
commit05db62dff9effe6c2bec75734819fdf34c2616be (patch)
tree27fc87df9a9018abefdecdb2e68c7184d7abf3d6
parent66652c9984aefa6a1d8008f9fb225b82e018d5c5 (diff)
Makefile: Add file
Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com>
-rw-r--r--Makefile71
1 files changed, 71 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..e6e24d0
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,71 @@
+MAKEFLAGS += --no-builtin-rules
+MAKEFLAGS += --no-builtin-variables
+MAKEFLAGS += --no-print-directory
+MAKEFLAGS += --warn-undefined-variables
+
+
+srcdir := .
+builddir := tmp
+
+
+LIBNXT_CFLAGS := -isystem/opt/local/unit/include
+LIBNXT_LIBS := -L/opt/local/unit/lib -lunit
+
+CFLAGS := -Wall -Wextra -Werror -std=gnu2x -O3 $(LIBNXT_CFLAGS)
+ASFLAGS :=
+LDFLAGS :=
+LIBS := $(LIBNXT_LIBS) -lpthread -lc -lgcc
+
+AR := ar
+AS := as
+CC := cc
+LD := $(CC) $(CFLAGS)
+
+
+FIND := find
+GREP := grep
+MKDIR := mkdir
+SED := sed
+SORT := sort
+
+
+SRCDIR := $(srcdir)/src
+SRC := $(shell $(FIND) $(SRCDIR) -type f | $(GREP) '\.c$$' | $(SORT))
+ASM := $(patsubst $(srcdir)/%.c,$(builddir)/%.s,$(SRC))
+OBJ := $(patsubst %.s,%.o,$(ASM))
+BIN := $(builddir)/unit_c_app
+
+SRCDIRS := $(shell $(FIND) $(SRCDIR) -type d | $(SED) 's,$$,/,')
+BUILDDIRS := $(patsubst $(srcdir)/%, $(builddir)/%, $(SRCDIRS))
+
+
+.PHONY: all
+all: $(BIN)
+
+
+.SECONDEXPANSION:
+
+
+$(ASM): $(builddir)/%.s: $(srcdir)/%.c Makefile | $$(@D)/
+ $(info CC $@)
+ $(CC) -S $(CFLAGS) -o $@ $<
+
+$(OBJ): %.o: %.s Makefile | $$(@D)/
+ $(info AS $@)
+ $(AS) $(ASFLAGS) -o $@ $<
+
+$(BIN): $(OBJ) Makefile | $$(@D)/
+ $(info LD $@)
+ $(LD) $(LDFLAGS) -o $@ $(OBJ) $(LIBS)
+
+$(BUILDDIRS): %/: | $$(dir %)
+ $(info MKDIR $@)
+ $(MKDIR) $@
+
+$(builddir)/:
+ $(info MKDIR $@)
+ $(MKDIR) $@
+
+
+
+$(V).SILENT: