LuPPC/Makefile

136 lines
3.7 KiB
Makefile
Raw Normal View History

2016-01-22 09:25:51 +11:00
# LuPI2 Makefile
2016-01-19 05:42:32 +11:00
2016-01-22 09:25:51 +11:00
# Default compiler settings.
2016-02-24 08:05:42 +11:00
PREFIX?=x86_64-linux-musl
2016-02-12 07:46:16 +11:00
2016-02-13 03:28:47 +11:00
CC = $(PREFIX)-gcc
2016-03-07 03:20:14 +11:00
CFLAGS?=-O2 -std=c99 -fdata-sections -ffunction-sections -pthread
LDFLAGS+= -O2 -Wl,--gc-sections -static -Ldependencies/lib-$(PREFIX) -pthread
2016-01-04 04:08:43 +11:00
2016-01-22 09:25:51 +11:00
# Project specific stuff
2016-01-04 04:08:43 +11:00
BUILD = bin/
2016-01-22 09:25:51 +11:00
SOURCE = src/c
2016-01-04 04:08:43 +11:00
2016-01-03 13:25:12 +11:00
CORELUA = src/lua/core
2016-01-19 11:25:14 +11:00
RESOURCES = resources
2016-02-29 09:10:26 +11:00
LIBS=-lm -llua -lssl -lcrypto -levent_core
2016-02-29 09:10:26 +11:00
INCLUDES=-I$(SOURCE) -Iinclude -Idependencies/include -Idependencies/include-$(PREFIX)
2016-01-22 09:25:51 +11:00
2016-01-19 11:25:14 +11:00
GENERATED=include/luares.h src/c/gen/luares.c include/res.h src/c/gen/res.c
2016-01-03 13:25:12 +11:00
LUAPARAMS = $(CORELUA) include/luares.h src/c/gen/luares.c lua_
2016-01-19 11:25:14 +11:00
RESPARAMS = $(RESOURCES) include/res.h src/c/gen/res.c res_
2016-01-03 13:25:12 +11:00
2016-01-04 04:08:43 +11:00
SRCDIRECTORIES = $(shell find $(SOURCE) -type d)
2016-01-22 09:25:51 +11:00
BUILDDIRECTORIES = $(patsubst $(SOURCE)/%, $(BUILD)%, $(SRCDIRECTORIES))
2016-01-04 04:08:43 +11:00
CFILES = $(shell find $(SOURCE) -type f -name '*.c')
2016-01-22 09:25:51 +11:00
OBJECTS := $(patsubst $(SOURCE)/%.c, $(BUILD)%.c.o, $(CFILES))
OUTNAME = lupi
2016-01-22 09:25:51 +11:00
# Targets
# Pseudo Targets
2016-02-10 03:35:49 +11:00
debug: CFLAGS+= -g -DLOGGING -DDEBUG
debug: build
2016-01-04 04:08:43 +11:00
2016-08-18 06:40:11 +10:00
####
winexe: $(BUILD)$(OUTNAME)
cp $(BUILD)$(OUTNAME) $(BUILD)$(OUTNAME).exe
2016-03-03 08:24:08 +11:00
win: LIBS+= -lws2_32 -lgdi32
win: all winexe
2016-03-03 08:24:08 +11:00
win-build: LIBS+= -lws2_32 -lgdi32
win-build: build winexe
2016-03-03 08:24:08 +11:00
win-debug: LIBS+= -lws2_32 -lgdi32
win-debug: debug winexe
2016-08-18 06:40:11 +10:00
####
dependencies/v86:
cd dependencies; git clone https://github.com/magik6k/v86.git
dependencies/v86/build/libv86.js: dependencies/v86
cd dependencies/v86 && wget -P closure-compiler http://dl.google.com/closure-compiler/compiler-latest.zip
cd dependencies/v86 && unzip -d closure-compiler closure-compiler/compiler-latest.zip compiler.jar
cd dependencies/v86 && make build/libv86.js
$(BUILD)web: dependencies/v86/build/libv86.js
rm -rf bin/web; mkdir -p bin/web
web: iso bin/web
####
ISOKERNEL=linux-4.5.2
dependencies/$(ISOKERNEL).tar.xz:
cd dependencies && wget https://cdn.kernel.org/pub/linux/kernel/v4.x/$(ISOKERNEL).tar.xz
dependencies/$(ISOKERNEL)/arch/x86/boot/bzImage: $(BUILD)lupi.cpio dependencies/$(ISOKERNEL).tar.xz
rm -rf dependencies/$(ISOKERNEL)/
cd dependencies && tar xf $(ISOKERNEL).tar.xz
cp src/iso/linux.config dependencies/$(ISOKERNEL)/.config
cd dependencies/$(ISOKERNEL)/ && make -j8
$(BUILD)lupi.cpio: $(BUILDDIRECTORIES) $(BUILD)$(OUTNAME) build
rm -rf $(BUILD)iso.init; mkdir -p $(BUILD)iso.init
mkdir -p bin/iso.init/sbin bin/iso.init/proc bin/iso.init/sys bin/iso.init/dev bin/iso.init/tmp
cp bin/lupi bin/iso.init/sbin/init
(cd bin/iso.init; find . | fakeroot cpio -o -H newc) > $@
$(BUILD)lupi.iso: dependencies/$(ISOKERNEL)/arch/x86/boot/bzImage
rm -rf bin/iso.dir; mkdir -p bin/iso.dir bin/iso.dir/boot
cp $(BUILD)lupi.cpio bin/iso.dir/boot/lupi.img
cp dependencies/$(ISOKERNEL)/arch/x86/boot/bzImage bin/iso.dir/boot/vmlinuz
cp src/iso/isolinux.cfg bin/iso.dir/isolinux.cfg
mkdir -p bin/iso.dir/syslinux bin/iso.dir/sbin
cp bin/lupi bin/iso.dir/sbin/init
cp /usr/lib/syslinux/bios/{isolinux.bin,ldlinux.c32,isohdpfx.bin} bin/iso.dir/syslinux/
mkisofs -o bin/lupi.iso -b syslinux/isolinux.bin -c syslinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table bin/iso.dir
iso: PREFIX?=i486-linux-musl
iso: build $(BUILD)lupi.iso
####
2016-01-04 04:08:43 +11:00
$(BUILDDIRECTORIES):
2016-01-05 04:20:40 +11:00
mkdir -p $@
2016-01-04 04:08:43 +11:00
build: smallclean $(BUILDDIRECTORIES) resources $(BUILD)$(OUTNAME)
2016-01-03 13:25:12 +11:00
2016-01-22 09:25:51 +11:00
all: clean build
$(BUILD)$(OUTNAME): $(OBJECTS)
2016-01-04 04:08:43 +11:00
$(CC) $(LDFLAGS) $(OBJECTS) -o $@ $(LIBS)
2016-01-22 09:25:51 +11:00
$(BUILD)%.c.o: $(SOURCE)/%.c
$(CC) -c $(CFLAGS) $(INCLUDES) $< -o $@
2016-01-03 13:25:12 +11:00
#Resources
2016-01-22 09:25:51 +11:00
resources: cleanresources
2016-01-03 13:25:12 +11:00
scripts/txt2c $(LUAPARAMS)
2016-01-19 11:25:14 +11:00
scripts/txt2c $(RESPARAMS)
2016-01-03 13:25:12 +11:00
2016-01-22 09:25:51 +11:00
# Clean rules
cleanresources:
2016-01-03 13:25:12 +11:00
-rm -f $(GENERATED)
2016-01-22 09:25:51 +11:00
mkdir -p $(SOURCE)/gen/
touch $(SOURCE)/gen/luares.c
2016-01-03 13:25:12 +11:00
touch include/luares.h
2016-01-22 09:25:51 +11:00
clean: cleanresources
2016-01-04 04:08:43 +11:00
-rm -rf $(BUILD)
2016-01-19 05:42:32 +11:00
smallclean:
find . -name '*~' -type f -exec rm {} \;
# Other
2016-08-18 06:40:11 +10:00
.PHONY: web iso debug clean cleanresourcues resources build smallclean all