1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00
sortix--sortix/Makefile

427 lines
12 KiB
Makefile
Raw Normal View History

SOFTWARE_MEANT_FOR_SORTIX=1
2014-06-28 10:10:20 -04:00
include build-aux/platform.mak
include build-aux/compiler.mak
include build-aux/version.mak
2012-09-10 17:36:15 -04:00
2013-08-31 07:15:53 -04:00
MODULES=\
doc \
libc \
libm \
libpthread \
dispd \
2015-03-07 07:34:43 -05:00
libmount \
2013-08-31 07:15:53 -04:00
bench \
2014-04-21 16:37:44 -04:00
carray \
2014-08-23 15:26:38 -04:00
editor \
2013-08-31 07:15:53 -04:00
ext \
games \
2014-10-04 11:34:51 -04:00
init \
2014-05-05 18:17:11 -04:00
kblayout \
2014-04-21 12:44:24 -04:00
kblayout-compiler \
2013-08-31 07:15:53 -04:00
mbr \
mkinitrd \
2014-02-20 09:48:20 -05:00
regress \
2015-09-19 21:33:04 -04:00
sf \
2014-12-04 11:39:41 -05:00
sh \
2014-05-13 16:46:23 -04:00
tix \
2013-03-16 17:40:02 -04:00
trianglix \
2013-08-31 07:15:53 -04:00
utils \
kernel
ifndef SYSROOT
2012-09-10 17:36:15 -04:00
SYSROOT:=$(shell pwd)/sysroot
endif
ifndef SYSROOT_OVERLAY
SYSROOT_OVERLAY:=$(shell pwd)/sysroot-overlay
2011-08-05 08:25:00 -04:00
endif
SORTIX_BUILDS_DIR?=builds
2013-10-30 07:09:57 -04:00
SORTIX_PORTS_DIR?=ports
SORTIX_RELEASE_DIR?=release
2013-10-30 07:09:57 -04:00
SORTIX_REPOSITORY_DIR?=repository
2014-06-28 10:10:20 -04:00
include build-aux/dirs.mak
BUILD_NAME:=sortix_$(VERSION)_$(MACHINE)
2011-08-05 08:25:00 -04:00
INITRD:=$(SORTIX_BUILDS_DIR)/$(BUILD_NAME).initrd
.PHONY: all
all: sysroot
2014-06-28 10:10:20 -04:00
.PHONY: install
install: sysroot
2014-10-01 13:01:28 -04:00
@if test -z '$(INSTALL_ROOTFS)' ; then \
echo "error: You must set INSTALL_ROOTFS to where you want Sortix installed" >&2; \
exit 1; \
fi
@if test -d '$(INSTALL_ROOTFS)' && test -z '$(STUPIDLY_FORCE_SORTIX_INSTALL_OVERWRITE)'; then \
for ENTRY in $$(ls -A "$(SYSROOT)"); do \
if test -e "$(INSTALL_ROOTFS)/$$ENTRY"; then \
echo "Error: Refusing to corrupt the existing installation at $(INSTALL_ROOTFS)" >&2; \
echo "Use sysmerge to update an existence installation." >&2; \
exit 1; \
fi; \
done; \
fi
cp -RTv "$(SYSROOT)" "$(INSTALL_ROOTFS)"
@if test -n '$(INSTALL_ROOTFS_UUID)'; then \
echo '$(INSTALL_ROOTFS_UUID)' > "$(INSTALL_ROOTFS)/etc/rootfs.uuid"; \
SYSROOT="$(SYSROOT)" $(MAKE) create-install-rootfs-initrd; \
2014-10-01 13:01:28 -04:00
else \
echo "Warning: INSTALL_ROOTFS_UUID was not set"; \
echo "Therefore: /etc/rootfs.uuid was not created"; \
echo "Therefore: No initrd was created and installed"; \
fi
.PHONY: create-install-rootfs-initrd
create-install-rootfs-initrd:
ifeq ($(BUILD_IS_SORTIX),0)
@if test -z '$(INSTALL_ROOTFS)' || test 'x$(INSTALL_ROOTFS)' = 'x/'; then \
echo "error: Refusing to create an initrd for the local non-Sortix operating system" >&2; \
exit 1; \
fi
2014-06-28 10:10:20 -04:00
endif
mkdir -p "$(INSTALL_ROOTFS)/boot"
rm -rf "$(INSTALL_ROOTFS)/boot/sortix.initrd.d"
mkdir -p "$(INSTALL_ROOTFS)/boot/sortix.initrd.d"
mkdir -p "$(INSTALL_ROOTFS)/boot/sortix.initrd.d/bin"
2014-10-01 13:01:28 -04:00
for PROGRAM in init mbrfs extfs; do \
cp "$(INSTALL_ROOTFS)/bin/$$PROGRAM" "$(INSTALL_ROOTFS)/boot/sortix.initrd.d/bin/$$PROGRAM"; \
2014-10-01 13:01:28 -04:00
done
mkdir -p "$(INSTALL_ROOTFS)/boot/sortix.initrd.d/etc"
mkdir -p "$(INSTALL_ROOTFS)/boot/sortix.initrd.d/etc/init"
cp "$(INSTALL_ROOTFS)/etc/rootfs.uuid" "$(INSTALL_ROOTFS)/boot/sortix.initrd.d/etc/init/rootfs.uuid"
mkinitrd --format=sortix-initrd-2 "$(INSTALL_ROOTFS)/boot/sortix.initrd.d" -o "$(INSTALL_ROOTFS)/boot/sortix.initrd"
rm -rf "$(INSTALL_ROOTFS)/boot/sortix.initrd.d"
2014-10-01 13:01:28 -04:00
.PHONY: sysmerge
sysmerge: sysroot
ifeq ($(BUILD_IS_SORTIX),0)
if test -z '$(DESTDIR)' || test 'x$(DESTDIR)' = 'x/'; then \
echo "error: Refusing to corrupt the local operating system by sysmerging it with Sortix" >&2 \
exit 1 \
fi
endif
for ENTRY in $$(ls -A "$(SYSROOT)" | grep -Ev '^(src|etc|home|mnt|tmp|var)$$'); do \
cp -RTv "$(SYSROOT)/$$ENTRY" "$(DESTDIR)/$$ENTRY" || exit $$?; \
done
2014-06-28 10:10:20 -04:00
2015-01-19 11:58:07 -05:00
.PHONY: clean-build-tools
clean-build-tools:
$(MAKE) -C carray clean
2014-04-21 12:44:24 -04:00
$(MAKE) -C kblayout-compiler clean
2015-01-19 11:58:07 -05:00
$(MAKE) -C mkinitrd clean
2015-09-19 21:33:04 -04:00
$(MAKE) -C sf clean
2015-01-19 11:58:07 -05:00
$(MAKE) -C tix clean
.PHONY: build-tools
build-tools:
2014-04-21 16:37:44 -04:00
$(MAKE) -C carray
2014-04-21 12:44:24 -04:00
$(MAKE) -C kblayout-compiler
$(MAKE) -C mkinitrd
2015-09-19 21:33:04 -04:00
$(MAKE) -C sf
2013-03-26 07:40:43 -04:00
$(MAKE) -C tix
.PHONY: install-build-tools
install-build-tools:
2014-04-21 16:37:44 -04:00
$(MAKE) -C carray install
2014-04-21 12:44:24 -04:00
$(MAKE) -C kblayout-compiler install
$(MAKE) -C mkinitrd install
2015-09-19 21:33:04 -04:00
$(MAKE) -C sf install
2013-03-26 07:40:43 -04:00
$(MAKE) -C tix install
2012-09-10 17:36:15 -04:00
.PHONY: sysroot-fsh
2012-09-10 17:36:15 -04:00
sysroot-fsh:
mkdir -p "$(SYSROOT)"
mkdir -p "$(SYSROOT)/bin"
mkdir -p "$(SYSROOT)/boot"
mkdir -p "$(SYSROOT)/etc"
mkdir -p "$(SYSROOT)/etc/skel"
mkdir -p "$(SYSROOT)/home"
mkdir -p "$(SYSROOT)/include"
mkdir -p "$(SYSROOT)/lib"
mkdir -p "$(SYSROOT)/libexec"
mkdir -p "$(SYSROOT)/mnt"
2015-02-15 06:54:44 -05:00
mkdir -p "$(SYSROOT)/sbin"
mkdir -p "$(SYSROOT)/share"
mkdir -p "$(SYSROOT)/src"
mkdir -p "$(SYSROOT)/tmp"
2014-06-28 10:13:20 -04:00
mkdir -p "$(SYSROOT)/var"
mkdir -p "$(SYSROOT)/var/empty"
2015-12-17 09:35:13 -05:00
ln -sfT . "$(SYSROOT)/usr"
2013-10-01 14:21:50 -04:00
echo "root::0:0:root:/root:sh" > "$(SYSROOT)/etc/passwd"
2013-10-01 16:23:50 -04:00
echo "root::0:root" > "$(SYSROOT)/etc/group"
.PHONY: sysroot-base-headers
sysroot-base-headers: sysroot-fsh
export SYSROOT="$(SYSROOT)" && \
2014-06-28 10:10:20 -04:00
(for D in libc libm libpthread kernel; do ($(MAKE) -C $$D install-headers DESTDIR="$(SYSROOT)") || exit $$?; done)
.PHONY: sysroot-system
sysroot-system: sysroot-fsh sysroot-base-headers
2015-10-05 18:32:45 -04:00
cp -RT share "$(SYSROOT)/share"
export SYSROOT="$(SYSROOT)" && \
2014-06-28 10:10:20 -04:00
(for D in $(MODULES); do ($(MAKE) -C $$D && $(MAKE) -C $$D install DESTDIR="$(SYSROOT)") || exit $$?; done)
.PHONY: sysroot-source
sysroot-source: sysroot-fsh
2014-06-28 10:10:20 -04:00
cp .gitignore -t "$(SYSROOT)/src"
cp COPYING-GPL -t "$(SYSROOT)/src"
cp COPYING-LGPL -t "$(SYSROOT)/src"
2014-06-28 10:10:20 -04:00
cp Makefile -t "$(SYSROOT)/src"
cp README -t "$(SYSROOT)/src"
2014-06-28 10:10:20 -04:00
cp -RT build-aux "$(SYSROOT)/src/build-aux"
2015-05-16 18:15:51 -04:00
cp -RT isosrc "$(SYSROOT)/src/isosrc"
2014-09-22 11:35:54 -04:00
(for D in $(MODULES); do (cp -R $$D -t "$(SYSROOT)/src" && $(MAKE) -C "$(SYSROOT)/src/$$D" clean) || exit $$?; done)
2013-10-30 07:09:57 -04:00
.PHONY: sysroot-ports
sysroot-ports: sysroot-fsh sysroot-base-headers sysroot-system sysroot-source
@SORTIX_PORTS_DIR="$(SORTIX_PORTS_DIR)" \
SORTIX_REPOSITORY_DIR="$(SORTIX_REPOSITORY_DIR)" \
SYSROOT="$(SYSROOT)" \
HOST="$(HOST)" \
MAKE="$(MAKE)" \
2014-06-28 10:10:20 -04:00
MAKEFLAGS="$(MAKEFLAGS)" \
build-aux/build-ports.sh
2013-10-30 07:09:57 -04:00
.PHONY: sysroot-overlay
2013-10-30 07:09:57 -04:00
sysroot-overlay: sysroot-fsh sysroot-system sysroot-ports
! [ -d "$(SYSROOT_OVERLAY)" ] || \
2014-06-28 10:10:20 -04:00
cp -RT --preserve=mode,timestamp,links "$(SYSROOT_OVERLAY)" "$(SYSROOT)"
.PHONY: sysroot-user-skel
2013-10-30 07:09:57 -04:00
sysroot-user-skel: sysroot-fsh sysroot-system sysroot-ports sysroot-overlay
2012-12-21 15:22:09 -05:00
cp "$(SYSROOT)/share/doc/welcome" -t "$(SYSROOT)/etc/skel"
.PHONY: sysroot-home-directory
2013-10-30 07:09:57 -04:00
sysroot-home-directory: sysroot-fsh sysroot-system sysroot-ports sysroot-overlay sysroot-user-skel
mkdir -p "$(SYSROOT)/root"
2014-06-28 10:10:20 -04:00
cp -RT "$(SYSROOT)/etc/skel" "$(SYSROOT)/root"
.PHONY: sysroot
2013-10-30 07:09:57 -04:00
sysroot: sysroot-system sysroot-source sysroot-ports sysroot-overlay sysroot-home-directory
$(SORTIX_REPOSITORY_DIR):
mkdir -p $@
$(SORTIX_REPOSITORY_DIR)/$(HOST): $(SORTIX_REPOSITORY_DIR)
mkdir -p $@
.PHONY: clean-core
clean-core:
2014-06-28 10:10:20 -04:00
(for D in $(MODULES); do $(MAKE) clean -C $$D || exit $$?; done)
2013-10-30 07:09:57 -04:00
.PHONY: clean-ports
clean-ports:
@SORTIX_PORTS_DIR="$(SORTIX_PORTS_DIR)" \
HOST="$(HOST)" \
MAKE="$(MAKE)" \
2014-06-28 10:10:20 -04:00
MAKEFLAGS="$(MAKEFLAGS)" \
build-aux/clean-ports.sh
2013-10-30 07:09:57 -04:00
.PHONY: clean-builds
2012-09-10 17:36:15 -04:00
clean-builds:
rm -rf "$(SORTIX_BUILDS_DIR)"
2014-09-19 10:38:40 -04:00
rm -f sortix.bin
rm -f sortix.initrd
2011-08-05 08:25:00 -04:00
rm -f sortix.iso
rm -f sortix.iso.xz
.PHONY: clean-release
clean-release:
rm -rf "$(SORTIX_RELEASE_DIR)"
2011-08-05 08:25:00 -04:00
2013-10-30 07:09:57 -04:00
.PHONY: clean-repository
clean-repository:
rm -rf "$(SORTIX_REPOSITORY_DIR)"
.PHONY: clean-sysroot
2012-09-10 17:36:15 -04:00
clean-sysroot:
rm -rf "$(SYSROOT)"
.PHONY: clean
2013-10-30 07:09:57 -04:00
clean: clean-core clean-ports
2012-09-10 17:36:15 -04:00
.PHONY: mostlyclean
2013-10-30 07:09:57 -04:00
mostlyclean: clean-core clean-ports clean-builds clean-release clean-sysroot
.PHONY: distclean
2013-10-30 07:09:57 -04:00
distclean: clean-core clean-ports clean-builds clean-release clean-repository clean-sysroot
.PHONY: most-things
2014-06-28 10:10:20 -04:00
most-things: sysroot initrd tar iso
.PHONY: everything
everything: most-things iso.xz
2012-09-10 17:36:15 -04:00
# Targets that build multiple architectures.
.PHONY: sysroot-base-headers-all-archs
sysroot-base-headers-all-archs:
2015-04-25 17:11:46 -04:00
$(MAKE) clean clean-sysroot
$(MAKE) sysroot-base-headers HOST=i486-sortix
2015-04-25 17:11:46 -04:00
$(MAKE) clean clean-sysroot
$(MAKE) sysroot-base-headers HOST=x86_64-sortix
.PHONY: all-archs
2012-09-10 17:36:15 -04:00
all-archs:
2015-04-25 17:11:46 -04:00
$(MAKE) clean clean-sysroot
$(MAKE) all HOST=i486-sortix
2015-04-25 17:11:46 -04:00
$(MAKE) clean clean-sysroot
$(MAKE) all HOST=x86_64-sortix
.PHONY: most-things-all-archs
most-things-all-archs:
2015-04-25 17:11:46 -04:00
$(MAKE) clean clean-sysroot
$(MAKE) most-things HOST=i486-sortix
2015-04-25 17:11:46 -04:00
$(MAKE) clean clean-sysroot
$(MAKE) most-things HOST=x86_64-sortix
.PHONY: everything-all-archs
everything-all-archs:
2015-04-25 17:11:46 -04:00
$(MAKE) clean clean-sysroot
$(MAKE) everything HOST=i486-sortix
2015-04-25 17:11:46 -04:00
$(MAKE) clean clean-sysroot
$(MAKE) everything HOST=x86_64-sortix
.PHONY: release-all-archs
release-all-archs:
2015-04-25 17:11:46 -04:00
$(MAKE) clean clean-sysroot
$(MAKE) release HOST=i486-sortix
2015-04-25 17:11:46 -04:00
$(MAKE) clean clean-sysroot
$(MAKE) release HOST=x86_64-sortix
2011-08-05 08:25:00 -04:00
2014-09-19 10:38:40 -04:00
# Kernel
.PHONY: kernel
kernel: sysroot
sortix.bin: kernel
cp "$(SYSROOT)/boot/sortix.bin" sortix.bin
2014-09-19 10:38:40 -04:00
# Initial ramdisk
$(INITRD): sysroot
mkdir -p `dirname $(INITRD)`
printf '' > $(INITRD).filter
echo "exclude /boot" >> $(INITRD).filter
echo "exclude /dev" >> $(INITRD).filter
echo "exclude /next" >> $(INITRD).filter
2014-06-28 10:10:20 -04:00
echo "exclude /src/sysroot" >> $(INITRD).filter
echo "exclude /tmp" >> $(INITRD).filter
if ! which mkinitrd; then echo You need to install mkinitrd; fi
2014-04-23 11:53:19 -04:00
mkinitrd --format=sortix-initrd-2 --filter=$(INITRD).filter "$(SYSROOT)" -o $(INITRD)
rm -f $(INITRD).filter
.PHONY: initrd
initrd: $(INITRD)
sortix.initrd: $(INITRD)
cp $(INITRD) sortix.initrd
2011-08-05 08:25:00 -04:00
# Packaging
$(SORTIX_BUILDS_DIR):
mkdir -p $(SORTIX_BUILDS_DIR)
$(SORTIX_BUILDS_DIR)/$(BUILD_NAME).tar.xz: sysroot $(INITRD) $(SORTIX_BUILDS_DIR)
rm -rf $(SORTIX_BUILDS_DIR)/tardir
mkdir -p $(SORTIX_BUILDS_DIR)/tardir
mkdir -p $(SORTIX_BUILDS_DIR)/tardir/boot
cp "$(SYSROOT)/boot/sortix.bin" $(SORTIX_BUILDS_DIR)/tardir/boot/sortix.bin
cp $(INITRD) $(SORTIX_BUILDS_DIR)/tardir/boot/sortix.initrd
tar --create --xz --file $(SORTIX_BUILDS_DIR)/$(BUILD_NAME).tar.xz -C $(SORTIX_BUILDS_DIR)/tardir `ls $(SORTIX_BUILDS_DIR)/tardir`
rm -rf $(SORTIX_BUILDS_DIR)/tardir
.PHONY: tar
tar: $(SORTIX_BUILDS_DIR)/$(BUILD_NAME).tar.xz
2011-08-05 08:25:00 -04:00
# Bootable images
$(SORTIX_BUILDS_DIR)/$(BUILD_NAME).iso: sysroot $(INITRD) $(SORTIX_BUILDS_DIR)
rm -rf $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso
mkdir -p $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso
2014-06-28 10:10:20 -04:00
cp -RT isosrc $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso
cp "$(SYSROOT)/boot/sortix.bin" $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso/boot/sortix.bin
cp $(INITRD) $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso/boot/sortix.initrd
grub-mkrescue -o $(SORTIX_BUILDS_DIR)/$(BUILD_NAME).iso $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso
rm -rf $(SORTIX_BUILDS_DIR)/$(BUILD_NAME)-iso
$(SORTIX_BUILDS_DIR)/$(BUILD_NAME).iso.xz: $(SORTIX_BUILDS_DIR)/$(BUILD_NAME).iso $(SORTIX_BUILDS_DIR)
xz -c $< > $@
.PHONY: iso
iso: $(SORTIX_BUILDS_DIR)/$(BUILD_NAME).iso
.PHONY: iso.xz
iso.xz: $(SORTIX_BUILDS_DIR)/$(BUILD_NAME).iso.xz
sortix.iso: $(SORTIX_BUILDS_DIR)/$(BUILD_NAME).iso
2014-06-28 10:10:20 -04:00
cp $< $@
sortix.iso.xz: $(SORTIX_BUILDS_DIR)/$(BUILD_NAME).iso.xz
2014-06-28 10:10:20 -04:00
cp $< $@
# Release
2015-10-05 18:32:45 -04:00
$(SORTIX_RELEASE_DIR)/$(VERSION):
mkdir -p $@
2011-08-05 08:25:00 -04:00
$(SORTIX_RELEASE_DIR)/$(VERSION)/builds: $(SORTIX_RELEASE_DIR)/$(VERSION)
mkdir -p $@
2012-09-10 17:36:15 -04:00
$(SORTIX_RELEASE_DIR)/$(VERSION)/builds/$(BUILD_NAME).iso.xz: $(SORTIX_BUILDS_DIR)/$(BUILD_NAME).iso.xz $(SORTIX_RELEASE_DIR)/$(VERSION)/builds
cp $< $@
.PHONY: release-iso.xz
release-iso.xz: $(SORTIX_RELEASE_DIR)/$(VERSION)/builds/$(BUILD_NAME).iso.xz
$(SORTIX_RELEASE_DIR)/$(VERSION)/builds/$(BUILD_NAME).tar.xz: $(SORTIX_BUILDS_DIR)/$(BUILD_NAME).tar.xz $(SORTIX_RELEASE_DIR)/$(VERSION)/builds
cp $< $@
.PHONY: release-tar
release-tar: $(SORTIX_RELEASE_DIR)/$(VERSION)/builds/$(BUILD_NAME).tar.xz
.PHONY: release-builds
2014-06-28 10:10:20 -04:00
release-builds: release-iso.xz release-tar
$(SORTIX_RELEASE_DIR)/$(VERSION)/README: README $(SORTIX_RELEASE_DIR)/$(VERSION)
cp $< $@
.PHONY: release-readme
release-readme: $(SORTIX_RELEASE_DIR)/$(VERSION)/README
2013-10-30 07:09:57 -04:00
$(SORTIX_RELEASE_DIR)/$(VERSION)/repository:
mkdir -p $@
$(SORTIX_RELEASE_DIR)/$(VERSION)/repository/$(HOST): sysroot $(SORTIX_REPOSITORY_DIR)/$(HOST) $(SORTIX_RELEASE_DIR)/$(VERSION)/repository
2014-06-28 10:10:20 -04:00
cp -RT $(SORTIX_REPOSITORY_DIR)/$(HOST) $@
2013-10-30 07:09:57 -04:00
.PHONY: release-repository
release-repository: $(SORTIX_RELEASE_DIR)/$(VERSION)/repository/$(HOST)
.PHONY: release-arch
2015-10-05 18:32:45 -04:00
release-arch: release-builds release-readme release-repository
.PHONY: release-shared
2015-10-05 18:32:45 -04:00
release-shared: release-readme
.PHONY: release
release: release-arch release-shared
2011-08-05 08:25:00 -04:00
# Virtualization
.PHONY: run-virtualbox
2011-08-05 08:25:00 -04:00
run-virtualbox: sortix.iso
virtualbox --startvm sortix
.PHONY: run-virtualbox-debug
2011-08-05 08:25:00 -04:00
run-virtualbox-debug: sortix.iso
virtualbox --debug --start-running --startvm sortix
# Statistics
.PHONY: linecount
linecount:
wc -l `find . -type f | grep -Ev '\.(h|h\+\+|c$$|cpp|c\+\+|s|S|asm|kblayout|mak|sh)$$|(^|/)Makefile$$' | grep -Ev '^\./(\.git|sysroot|sysroot-overlay|ports|repository)(/|$$)'` | sort -n