50 lines
1.1 KiB
Makefile
50 lines
1.1 KiB
Makefile
|
|
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)
|
|
OUTPUT_FILE := $(SUBDIR)_all.o
|
|
|
|
ifdef SUBDIRS
|
|
SUBDIRS_clean := $(SUBDIRS:%=%.clean)
|
|
endif
|
|
|
|
all: $(OUTPUT_FILE)
|
|
|
|
$(OUTPUT_FILE): $(ASMOBJS) $(COBJS) $(CXXOBJS) $(SUBDIRS)
|
|
$(LD) -r -o $@ $(ASMOBJS) $(COBJS) $(CXXOBJS) $(foreach subdir,$(SUBDIRS),$(subdir)/$(subdir)_all.o)
|
|
|
|
%.o: %.asm
|
|
$(NASM) -f elf -o $@ $<
|
|
|
|
%.o: %.c
|
|
$(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $<
|
|
|
|
%.o: %.cc
|
|
$(CXX) -c -o $@ $(CPPFLAGS) $(CXXFLAGS) $<
|
|
|
|
ifdef SUBDIRS
|
|
.PHONY: $(SUBDIRS)
|
|
$(SUBDIRS):
|
|
$(MAKE) -C $@ SUBDIR=$@
|
|
endif
|
|
|
|
# Make dependency files
|
|
%.dep: %.c
|
|
@set -e; rm -f $@; \
|
|
$(CC) -MM $(CPPFLAGS) $< | sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' > $@
|
|
|
|
clean: $(SUBDIRS_clean)
|
|
-rm -f *.o *.dep *~
|
|
|
|
ifdef SUBDIRS
|
|
%.clean:
|
|
$(MAKE) -C $* clean clean=1
|
|
endif
|
|
|
|
# Include dependency files
|
|
ifndef clean
|
|
-include $(DEPS)
|
|
endif
|