Code: Select all
include include.mk
export BASEDIR=$(realpath .)
KNAME=extrn
LIBS=
MODS=mm
.PHONY: all
all : build
# Called by Code::Blocks
.PHONY : Debug
Debug : all
.PHONY: build
build : $(BINDIR)/$(KNAME)
.PHONY: $(BINDIR)/$(KNAME) $(foreach MOD,$(MODS),$(OBJDIR)/$(MOD).o) $(foreach LIB,$(LIBS),$(OBJDIR)/$(LIB).a)
$(BINDIR)/$(KNAME) : $(foreach MOD,$(MODS),$(OBJDIR)/$(MOD).o) $(foreach LIB,$(LIBS),$(OBJDIR)/$(LIB).a)
ld -melf_i386 -nostdlib --oformat elf32-i386 -o $@ $+
$(OBJDIR)/%.o :
cd $(SRCDIR)/$(basename $(@F));make;
# TODO
.PHONY: clean
clean:
Code: Select all
# Path related variables
BINDIR=$(BASEDIR)/bin
INCDIR=$(BASEDIR)/inc
OBJDIR=$(BASEDIR)/obj
SRCDIR=$(BASEDIR)/src
# Toolchain related variables
ASM=fasm
ASMFLAGS=-m 262144 -p 10000
CC=gcc
CFLAGS=-std=c99 -c -ffreestanding $(foreach DIR,$(INCDIR),-I$(DIR)) -m32 -masm=intel -nostdinc -Wall
C++FLAGS=-c -ffreestanding -I $(INCDIR) -m32 -masm=intel -nostdinc -Wall
LDFLAGS=-melf_i386 -nostdlib --oformat elf32-i386 --warn-unresolved-symbols
#MAKEFLAGS += -rR --no-print-directory
.SUFFIXES:.asm .c .o
.asm.o :
$(info ==== .asm($<) -> .o($@) rule)
@$(ASM) $(ASMFLAGS) $< $@
.c.o :
$(info ==== .c($<) -> .o($@) rule)
@$(CC) $(CFLAGS) $< -o $@
.o:
$(info ==== .o($+) rule)
@ld $(LDFLAGS) $+ -o $@
.o.o :
$(info ==== .o($+) -> .o($@) rule)
@ld $(LDFLAGS) -r $+ -o $@