Skip to content
This repository has been archived by the owner on Nov 26, 2022. It is now read-only.

Commit

Permalink
Fix spacing and add windows ninja build
Browse files Browse the repository at this point in the history
  • Loading branch information
raywan committed May 17, 2019
1 parent da177fe commit 3a5d63c
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 74 deletions.
140 changes: 76 additions & 64 deletions configure.py
Original file line number Diff line number Diff line change
@@ -1,92 +1,104 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

import os
import sys
import fnmatch
from ninja_syntax import Writer

PROJECT_NAME = "toy"
PROJECT_NAME = 'toy'

CC = "g++"
CFLAGS = [
"-std=c++11",
"-O3",
"-pthread",
"-march=native",
"-Iinclude",
]
CC = 'g++' if sys.platform != 'win32' else 'cl'
CFLAGS = []
if sys.platform == 'win32':
CFLAGS = ['/O2', '/EHsc', '/Zi', '/I..\include']
else:
CFLAGS = ['-std=c++11', '-O3', '-pthread', '-march=native', '-Iinclude']

SRC_DIR = "src"
BUILD_DIR = "build"
BIN_DIR = "bin"
SRC_DIR = 'src'
BUILD_DIR = 'build'
BIN_DIR = 'bin'

with open('build.ninja', 'w') as build_file:
n = Writer(build_file)
n = Writer(build_file)

n.comment("THIS FILE IS GENERATED BY configure.py")
n.comment("EDITS WILL BE OVERWRITTEN")
n.newline()
n.comment('THIS FILE IS GENERATED BY configure.py')
n.comment('EDITS WILL BE OVERWRITTEN')
n.newline()

#############################################################################
# VARIABLES
#############################################################################
############################################################################
# VARIABLES
############################################################################

n.variable(key="ninja_required_version", value="1.9");
n.variable(key='ninja_required_version', value='1.9')

n.variable(key="cc", value=CC);
n.variable(key="cflags", value=' '.join(CFLAGS))
n.variable(key="project_name", value=PROJECT_NAME)
n.variable(key="src_dir", value=SRC_DIR)
n.variable(key="bin_dir", value=BIN_DIR)
n.variable(key="build_dir", value=BUILD_DIR)
n.variable(key='cc', value=CC)
n.variable(key='cflags', value=' '.join(CFLAGS))
n.variable(key='project_name', value=PROJECT_NAME)
n.variable(key='src_dir', value=SRC_DIR)
n.variable(key='bin_dir', value=BIN_DIR)
n.variable(key='build_dir', value=BUILD_DIR)

n.newline()
n.newline()

#############################################################################
# RULES
#############################################################################
############################################################################
# RULES
############################################################################

n.rule("compile",
command="$cc $cflags -c $in -o $out -MMD -MF $out.d",
depfile="$out.d"
)
if sys.platform == 'win32':
n.rule('compile', command='$cc $cflags /c $in /Fo$build_dir')
else:
n.rule('compile',
command='$cc $cflags -c $in -o $out -MMD -MF $out.d',
depfile='$out.d')

n.rule("link", command="$cc $in -o $bin_dir/$out")
if sys.platform == 'win32':
n.rule('link', command='link $in /OUT:$bin_dir/$out')
else:
n.rule('link', command='$cc $in -o $bin_dir/$out')

n.rule("clean_all", command="rm -rf $build_dir $bin_dir $project_name")
n.rule("make_dirs", command="mkdir -p $build_dir $bin_dir")
n.rule("create_sym_link", command="ln -sf $bin_dir/$project_name $project_name")
n.rule('clean_all', command='rm -rf $build_dir $bin_dir $project_name')
n.rule('make_dirs', command='mkdir -p $build_dir $bin_dir')
if sys.platform == 'win32':
n.rule('create_sym_link', command='mklink $bin_dir/$project_name $project_name')
else:
n.rule('create_sym_link', command='ln -sf $bin_dir/$project_name $project_name')

n.newline()
n.newline()

#############################################################################
# BUILDS
#############################################################################
############################################################################
# BUILDS
############################################################################

n.build(outputs="dirs", rule="make_dirs")
n.build(outputs="fresh", rule="clean_all")
n.build(outputs="sym", rule="create_sym_link")
n.build(outputs='dirs', rule='make_dirs')
n.build(outputs='fresh', rule='clean_all')
n.build(outputs='sym', rule='create_sym_link')

sources = []
for root, dirnames, filenames in os.walk(SRC_DIR):
for filename in fnmatch.filter(filenames, '*.cpp'):
if 'win32_' not in filename:
sources.append(os.path.join(root, filename))
sources = []
for (root, dirnames, filenames) in os.walk(SRC_DIR):
for filename in fnmatch.filter(filenames, '*.cpp'):
if 'win32_' not in filename:
sources.append(os.path.join(root, filename))

for source in sources:
n.build(outputs=source.replace(".cpp", ".o").replace('src', BUILD_DIR),
rule="compile",
inputs=source
)
for source in sources:
n.build(outputs=source.replace('.cpp', '.o').replace('src',
BUILD_DIR), rule='compile', inputs=source)

o_files = [x.replace(".cpp", ".o").replace('src', BUILD_DIR) for x in sources]
n.build(outputs=PROJECT_NAME, rule="link", inputs=o_files)
o_files = []
if sys.platform == 'win32':
o_files = [x.replace('.cpp', '.obj').replace('src', BUILD_DIR) for x in sources]
else:
o_files = [x.replace('.cpp', '.o').replace('src', BUILD_DIR) for x in sources]

n.newline()
n.build(outputs=PROJECT_NAME, rule='link', inputs=o_files)

#############################################################################
# DEFAULTS
#############################################################################
n.newline()

############################################################################
# DEFAULTS
############################################################################

n.default('dirs')
n.default(PROJECT_NAME)
n.default('sym')

n.default("dirs")
n.default(PROJECT_NAME)
n.default("sym")
20 changes: 10 additions & 10 deletions src/win32_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ unsigned int worker(void *t_arg) {
while (1) {
switch (WaitForSingleObject(jq_mutex, 0xFFFFFFFF)) {
case WAIT_OBJECT_0: {
if (data->job_queue->size() == 0) {
ReleaseMutex(jq_mutex);
return 1;
}
Tile t = data->job_queue->front();
data->job_queue->pop();
ReleaseMutex(jq_mutex);
// Do work
render(data, t);
if (data->job_queue->size() == 0) {
ReleaseMutex(jq_mutex);
return 1;
}
Tile t = data->job_queue->front();
data->job_queue->pop();
ReleaseMutex(jq_mutex);
// Do work
render(data, t);
} break;
case WAIT_ABANDONED:
return 0;
return 0;
}
}
return 1;
Expand Down

0 comments on commit 3a5d63c

Please sign in to comment.