Merge pull request #1 from neunenak/master
[arcanos.git] / GNUmakefile
1 #
2 # This makefile system follows the structuring conventions
3 # recommended by Peter Miller in his excellent paper:
4 #
5 #       Recursive Make Considered Harmful
6 #       http://aegis.sourceforge.net/auug97.pdf
7 #
8 OBJDIR := obj
9
10 TOP = .
11
12 # try to infer the correct GCCPREFIX
13 ifndef GCCPREFIX
14 GCCPREFIX := $(shell if objdump -i 2>&1 | grep 'elf32-i386' >/dev/null 2>&1; \
15         then echo ''; \
16         else echo "***" 1>&2; \
17         echo "*** Error: Couldn't find an i386-*-elf version of GCC/binutils." 1>&2; \
18         echo "*** Is the directory with i386-*-elf-gcc in your PATH?" 1>&2; \
19         echo "***" 1>&2; exit 1; fi)
20 endif
21
22 CC      := $(GCCPREFIX)gcc -pipe
23 GCC_LIB := $(shell $(CC) -print-libgcc-file-name)
24 AS      := $(GCCPREFIX)as
25 AR      := $(GCCPREFIX)ar
26 LD      := $(GCCPREFIX)ld
27 OBJCOPY := $(GCCPREFIX)objcopy
28 OBJDUMP := $(GCCPREFIX)objdump
29 NM      := $(GCCPREFIX)nm
30
31 # Native commands
32 NCC     := gcc $(CC_VER) -pipe
33 TAR     := gtar
34
35 # Compiler flags
36 # -fno-builtin is required to avoid refs to undefined functions in the kernel.
37 # Only optimize to -O1 to discourage inlining, which complicates backtraces.
38 CFLAGS  := $(CFLAGS) $(DEFS) $(LABDEFS) -O -fno-builtin -I$(TOP) -MD -Wall -Wno-format -Wno-unused -Werror -gstabs -fno-stack-protector -std=gnu99 -m32 -nostdlib
39
40 # Lists that the */Makefrag makefile fragments will add to
41 OBJDIRS :=
42
43 # Make sure that 'all' is the first target
44 all:
45
46 # Eliminate default suffix rules
47 .SUFFIXES:
48
49 # Delete target files if there is an error (or make is interrupted)
50 .DELETE_ON_ERROR:
51
52 # make it so that no intermediate .o files are ever deleted
53 .PRECIOUS: %.o $(OBJDIR)/boot/%.o $(OBJDIR)/kern/%.o \
54         $(OBJDIR)/lib/%.o $(OBJDIR)/fs/%.o $(OBJDIR)/user/%.o
55
56 KERN_CFLAGS := $(CFLAGS) -DARCANOS_KERNEL -gstabs
57 USER_CFLAGS := $(CFLAGS) -I usr/inc -DARCANOS_USER -gstabs
58
59 # Include Makefrags for subdirectories
60 include kern/Makefrag
61 include usr/lib/Makefrag
62 include usr/app/Makefrag
63
64 IMAGES = $(OBJDIR)/kern/bochs.img
65
66 # For deleting the build
67 clean:
68         rm -rf $(OBJDIR)
69
70 # Auto-copy to boot disk image
71 load: all
72         mkdir -p mnt
73         ./tools/copy_to_image.sh
74
75 EMULATOR=bochs
76 run: all
77         $(EMULATOR) -q
78
79 always:
80         @:
81
82 .PHONY: all always \
83         clean