commit d6f33dfcbdda067c5d2bdc3f3c35a93a905c3e70
parent ae09cb99cc6d9c19ae78849c43c50b834edccb8d
Author: afify <hassan@afify.dev>
Date: Mon, 21 Mar 2022 13:57:56 +0300
[ref] portable Makefile
Diffstat:
M | Makefile | | | 26 | ++++++++++++++------------ |
1 file changed, 14 insertions(+), 12 deletions(-)
diff --git a/Makefile b/Makefile
@@ -1,9 +1,11 @@
# See LICENSE file for copyright and license details.
+.PHONY: all options clean
+.SUFFIXES: .hex .o
-SRC = execve.s hi.s abc.s
-BIN = ${SRC:%.s=%}
-OBJ = ${SRC:%.s=%.o}
-HEX = ${SRC:%.s=%.hex}
+BIN = execve hi abc
+SRC = ${BIN:=.s}
+OBJ = ${BIN:=.o}
+HEX = ${BIN:=.hex}
ASM = nasm
LNK = ld
@@ -21,14 +23,15 @@ options:
@echo "ASM = ${ASM}"
@echo "LNK = ${LNK}"
-${OBJ}: %.o: %.s
- ${ASM} ${AFLAGS} -o $@ $<
+${BIN}: ${OBJ}
+ ${LNK} ${LFLAGS} -o $@ $@.o
-${BIN}: %: %.o
- ${LNK} ${LFLAGS} -o $@ $<
+.s.o:
+ ${ASM} ${AFLAGS} -o $@ $<
-${HEX}: %.hex: %
- objdump -d $< | grep '[0-9a-f]:'|\
+.o.hex:
+ @echo "objdump -d $< -o $@"
+ @objdump -d $< | grep '[0-9a-f]:'|\
grep -v 'file'| cut -f2 |\
sed 's/^/\\x/g'|\
sed "s/ *$$//g" |\
@@ -37,6 +40,7 @@ ${HEX}: %.hex: %
fold -w 32 |\
sed 's/^/"/'|\
sed 's/$$/"/'> $@
+ @echo ";" >> $@
loader:
${CC} ${CFLAGS} $@.c -o $@
@@ -52,5 +56,3 @@ tiny:
clean:
rm -rf *.o *.hex ${BIN} loader
-
-.PHONY: all options clean