# Toplevel makefile for Minirighi
#
# Copyright (C) 2004 Andrea Righi <righiandr@users.sf.net>
.EXPORT_ALL_VARIABLES:
export MAKE
# Kernel name #
KERNELNAME = minirighi32 (ia-32)
# Kenrel version #
MAINVERSION = 0
SUBVERSION = 12
SUBLEVEL = 2
VERSION = $(MAINVERSION).$(SUBVERSION).$(SUBLEVEL)
# Directories #
TOPDIR = $(shell /bin/pwd)
APPS = $(TOPDIR)/apps
APPSBIN = $(TOPDIR)/apps/bin
BIN = $(TOPDIR)/bin
DOC = $(TOPDIR)/doc
INCLUDE = $(TOPDIR)/include
LIB = $(TOPDIR)/lib
KERNEL = $(TOPDIR)/os
SCRIPTS = $(TOPDIR)/scripts
# Files #
CONFIG = $(TOPDIR)/.config
CONFIGH = $(INCLUDE)/kernel/config.h
TARGET = $(TOPDIR)/bin/mr32.elf
ASMDUMP = $(TOPDIR)/bin/mr32.dis
GZTARGET = $(TOPDIR)/bin/mr32.gz
MAP = $(TOPDIR)/bin/mr32.map
MTOOLSRC = $(TOPDIR)/.mtoolsrc
FDIMAGE = $(BIN)/minirighi-floppy.img
CDIMAGE = $(BIN)/minirighi-cdrom.iso
ifeq ($(TOPDIR)/.config,$(wildcard $(TOPDIR)/.config))
include $(TOPDIR)/.config
endif
# this is needed to speed-up the build process.
NCPUS := $(shell egrep -c '^processor' /proc/cpuinfo)
# Options #
LDFLAGS = -melf_i386 -g -nostdlib -X -L$(LIB) -lc
CFLAGS = -fno-stack-protector -m32 -mtune=i386 -Wall -pipe \
-I$(INCLUDE) \
-O3 \
-fomit-frame-pointer -mpreferred-stack-boundary=2 \
-nostdinc -fno-builtin
ifeq ($(CONFIG_DEBUG),y)
CFLAGS += -g
else
LDFLAGS += -S
endif
ifdef CONFIG_M386
CFLAGS += -march=i386
endif
ifdef CONFIG_M486
CFLAGS += -march=i486
endif
ifdef CONFIG_M586
CFLAGS += -march=i586
endif
ifdef CONFIG_M586TSC
CFLAGS += -march=i586
endif
ifdef CONFIG_M586MMX
CFLAGS += -march=i586 -march=pentium-mmx
endif
ifdef CONFIG_M686
CFLAGS += -march=i686
endif
ifdef CONFIG_MPENTIUMII
CFLAGS += -march=i686 -march=pentium2
endif
ifdef CONFIG_MPENTIUMIII
CFLAGS += -march=i686 -march=pentium3
endif
ifdef CONFIG_MPENTIUM4
CFLAGS += -march=i686 -march=pentium4
endif
ifdef CONFIG_MK6
CFLAGS += $(shell if $(CC) -march=k6 -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-march=k6"; else echo "-march=i586"; fi)
endif
ifdef CONFIG_MK7
CFLAGS += $(shell if $(CC) -march=athlon -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-march=athlon"; else echo "-march=i686 -malign-functions=4"; fi)
endif
ifdef CONFIG_MATHLONXP
CFLAGS += $(shell if $(CC) -march=athlon-xp -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-march=athlon-xp"; else echo "-march=i686 -malign-functions=4"; fi)
endif
ifdef CONFIG_MK8
CFLAGS += $(shell if $(CC) -march=k8 -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-march=k8"; else echo "-march=i686 -malign-functions=4"; fi)
endif
# Programs #
MAKE = make -s
AS = gcc
CC = gcc
LD = ld
OBJDUMP = objdump -D -l -x -t
NASM = nasm -f elf
GRUB = /usr/sbin/grub
#########################################################################
# #
# Rules for kernel, library & applications. #
# #
#########################################################################
all: kernel
@/bin/echo -e "Well done."
@/bin/echo -e "Don't forget to run \"make install\" to copy the kernel on the floppy image."
@echo
world:
@/bin/echo -e "\n--- Configuration ---\n"
$(MAKE) config
@/bin/echo -e "\n--- Make dependencies ---\n"
$(MAKE) dep
@/bin/echo -e "\n--- Cleaning ---\n"
$(MAKE) clean
@/bin/echo -e "\n--- Making the kernel ---\n"
$(MAKE) -j$(NCPUS) all
@/bin/echo -e "\n--- Installing the kernel to floppy image ---\n"
$(MAKE) install
@/bin/echo -e "\n--- Making applications ---\n"
$(MAKE) -j$(NCPUS) apps
@/bin/echo -e "\n--- Installing applications to floppy image ---\n"
$(MAKE) apps_install
@/bin/echo -e "\nWorld done... enjoy!\n"
kernel: .config .depend lib
@echo Making kernel...
@$(MAKE) -C $(KERNEL)
install: .config .depend kernel $(FDIMAGE)
@echo "Copying kernel to floppy image $(FDIMAGE)"
@mcopy -n $(GZTARGET) a:/kernel/
@sync
@echo "done."
lib:
@echo Making library...
@$(MAKE) -C $(LIB)
apps: .config lib $(FDIMAGE)
@echo Making applications...
@$(MAKE) -C $(APPS) all
@echo "done."
apps_install:
@echo -n "Copying applications to floppy image $(FDIMAGE)... "
@mcopy -n $(APPSBIN)/* a:/bin/
@sync
@echo "done."
apps_clean:
@$(MAKE) -C $(APPS) clean
clean: apps_clean
@$(MAKE) -C $(KERNEL) clean
@$(MAKE) -C $(LIB) clean
@find . -name *~ -print | xargs rm -f
config:
@$(SCRIPTS)/config.sh
@/bin/echo -e "Configuration done."
@/bin/echo -e "Now it's time to run \"make dep\" to find all dependencies.\n"
depend dep: .config
@rm -f .depend
@echo -n "Finding dependencies for all C files... "
@$(foreach i, $(shell find ${TOPDIR} -name \*.c -print), \
echo -n $(dir $i) >> .depend; $(CC) -I$(INCLUDE) -M $i >> .depend;)
@echo "done."
@/bin/echo -e "Now it's time to run \"make\" to compile the kernel.\n"
.depend:
@/bin/echo -e "\nYou have to run \"make dep\" before!!!\n"
@exit 1
.config:
@/bin/echo -e "\nYou have to run \"make config\" before!!!\n"
@exit 1
#########################################################################
# #
# Rules for the installation device images. #
# #
#########################################################################
$(FDIMAGE):
@$(SCRIPTS)/mkfdimg.sh
isocd: install $(FDIMAGE)
@mkdir cd_root
@cp $(FDIMAGE) cd_root/`basename $(FDIMAGE)`
@mkisofs -o $(CDIMAGE) -b `basename $(FDIMAGE)` -R -J cd_root
@rm -rf cd_root
@/bin/echo -e "\nISO bootable cd image created $(CDIMAGE)\n"
disk: install
dd bs=8192 if=$(FDIMAGE) of=/dev/fd0
#########################################################################
# #
# Rules for backup, documentation, etc... #
# #
#########################################################################
distclean: clean
@$(MAKE) -C $(KERNEL) distclean
@$(MAKE) -C $(DOC) clean
@find $(TOPDIR) -type f -name \*.o -exec rm -f {} \;
@rm -f $(CDIMAGE) $(FDIMAGE) $(MTOOLSRC) $(CONFIG) $(CONFIGH) .depend tags
@echo Clean done.
backup: distclean
cd .. && tar cf - `basename $(TOPDIR)`/ | bzip2 -c -9 > minirighi32-$(VERSION).tar.bz2
sync
@/bin/echo -e "Backup done.\n"
documentation doc:
@$(MAKE) -C $(DOC) all
@echo
@/bin/echo -e "Documentation done in $(DOC).\n"
tags:
find . -name '*.[chS]' | xargs ctags -a
wc:
find . -type f -name *.[Sch] -print | sort | xargs wc -l
.PHONY: config depend dep kernel all lib install apps disk isocd clean \
distclean backup doc documentation wc world
include Rules.make