From b223cc1a4247bcc5ebb21d6015a033ed8283f830 Mon Sep 17 00:00:00 2001 From: AceVest Date: Wed, 16 Apr 2014 22:55:13 +0800 Subject: [PATCH] modify makefile --- Makefile | 68 ++++++++++++++++++++---------------------------- bin/Makefile | 22 ++++++++-------- boot/Makefile | 23 ---------------- drivers/Makefile | 23 ---------------- fs/Makefile | 23 ---------------- kernel.mk | 1 - kernel/Makefile | 23 ---------------- lib/Makefile | 23 ---------------- mm/Makefile | 23 ---------------- pci/Makefile | 23 ---------------- setup/Makefile | 23 ---------------- 11 files changed, 39 insertions(+), 236 deletions(-) delete mode 100644 boot/Makefile delete mode 100644 drivers/Makefile delete mode 100644 fs/Makefile delete mode 100644 kernel.mk delete mode 100644 kernel/Makefile delete mode 100644 lib/Makefile delete mode 100644 mm/Makefile delete mode 100644 pci/Makefile delete mode 100644 setup/Makefile diff --git a/Makefile b/Makefile index 266ccb7..37ce15e 100644 --- a/Makefile +++ b/Makefile @@ -1,52 +1,40 @@ ############################################################################ -CF = -c -I include -fno-builtin -CC = $(_CC) $(CF) -o +CC = gcc +CFLAGS = -c -fno-builtin SYSTEMMAP = System.map KERNELBIN = KERNEL.BIN LINKSCRIPT = scripts/link.ld -OBJS = boot/multiboot.S.o boot/boot.o boot/reboot.S.o boot/cmdline.o\ - setup/*.o mm/*.o kernel/*.o fs/*.o pci/*.o lib/*.o \ - drivers/*.o -#BINS####################################################################### -$(KERNELBIN): - cd boot && make - cd setup && make - cd mm && make - cd kernel && make - cd fs && make - cd pci && make - cd lib && make - cd drivers && make - ld -M -T$(LINKSCRIPT) -o $@ $(OBJS) > $(SYSTEMMAP) - ld -T$(LINKSCRIPT) -o $@ $(OBJS) - cd bin && make - md5sum $(KERNELBIN) - #./scripts/grub2-debug.sh - #mv $@ KRNL.ELF -.PHONY:real -real: - -.PHONY:c +############################################################################ + +SRC_DIRS = boot setup mm lib fs kernel drivers pci +INC_DIRS = include drivers + +CSOURCE_FILES := $(foreach dir, $(SRC_DIRS), $(wildcard $(dir)/*.c)) +SSOURCE_FILES := $(foreach dir, $(SRC_DIRS), $(wildcard $(dir)/*.S)) + +OBJS := $(patsubst %.c,%.c.o,$(CSOURCE_FILES)) +OBJS += $(patsubst %.S,%.S.o,$(SSOURCE_FILES)) + +CFLAGS += ${INC_DIRS:%=-I%} + +${KERNELBIN}: ${OBJS} $ + ld -M -T$(LINKSCRIPT) $(OBJS) -o $@ > $(SYSTEMMAP) + +%.S.o: %.S + ${CC} ${CFLAGS} $< -o $@ + +%.c.o: %.c + ${CC} ${CFLAGS} $< -o $@ + c: rm -f $(KERNELBIN) -.PHONY:clean clean: - cd boot && make clean - cd setup && make clean - cd mm && make clean - cd kernel && make clean - cd fs && make clean - cd pci && make clean - cd lib && make clean - cd drivers && make clean - cd bin && make clean - rm -f $(KERNELBIN) System.map snapshot.txt log.txt - rm -f KRNL.ELF - -.PHONY:install + rm -f $(OBJS) + rm -f $(KERNELBIN) $(SYSTEMMAP) + install: cp KERNEL.BIN /boot/ -.PHONY:copy + copy: ./scripts/copy.sh diff --git a/bin/Makefile b/bin/Makefile index 12a8eee..66e2586 100644 --- a/bin/Makefile +++ b/bin/Makefile @@ -1,20 +1,20 @@ CC = gcc CFLAGS = -c -I../include -fno-builtin -LDOBJS = ../lib/errno.o ../lib/fork.o ../lib/lib.o ../lib/open.o \ - ../lib/stat.o ../lib/string.o ../lib/write.o ../lib/exec.o \ - ../lib/vsprintf.o ../lib/read.o \ - ../lib/keyboard.o ../lib/exit.o +LDOBJS = ../lib/errno.c.o ../lib/fork.c.o ../lib/lib.c.o ../lib/open.c.o \ + ../lib/stat.c.o ../lib/string.c.o ../lib/write.c.o ../lib/exec.c.o \ + ../lib/vsprintf.c.o ../lib/read.c.o \ + ../lib/keyboard.c.o ../lib/exit.c.o all: - gcc -c shell.S -o shell.S.o - gcc $(CFLAGS) shell.c -o shell.o - ld $(LDOBJS) shell.S.o shell.o -o sh - gcc -c helloworld.S -o helloworld.S.o - gcc $(CFLAGS) helloworld.c -o helloworld.o - ld $(LDOBJS) helloworld.S.o helloworld.o -o hw + gcc -c shell.S -o shell.S.c.o + gcc $(CFLAGS) shell.c -o shell.c.o + ld $(LDOBJS) shell.S.c.o shell.c.o -o sh + gcc -c helloworld.S -o helloworld.S.c.o + gcc $(CFLAGS) helloworld.c -o helloworld.c.o + ld $(LDOBJS) helloworld.S.c.o helloworld.c.o -o hw .PHONY:clean clean: - rm sh hw helloworld.o -f + rm sh hw helloworld.c.o -f .PHONY:c c: make clean diff --git a/boot/Makefile b/boot/Makefile deleted file mode 100644 index 10ffe92..0000000 --- a/boot/Makefile +++ /dev/null @@ -1,23 +0,0 @@ -include ../kernel.mk -CC = gcc -CFLAGS = $(CF) - -CSOUCE_FILES = $(wildcard *.c) -SSOUCE_FILES = $(wildcard *.S) -OBJS = $(patsubst %.c,%.o,$(CSOUCE_FILES)) -OBJS += $(patsubst %.S,%.S.o,$(SSOUCE_FILES)) - -%.o : %.c *.h ../include/*.h - $(CC) $(CFLAGS) $< -o $@ -%.S.o : %.S ../include/*.h - $(CC) $(CFLAGS) $< -o $@ - - -all:$(OBJS) - -.PHONY:clean -clean: - $(RM) $(OBJS) -.PHONY:c -c: - make clean diff --git a/drivers/Makefile b/drivers/Makefile deleted file mode 100644 index 23675f3..0000000 --- a/drivers/Makefile +++ /dev/null @@ -1,23 +0,0 @@ -include ../kernel.mk -CC = gcc -CFLAGS = $(CF) - -CSOUCE_FILES = $(wildcard *.c) -SSOUCE_FILES = $(wildcard *.S) -OBJS = $(patsubst %.c,%.o,$(CSOUCE_FILES)) -OBJS += $(patsubst %.S,%.S.o,$(SSOUCE_FILES)) - -%.o : %.c ../include/*.h ./*.h - $(CC) $(CFLAGS) $< -o $@ -%.S.o : %.S ../include/*.h ./*.h - $(CC) $(CFLAGS) $< -o $@ - - -all:$(OBJS) - -.PHONY:clean -clean: - $(RM) $(OBJS) -.PHONY:c -c: - make clean diff --git a/fs/Makefile b/fs/Makefile deleted file mode 100644 index 23675f3..0000000 --- a/fs/Makefile +++ /dev/null @@ -1,23 +0,0 @@ -include ../kernel.mk -CC = gcc -CFLAGS = $(CF) - -CSOUCE_FILES = $(wildcard *.c) -SSOUCE_FILES = $(wildcard *.S) -OBJS = $(patsubst %.c,%.o,$(CSOUCE_FILES)) -OBJS += $(patsubst %.S,%.S.o,$(SSOUCE_FILES)) - -%.o : %.c ../include/*.h ./*.h - $(CC) $(CFLAGS) $< -o $@ -%.S.o : %.S ../include/*.h ./*.h - $(CC) $(CFLAGS) $< -o $@ - - -all:$(OBJS) - -.PHONY:clean -clean: - $(RM) $(OBJS) -.PHONY:c -c: - make clean diff --git a/kernel.mk b/kernel.mk deleted file mode 100644 index e9ab7a4..0000000 --- a/kernel.mk +++ /dev/null @@ -1 +0,0 @@ -CF = -g -c -I. -Iinclude -I../include -fno-builtin diff --git a/kernel/Makefile b/kernel/Makefile deleted file mode 100644 index 2aaf358..0000000 --- a/kernel/Makefile +++ /dev/null @@ -1,23 +0,0 @@ -include ../kernel.mk -CC = gcc -CFLAGS = $(CF) - -CSOUCE_FILES = $(wildcard *.c) -SSOUCE_FILES = $(wildcard *.S) -OBJS = $(patsubst %.c,%.o,$(CSOUCE_FILES)) -OBJS += $(patsubst %.S,%.S.o,$(SSOUCE_FILES)) - -%.o : %.c ../include/*.h - $(CC) $(CFLAGS) $< -o $@ -%.S.o : %.S ../include/*.h - $(CC) $(CFLAGS) $< -o $@ - - -all:$(OBJS) - -.PHONY:clean -clean: - $(RM) $(OBJS) -.PHONY:c -c: - make clean diff --git a/lib/Makefile b/lib/Makefile deleted file mode 100644 index 2aaf358..0000000 --- a/lib/Makefile +++ /dev/null @@ -1,23 +0,0 @@ -include ../kernel.mk -CC = gcc -CFLAGS = $(CF) - -CSOUCE_FILES = $(wildcard *.c) -SSOUCE_FILES = $(wildcard *.S) -OBJS = $(patsubst %.c,%.o,$(CSOUCE_FILES)) -OBJS += $(patsubst %.S,%.S.o,$(SSOUCE_FILES)) - -%.o : %.c ../include/*.h - $(CC) $(CFLAGS) $< -o $@ -%.S.o : %.S ../include/*.h - $(CC) $(CFLAGS) $< -o $@ - - -all:$(OBJS) - -.PHONY:clean -clean: - $(RM) $(OBJS) -.PHONY:c -c: - make clean diff --git a/mm/Makefile b/mm/Makefile deleted file mode 100644 index 2aaf358..0000000 --- a/mm/Makefile +++ /dev/null @@ -1,23 +0,0 @@ -include ../kernel.mk -CC = gcc -CFLAGS = $(CF) - -CSOUCE_FILES = $(wildcard *.c) -SSOUCE_FILES = $(wildcard *.S) -OBJS = $(patsubst %.c,%.o,$(CSOUCE_FILES)) -OBJS += $(patsubst %.S,%.S.o,$(SSOUCE_FILES)) - -%.o : %.c ../include/*.h - $(CC) $(CFLAGS) $< -o $@ -%.S.o : %.S ../include/*.h - $(CC) $(CFLAGS) $< -o $@ - - -all:$(OBJS) - -.PHONY:clean -clean: - $(RM) $(OBJS) -.PHONY:c -c: - make clean diff --git a/pci/Makefile b/pci/Makefile deleted file mode 100644 index 2aaf358..0000000 --- a/pci/Makefile +++ /dev/null @@ -1,23 +0,0 @@ -include ../kernel.mk -CC = gcc -CFLAGS = $(CF) - -CSOUCE_FILES = $(wildcard *.c) -SSOUCE_FILES = $(wildcard *.S) -OBJS = $(patsubst %.c,%.o,$(CSOUCE_FILES)) -OBJS += $(patsubst %.S,%.S.o,$(SSOUCE_FILES)) - -%.o : %.c ../include/*.h - $(CC) $(CFLAGS) $< -o $@ -%.S.o : %.S ../include/*.h - $(CC) $(CFLAGS) $< -o $@ - - -all:$(OBJS) - -.PHONY:clean -clean: - $(RM) $(OBJS) -.PHONY:c -c: - make clean diff --git a/setup/Makefile b/setup/Makefile deleted file mode 100644 index 2aaf358..0000000 --- a/setup/Makefile +++ /dev/null @@ -1,23 +0,0 @@ -include ../kernel.mk -CC = gcc -CFLAGS = $(CF) - -CSOUCE_FILES = $(wildcard *.c) -SSOUCE_FILES = $(wildcard *.S) -OBJS = $(patsubst %.c,%.o,$(CSOUCE_FILES)) -OBJS += $(patsubst %.S,%.S.o,$(SSOUCE_FILES)) - -%.o : %.c ../include/*.h - $(CC) $(CFLAGS) $< -o $@ -%.S.o : %.S ../include/*.h - $(CC) $(CFLAGS) $< -o $@ - - -all:$(OBJS) - -.PHONY:clean -clean: - $(RM) $(OBJS) -.PHONY:c -c: - make clean -- 2.44.0