minor changes in ne2k_pci and pci drivers
[quarnos.git] / Makefile
bloba04f7e55221f45ac7f7dfb53ceb27842028e5809
1 # Quarn OS
3 # Main Makefile
5 # Copyright (C) 2008 Pawel Dziepak
9 # make help describes all possible targets
12 MAKEFLAGS += --no-print-directory
14 MAJREL = 0
15 MINREL = 0
16 PROREL = 90
17 ADDONS = -dev
19 $(info Quarn OS $(MAJREL).$(MINREL).$(PROREL)$(ADDONS))
20 $(info Copyright (C) 2008 Pawel Dziepak)
21 $(info )
23 # Check host OS
24 $(info Checking host environment...)
25 $(if $(shell which gcc), , $(error GCC is needed to compile Quarn))
26 $(if $(shell which g++), , $(error G++ is needed to compile Quarn))
27 $(if $(shell which ld), , $(error LD is needed to compile Quarn))
28 $(if $(shell which sed), , $(error SED is needed to compile Quarn))
29 $(if $(shell which pwd), , $(error PWD is needed to compile Quarn))
30 $(if $(shell which perl), , $(error PERL is needed to compile Quarn))
32 PERL = perl
34 # Main tools
35 CC = gcc
36 CPP = g++
37 LD = ld
39 DIR = $(shell pwd)
40 DIR_SHORT = $(shell pwd | sed 's/\/.*\///')
42 CONFFILE = quarnconf.h
43 CONF = -include $(CONFFILE)
45 ifeq ($(shell $(PERL) scripts/mk_conf.pl OPT_SIZE), 0)
46 OPTIMIZE = -O2
47 POSTLD =
48 else
49 OPTIMIZE = -Os
50 POSTLD = strip quarn
51 endif
53 # Main flags
54 CFLAGS = -Wall -pedantic -std=c99 $(OPTIMIZE) -fno-builtin -nostartfiles -nostdlib -I$(DIR) $(CONF)
55 CPPFLAGS = -Wall -pedantic $(OPTIMIZE) --no-rtti --no-exceptions -fno-builtin -nostartfiles -nostdlib -I$(DIR) $(CONF)
56 LDFLAGS =
58 ARCH=x86
60 ifeq ($(shell $(PERL) scripts/mk_conf.pl USE_MULTIBOOT), 0)
61 MB =
62 else
63 MB = arch/$(ARCH)/loaders/systemload.o
64 endif
66 ifeq ($(shell $(PERL) scripts/mk_conf.pl DEBUG_MODE), 0)
67 MAP =
68 QFLAGS =
69 POSTQEMU =
70 else
71 $(if $(shell which sed), , $(error GDB is needed to debug Quarn))
72 MAP = -Map quarn.map
73 CFLAGS += -g
74 CPPFLAGS += -g
75 QFLAGS = -s -S &
76 POSTQEMU = gdb quarn
77 endif
79 # Directories that consist of code has to be compiled
80 DIRS = actors/ arch/low/ libs/ arch/low/loaders manes/ modules/ services/ resources/ hydra/
82 SUDO = sudo
84 LOOPDEV = $(shell $(SUDO) /sbin/losetup -f)
86 # Compile whole kernel
87 compile:
88 $(info Compiling Quarn OS...)
89 $(shell rm -f arch/low)
90 $(shell ln -s $(DIR)/arch/$(ARCH)/ arch/low)
91 @$(if $(wildcard $(CONFFILE)), , $(error You have to configure Quarn OS first.))
92 @for dir in $(DIRS); do \
93 (cd $$dir; $(MAKE) CC=$(CC) CPP=$(CPP) LD=$(LD) \
94 CFLAGS="$(CFLAGS)" CPPFLAGS="$(CPPFLAGS)" \
95 LDFLAGS=$(LDFAGS)); \
96 done
97 @echo -e "\t\t[$(LD)]\tquarn"
98 @$(LD) -Tscripts/x86_kernel.ld $(MB) `find . -name *.o | grep -v -E 'loaders|modules_start|rs232|test'` -o quarn $(MAP)
99 @$(POSTLD)
101 # Clean all and then compile
102 rebuild: clean compile
104 # Clean object files
105 clean:
106 $(shell rm -f arch/low)
107 $(shell ln -s $(DIR)/arch/$(ARCH)/ arch/low)
108 $(info Cleaning project directory...)
109 @for dir in $(DIRS); do \
110 (cd $$dir; $(MAKE) clean); \
111 done
112 @echo -e "\t\t[rm]\tquarn"
113 @rm -f quarn
114 @rm -f quarn.map
116 # Clean also built tools
117 allclean: clean
118 $(info Cleaning configuration files...)
119 @echo -e "\t\t[rm]\tscripts/nc_config"
120 @rm -f scripts/nc_config
121 @echo -e "\t\t[rm]\tquarnconf.h"
122 @rm -f quarnconf.h
123 @echo -e "\t\t[rm]\tfd.img"
124 @rm -f fd.img
125 @rm -f arch/low
127 # Compile configuration program (ncurses) and run it
128 config: scripts/nc_config
129 @echo -e "\t\t[sh]\tscripts/nc_config"
130 @scripts/nc_config
132 scripts/nc_config: scripts/nc_config.c
133 @echo -e "\t\t[$(CC)]\tscripts/nc_config.c"
134 @$(CC) scripts/nc_config.c -lmenu -lncurses -I/usr/include/ncurses -o scripts/nc_config
136 defconf: clean
137 $(info Restoring default configuration...)
138 @echo -e "\t\t[$(PERL)]\tscripts/text_config.pl"
139 @$(PERL) scripts/text_config.pl def
141 # Run configuration script (doesn't need ncurses)
142 textconf: clean
143 $(info Launching configuration tool...)
144 @echo -e "\t\t[$(PERL)]\tscripts/text_config.pl"
145 @$(PERL) scripts/text_config.pl $(MAJREL).$(MINREL).$(PROREL)$(ADDONS)
147 # Create bootable floppy image
148 fd_img: compile
149 $(info Creating floppy image...)
150 @/sbin/mkdosfs -F 12 -C fd.img 1440
151 @$(SUDO) /sbin/losetup $(LOOPDEV) fd.img
152 @$(SUDO) dd if=arch/low/loaders/boot of=$(LOOPDEV)
153 @mkdir image
154 @$(SUDO) mount $(LOOPDEV) image
155 @-$(SUDO) cp arch/low/loaders/loader image/
156 @$(SUDO) cp quarn image/
157 @$(SUDO) cp AUTHORS image/
158 #@$(SUDO) cp modules/*.ko image/
159 #@$(SUDO) cp hydra/*.ko image/
160 @$(SUDO) umount $(LOOPDEV)
161 @rmdir image
162 @$(SUDO) /sbin/losetup -d $(LOOPDEV)
164 qemu: fd_img
165 @qemu -fda fd.img -usb -net nic,model=ne2k_pci -net user
167 debug: fd_img
168 @qemu -fda fd.img -usb -net nic,model=ne2k_pci -net user $(QFLAGS)
169 @$(POSTQEMU)
171 # Put bootable image on the floppy
172 floppy: fd_img
173 $(info Putting image on a floppy...)
174 @$(SUDO) dd if=fd.img of=/dev/fd0
176 #Create build package
177 build: fd_img
178 $(if $(shell which tar), , $(error TAR is needed to compile Quarn))
179 $(if $(shell which gzip), , $(error GZIP is needed to compile Quarn))
180 $(info Creating build package...)
181 @-rm -f ../quarnos_`date +%Y-%m-%d`.tar
182 @tar -cf ../quarnos_`date +%Y-%m-%d`.tar ../$(DIR_SHORT)
183 @tar --delete -f ../quarnos_`date +%Y-%m-%d`.tar $(DIR_SHORT)/.git
184 @gzip -f ../quarnos_`date +%Y-%m-%d`.tar
186 pack: allclean
187 $(if $(shell which tar), , $(error TAR is needed to compile Quarn))
188 $(if $(shell which gzip), , $(error GZIP is needed to compile Quarn))
189 $(info Creating release package...)
190 @-rm -f ../quarnos_$(MAJREL).$(MINREL).$(PROREL)$(ADDONS).tar
191 @tar -cf ../quarnos_$(MAJREL).$(MINREL).$(PROREL)$(ADDONS).tar ../$(DIR_SHORT)
192 @tar --delete -f ../quarnos_$(MAJREL).$(MINREL).$(PROREL)$(ADDONS).tar $(DIR_SHORT)/.git
193 @gzip -f ../quarnos_$(MAJREL).$(MINREL).$(PROREL)$(ADDONS).tar
195 # Show possible targets
196 help:
197 @echo -e "\t\tQuarn OS $(MAJREL).$(MINREL).$(PROREL) Makefile"
198 @echo -e "\t\t-----------------------"
199 @echo -e "\nConfiguration:"
200 @echo -e "\tconfig\t\t- ncurses configuration tool (WIP)"
201 @echo -e "\tdefconf\t\t- uses default configuration"
202 @echo -e "\ttextconf\t- text configuration tool"
203 @echo -e "\nCompiling:"
204 @echo -e "\tcompile\t\t- compile whole kernel (default)"
205 @echo -e "\trebuild\t\t- allclean + compile"
206 @echo -e "\nInstallation:"
207 @echo -e "\tfd_img\t\t- create floppy image (requires root)"
208 @echo -e "\tfloppy\t\t- fd_img + put image on the floppy (requires root)"
209 @echo -e "\nPackaging:"
210 @echo -e "\tbuild\t\t- create build package in the upper directory"
211 @echo -e "\tpack\t\t- create release package in upper directory"
212 @echo -e "\nCleaning:"
213 @echo -e "\tallclean\t- clean + remove configuration files"
214 @echo -e "\tclean\t\t- remove all files generated by target compile"
215 @echo ""