mirror of https://github.com/flysand7/ciabatta.git
say no to make, say no to shell scripts, python is the way to go
This commit is contained in:
parent
a84b34abdd
commit
3ab1c1ad29
66
Makefile
66
Makefile
|
@ -1,66 +0,0 @@
|
||||||
|
|
||||||
CC=clang
|
|
||||||
SRC_DIR := src
|
|
||||||
OBJ_DIR := bin
|
|
||||||
IFLAGS := -Iinc -Isrc/win -Iunicope/inc
|
|
||||||
|
|
||||||
# Detect target operating system
|
|
||||||
ifeq ($(OS),Windows_NT)
|
|
||||||
PLATFORM := win
|
|
||||||
else
|
|
||||||
PLATFORM := $(shell sh -c 'uname 2>/dev/null || echo Unknown')
|
|
||||||
PLATFORM := $(shell sh -c 'echo $(PLATFORM) | tr A-Z a-z')
|
|
||||||
endif
|
|
||||||
ifeq ($(PLATFORM),Unknown)
|
|
||||||
echo Unknown platform
|
|
||||||
exit 1
|
|
||||||
endif
|
|
||||||
|
|
||||||
# If we're compiling under windows we'll link to these libraries
|
|
||||||
ifeq ($(PLATFORM),win)
|
|
||||||
LIBS := -lDbghelp -lkernel32 -luser32 -lshell32
|
|
||||||
MKDIR_P_FLAG :=
|
|
||||||
NUL_FILE := NUL
|
|
||||||
else
|
|
||||||
LIBS := -lrt -lpthread -ldl
|
|
||||||
MKDIR_P_FLAG := '-p'
|
|
||||||
NUL_FILE := /dev/null
|
|
||||||
endif
|
|
||||||
|
|
||||||
# Compiler flags
|
|
||||||
ifeq ($(CC), clang)
|
|
||||||
CFLAGS=$(GNUFLAGS) -Wall -msse2 -mfma $(IFLAGS)
|
|
||||||
else
|
|
||||||
echo BAD CC
|
|
||||||
exit 1
|
|
||||||
endif
|
|
||||||
|
|
||||||
# Figure out what we want to compile at the end
|
|
||||||
SRC_FILES := \
|
|
||||||
$(wildcard $(SRC_DIR)/code/*.c) \
|
|
||||||
$(wildcard $(SRC_DIR)/code/**/*.c) \
|
|
||||||
$(wildcard $(SRC_DIR)/$(PLATFORM)/*.c) \
|
|
||||||
$(wildcard $(SRC_DIR)/$(PLATFORM)/**/*.c)
|
|
||||||
OBJ_FILES := $(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/%.obj,$(SRC_FILES))
|
|
||||||
|
|
||||||
$(OBJ_DIR)/%.obj: $(SRC_DIR)/%.c
|
|
||||||
@-mkdir $(MKDIR_P_FLAG) "$(dir $@)" 2> $(NUL_FILE)
|
|
||||||
$(CC) $(CFLAGS) -c -o $@ $<
|
|
||||||
|
|
||||||
ciabatta.lib: $(OBJ_FILES) unicope/unicope.lib
|
|
||||||
llvm-ar rc $@ $^
|
|
||||||
|
|
||||||
unicope/unicope.lib:
|
|
||||||
unicope\bake
|
|
||||||
|
|
||||||
|
|
||||||
test: ciabatta.lib
|
|
||||||
clang -g test/test_$(test).c ciabatta.lib -std=c11 $(LIBS) -nostdlib -Iinc
|
|
||||||
|
|
||||||
clean:
|
|
||||||
rd/s/q bin || true
|
|
||||||
rm -Rf bin || true
|
|
||||||
rm -f ciabatta.lib || true
|
|
||||||
del ciabatta.lib || true
|
|
||||||
|
|
||||||
.PHONY: ciabatta.lib test
|
|
41
bake.cmd
41
bake.cmd
|
@ -1,41 +0,0 @@
|
||||||
@echo off
|
|
||||||
setlocal enabledelayedexpansion
|
|
||||||
|
|
||||||
:: Make sure that if I ctrl+c out of the script the dir is popped
|
|
||||||
:: If there's anything that requires user input, this script will break
|
|
||||||
:: in that case I recommend you removing the 'echo y' part.
|
|
||||||
:: although you will have to confirm termination of the script twice
|
|
||||||
if "%~1" neq "_start_" (
|
|
||||||
pushd %~pd0
|
|
||||||
echo y | cmd /c "%~f0" _start_ %*
|
|
||||||
popd
|
|
||||||
exit /b
|
|
||||||
)
|
|
||||||
shift /1
|
|
||||||
|
|
||||||
set CIABATTA_OPTIONS=-Iinc -I unicope\inc -Wall -g -gcodeview -nodefaultlibs -D_CRT_SECURE_NO_WARNINGS -mfma
|
|
||||||
set PLATFORM=win
|
|
||||||
|
|
||||||
if "%1"=="test" (
|
|
||||||
goto :skip_crt_compilation
|
|
||||||
)
|
|
||||||
|
|
||||||
if exist bin rd/s/q bin
|
|
||||||
mkdir bin
|
|
||||||
mkdir bin\%PLATFORM%
|
|
||||||
|
|
||||||
del ciabatta.lib 2> nul
|
|
||||||
call bake_cc.cmd
|
|
||||||
for /R src\%PLATFORM% %%F in (*.asm) do (
|
|
||||||
echo %%F
|
|
||||||
nasm %%F -f win64 -o bin\%PLATFORM%\%%~nF.obj
|
|
||||||
)
|
|
||||||
llvm-ar rc ciabatta.lib bin\*.obj bin\%PLATFORM%\*.obj
|
|
||||||
|
|
||||||
:skip_crt_compilation
|
|
||||||
|
|
||||||
if "%TEST%"=="" set TEST=threads
|
|
||||||
|
|
||||||
echo Compiling test_%TEST%.c
|
|
||||||
clang test\test_%TEST%.c ciabatta.lib -std=c11 -lDbghelp -lkernel32 -luser32 -lshell32 -nostdlib %CIABATTA_OPTIONS%
|
|
||||||
::cl test\test_math.c /Iinc -D_CRT_SECURE_NO_WARNINGS /Z7 /link ciabatta.lib kernel32.lib user32.lib shell32.lib -nostdlib -nodefaultlibs
|
|
|
@ -0,0 +1,89 @@
|
||||||
|
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
# General compile options
|
||||||
|
|
||||||
|
platform = 'win'
|
||||||
|
do_cuik = False
|
||||||
|
|
||||||
|
inc_folders = [
|
||||||
|
'inc',
|
||||||
|
os.path.join('unicope', 'inc'),
|
||||||
|
]
|
||||||
|
|
||||||
|
definitions = [
|
||||||
|
'_CRT_SECURE_NO_WARNINGS',
|
||||||
|
]
|
||||||
|
|
||||||
|
# Compiler-specific options
|
||||||
|
|
||||||
|
clang_dbg_flags = ['-g', '-gcodeview']
|
||||||
|
clang_common_flags = ['-c', '-nodefaultlibs', '-mfma']
|
||||||
|
|
||||||
|
cuik_flags = []
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------#
|
||||||
|
# Map lists to lists of options
|
||||||
|
inc_flags = []
|
||||||
|
def_flags = []
|
||||||
|
def compile(root, cmap):
|
||||||
|
global inc_flags
|
||||||
|
global def_flags
|
||||||
|
inc_flags = list(map(lambda p: '-I '+ p, inc_folders))
|
||||||
|
def_flags = list(map(lambda d: '-D' + d, definitions))
|
||||||
|
for path, subdirs, files in os.walk(root):
|
||||||
|
for file_name in files:
|
||||||
|
file_path = os.path.join(path, file_name)
|
||||||
|
short_name, ext = os.path.splitext(file_path)
|
||||||
|
if ext in cmap.keys():
|
||||||
|
func = cmap[ext]
|
||||||
|
func(file_path)
|
||||||
|
|
||||||
|
def get_bin_path(file_path):
|
||||||
|
rel_path = os.path.normpath(file_path).split(os.path.sep)[1:]
|
||||||
|
name, ext = os.path.splitext(os.path.sep.join(rel_path))
|
||||||
|
bin_path = os.path.join('bin', name+'.obj')
|
||||||
|
os.makedirs(os.path.dirname(bin_path), exist_ok=True)
|
||||||
|
return bin_path
|
||||||
|
|
||||||
|
def clang_compile(file_name):
|
||||||
|
bin_path = get_bin_path(file_name)
|
||||||
|
dbg_flags = clang_dbg_flags
|
||||||
|
cmn_flags = clang_common_flags
|
||||||
|
flags = dbg_flags + cmn_flags + inc_flags + def_flags
|
||||||
|
command = ' '.join(["clang", file_name, '-o', bin_path] + flags)
|
||||||
|
subprocess.run(command.split(' '))
|
||||||
|
print(file_name, '=>', bin_path)
|
||||||
|
|
||||||
|
def nasm_compile(file_name):
|
||||||
|
bin_path = get_bin_path(file_name)
|
||||||
|
subprocess.run(['nasm', file_name, '-f', 'win64', '-o', bin_path])
|
||||||
|
print(file_name, '=>', bin_path)
|
||||||
|
|
||||||
|
#-----------------------------------------------------------------------------#
|
||||||
|
|
||||||
|
if not do_cuik:
|
||||||
|
# Compile the platform-independent part
|
||||||
|
compile_map = {}
|
||||||
|
compile_map['.c'] = clang_compile
|
||||||
|
compile_map['.asm'] = nasm_compile
|
||||||
|
compile(os.path.normpath('src/code'), compile_map)
|
||||||
|
|
||||||
|
# Add the platform folder to includes and compile platform-dependent part
|
||||||
|
inc_folders.append(os.path.join('src', platform))
|
||||||
|
compile(os.path.normpath(os.path.join('src', platform)), compile_map)
|
||||||
|
|
||||||
|
# Make an archive of all object files
|
||||||
|
obj_paths = []
|
||||||
|
for dir, _, f in os.walk('bin'):
|
||||||
|
if len(f) != 0:
|
||||||
|
obj_paths.append(os.path.join(dir, '*.obj'))
|
||||||
|
subprocess.run(['llvm-ar', 'rc', 'ciabatta.lib'] + obj_paths)
|
||||||
|
else:
|
||||||
|
src = os.path.join('src', 'code', '*.c')
|
||||||
|
os_src = os.path.join('src', platform)
|
||||||
|
cmd = cuik_flags + '-c -o ciabatta.obj'.split(' ') + [src, os_src]
|
||||||
|
print(cmd)
|
||||||
|
subprocess.run(['cuik'] + cmd)
|
||||||
|
subprocess.run('lib', '/out:ciabatta.lib', 'ciabatta.obj')
|
|
@ -1,8 +0,0 @@
|
||||||
for /R src\%PLATFORM% %%F in (*.c) do (
|
|
||||||
echo %%F
|
|
||||||
start /B clang -I unicope\inc -Isrc/win -c -o bin\%PLATFORM%\%%~nF.obj %%F %CIABATTA_OPTIONS%
|
|
||||||
)
|
|
||||||
for /R src\code %%F in (*.c) do (
|
|
||||||
echo %%F
|
|
||||||
start /B clang -I unicope\inc -c -o bin\%%~nF.obj %%F %CIABATTA_OPTIONS%
|
|
||||||
)
|
|
|
@ -1,16 +0,0 @@
|
||||||
@echo off
|
|
||||||
setlocal enabledelayedexpansion
|
|
||||||
|
|
||||||
set PLATFORM=win
|
|
||||||
set CIABATTA_OPTIONS=--crt none -I %% -I inc -I unicope/inc
|
|
||||||
|
|
||||||
del ciabatta.lib
|
|
||||||
del unicope\unicope.lib
|
|
||||||
cuik unicope\src\unicode.c -I unicope\inc -c -o unicope\unicope.lib
|
|
||||||
cuik %CIABATTA_OPTIONS% src\code\*.c src\%PLATFORM%\*.c -c -o ciabatta.obj
|
|
||||||
lib /out:ciabatta.lib ciabatta.obj
|
|
||||||
|
|
||||||
if "%TEST%"=="" set TEST=assert
|
|
||||||
|
|
||||||
cuik test\test_%TEST%.c --lib ciabatta.lib,unicope/unicope.lib,kernel32.lib,user32.lib,shell32.lib %CIABATTA_OPTIONS%
|
|
||||||
del ciabatta.obj
|
|
Loading…
Reference in New Issue