changing Makefile system a bit, again

git-svn-id: svn://anubis/hos/trunk@19 5b3e749e-e535-0410-8002-a9bb6afbdfca
This commit is contained in:
josh 2009-06-25 19:46:49 +00:00
parent 8fe8d78051
commit a5ca4348d9
2 changed files with 64 additions and 19 deletions

View File

@ -1,23 +1,31 @@
KERNEL := hos
LDFLAGS := -T link.ld
export PLATFORM := $(shell if [[ `uname` =~ "CYGWIN" ]]; then \
echo cygwin; \
else \
echo unix; \
fi)
ifeq ($(PLATFORM), cygwin)
export LD := i586-elf-ld
export CC := i586-elf-gcc
export CXX := i586-elf-g++
else
export LD := ld
export CC := gcc
export CXX := g++
endif
export NASM := nasm
ifeq ($(PLATFORM), cygwin)
export LD := i586-elf-ld
export CC := i586-elf-gcc
export CXX := i586-elf-g++
else
export LD := ld
export CC := gcc
export CXX := g++
endif
export NASM := nasm
WD := $(shell pwd)
LDSCRIPT := link.ld
KERNEL := hos
export CPPFLAGS := -I$(WD)/include
export CFLAGS := -Wall -O2
export CXXFLAGS := -Wall -O2
export LDFLAGS := -T $(LDSCRIPT)
SUBDIRS := boot
SUBDIRS_clean := $(subdirs:%=%.clean)
.PHONY: all
all: $(KERNEL).gz
@ -25,12 +33,16 @@ all: $(KERNEL).gz
$(KERNEL).gz: $(KERNEL)
gzip -c $< > $@
$(KERNEL): boot.o
$(LD) $(LDFLAGS) -o $@ $<
$(KERNEL): $(SUBDIRS)
$(LD) $(LDFLAGS) -o $@ $(SUBDIRS:%=%/%.o)
boot.o: boot.asm
$(NASM) -f elf -o $@ $<
.PHONY: $(SUBDIRS)
$(SUBDIRS):
$(MAKE) -C $@
.PHONY: clean
clean:
-rm -f *~ $(KERNEL) $(KERNEL).gz *.o
clean: $(SUBDIRS_clean)
-rm -f *~ $(KERNEL) $(KERNEL).gz
%.clean:
$(MAKE) -C $* clean clean=1

33
kernel/subdir.mak Normal file
View File

@ -0,0 +1,33 @@
ASMOBJS := $(patsubst %.asm,%.o,$(wildcard *.asm))
COBJS := $(patsubst %.c,%.o,$(wildcard *.c))
CXXOBJS := $(patsubst %.cc,%.o,$(wildcard *.cc))
CDEPS := $(COBJS:.o=.dep)
CXXDEPS := $(CXXOBJS:.o=.dep)
all: $(SUBDIR).o
$(SUBDIR).o: $(ASMOBJS) $(COBJS) $(CXXOBJS)
$(LD) -r -o $@ $^
%.o: %.asm
$(NASM) -f elf -o $@ $<
%.o: %.c
$(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $<
%.o: %.cc
$(CXX) -c -o $@ $(CPPFLAGS) $(CXXFLAGS) $<
# Make dependency files
%.dep: %.c
@set -e; rm -f $@; \
$(CC) -MM $(CPPFLAGS) $< | sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' > $@
clean:
-rm -f *.o *.dep *~
# Include dependency files
ifndef clean
-include $(DEPS)
endif