creator-level saving new files in fat
[quarnos.git] / Makefile
blob6ddeb62ffe483d356a32784bdd2e8571c5bf2fbe
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 $(OPTIMIZE) -fno-builtin -nostartfiles -nostdlib -I$(DIR) $(CONF)
55 CPPFLAGS = -Wall $(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 # Directories that consist of code has to be compiled
67 DIRS = actors/ arch/$(ARCH)/ libs/ arch/$(ARCH)/loaders manes/ modules/ services/ resources/ hydra/
69 SUDO = sudo
71 LOOPDEV = $(shell $(SUDO) /sbin/losetup -f)
73 # Compile whole kernel
74 compile:
75 $(info Compiling Quarn OS...)
76 @$(if $(wildcard $(CONFFILE)), , $(error You have to configure Quarn OS first.))
77 @for dir in $(DIRS); do \
78 (cd $$dir; $(MAKE) CC=$(CC) CPP=$(CPP) LD=$(LD) \
79 CFLAGS="$(CFLAGS)" CPPFLAGS="$(CPPFLAGS)" \
80 LDFLAGS=$(LDFAGS)); \
81 done
82 @echo -e "\t\t[$(LD)]\tquarn"
83 @$(LD) -Tscripts/x86_kernel.ld $(MB) `find . -name *.o | grep -v -E 'loaders|modules_start|rs232|test'` -o quarn
84 @$(POSTLD)
86 # Clean all and then compile
87 rebuild: clean compile
89 # Clean object files
90 clean:
91 $(info Cleaning project directory...)
92 @for dir in $(DIRS); do \
93 (cd $$dir; $(MAKE) clean); \
94 done
95 @echo -e "\t\t[rm]\tquarn"
96 @rm -f quarn
98 # Clean also built tools
99 allclean: clean
100 $(info Cleaning configuration files...)
101 @echo -e "\t\t[rm]\tscripts/nc_config"
102 @rm -f scripts/nc_config
103 @echo -e "\t\t[rm]\tquarnconf.h"
104 @rm -f quarnconf.h
105 @echo -e "\t\t[rm]\tfd.img"
106 @rm -f fd.img
108 # Compile configuration program (ncurses) and run it
109 config: scripts/nc_config
110 @echo -e "\t\t[sh]\tscripts/nc_config"
111 @scripts/nc_config
113 scripts/nc_config: scripts/nc_config.c
114 @echo -e "\t\t[$(CC)]\tscripts/nc_config.c"
115 @$(CC) scripts/nc_config.c -lmenu -lncurses -I/usr/include/ncurses -o scripts/nc_config
117 defconf:
118 @echo -e "\t\t[$(PERL)]\tscripts/text_config.pl"
119 @$(PERL) scripts/text_config.pl def
121 # Run configuration script (doesn't need ncurses)
122 textconf:
123 @echo -e "\t\t[$(PERL)]\tscripts/text_config.pl"
124 @$(PERL) scripts/text_config.pl $(MAJREL).$(MINREL).$(PROREL)$(ADDONS)
126 # Create bootable floppy image
127 fd_img: compile
128 $(info Creating floppy image...)
129 @/sbin/mkdosfs -F 12 -C fd.img 1440
130 @$(SUDO) /sbin/losetup $(LOOPDEV) fd.img
131 @$(SUDO) dd if=arch/$(ARCH)/loaders/boot of=$(LOOPDEV)
132 @mkdir image
133 @$(SUDO) mount $(LOOPDEV) image
134 @-$(SUDO) cp arch/$(ARCH)/loaders/loader image/
135 @$(SUDO) cp quarn image/
136 @$(SUDO) cp AUTHORS image/
137 #@$(SUDO) cp modules/*.ko image/
138 #@$(SUDO) cp hydra/*.ko image/
139 @$(SUDO) umount $(LOOPDEV)
140 @rmdir image
141 @$(SUDO) /sbin/losetup -d $(LOOPDEV)
143 qemu: fd_img
144 @qemu -fda fd.img
146 # Put bootable image on the floppy
147 floppy: fd_img
148 $(info Putting image on a floppy...)
149 @$(SUDO) dd if=fd.img of=/dev/fd0
151 #Create build package
152 build: fd_img
153 $(if $(shell which tar), , $(error TAR is needed to compile Quarn))
154 $(if $(shell which gzip), , $(error GZIP is needed to compile Quarn))
155 $(info Creating build package...)
156 @-rm -f ../quarnos_`date +%Y-%m-%d`.tar
157 @tar -cf ../quarnos_`date +%Y-%m-%d`.tar ../$(DIR_SHORT)
158 @tar --delete -f ../quarnos_`date +%Y-%m-%d`.tar $(DIR_SHORT)/.git
159 @gzip -f ../quarnos_`date +%Y-%m-%d`.tar
161 pack: allclean
162 $(if $(shell which tar), , $(error TAR is needed to compile Quarn))
163 $(if $(shell which gzip), , $(error GZIP is needed to compile Quarn))
164 $(info Creating release package...)
165 @-rm -f ../quarnos_$(MAJREL).$(MINREL).$(PROREL)$(ADDONS).tar
166 @tar -cf ../quarnos_$(MAJREL).$(MINREL).$(PROREL)$(ADDONS).tar ../$(DIR_SHORT)
167 @tar --delete -f ../quarnos_$(MAJREL).$(MINREL).$(PROREL)$(ADDONS).tar $(DIR_SHORT)/.git
168 @gzip -f ../quarnos_$(MAJREL).$(MINREL).$(PROREL)$(ADDONS).tar
170 # Show possible targets
171 help:
172 @echo -e "\t\tQuarn OS $(MAJREL).$(MINREL).$(PROREL) Makefile"
173 @echo -e "\t\t-----------------------"
174 @echo -e "\nConfiguration:"
175 @echo -e "\tconfig\t\t- ncurses configuration tool (WIP)"
176 @echo -e "\tdefconf\t\t- uses default configuration"
177 @echo -e "\ttextconf\t- text configuration tool"
178 @echo -e "\nCompiling:"
179 @echo -e "\tcompile\t\t- compile whole kernel (default)"
180 @echo -e "\trebuild\t\t- allclean + compile"
181 @echo -e "\nInstallation:"
182 @echo -e "\tfd_img\t\t- create floppy image (requires root)"
183 @echo -e "\tfloppy\t\t- fd_img + put image on the floppy (requires root)"
184 @echo -e "\nPackaging:"
185 @echo -e "\tbuild\t\t- create build package in the upper directory"
186 @echo -e "\tpack\t\t- create release package in upper directory"
187 @echo -e "\nCleaning:"
188 @echo -e "\tallclean\t- clean + remove configuration files"
189 @echo -e "\tclean\t\t- remove all files generated by target compile"
190 @echo ""