initial commit
This commit is contained in:
commit
f3f4e98843
81
README.md
Normal file
81
README.md
Normal file
|
@ -0,0 +1,81 @@
|
|||
## Marmalade MKB Source File Listing Generator
|
||||
|
||||
This is a script which allows you to automatically populate a list
|
||||
of source files/directories in your MKB files. The source files may
|
||||
be organized into a subdirectory tree in any way you see fit.
|
||||
|
||||
Marmalade's MKB wildcard support is very weak currently when it
|
||||
comes to wanting to specify source files which are organized
|
||||
into many different directories and subdirectories. This script
|
||||
helps work around this limitation.
|
||||
|
||||
# Usage
|
||||
|
||||
You first create a template file **mkb_template.txt** for your MKB.
|
||||
This will contain all the normal things found in an MKB file like
|
||||
your defines, deployment options, includepaths, options, etc. For
|
||||
your files section you simply write it like:
|
||||
|
||||
files
|
||||
{
|
||||
%%SOURCE_FILES%%
|
||||
}
|
||||
|
||||
|
||||
The **%%SOURCE_FILES%%** tag will be replaced with a listing like
|
||||
the following after running the **mkb_generate** script:
|
||||
|
||||
(../src) [src] '*.*'
|
||||
(../src/subdir) [src/subdir] '*.*'
|
||||
(../src/another/sub/dir) [src/another/sub/dir] '*.*'
|
||||
(../lib/eastl) [lib/eastl] '*.*'
|
||||
(../lib/eastl/include/EABase) [lib/eastl/include/EABase] '*.*'
|
||||
... etc ...
|
||||
... etc ...
|
||||
|
||||
This kind of MKB source file listing ensures that under Visual Studio
|
||||
and Xcode that your project, as shown in the IDE, will have it's
|
||||
source files listed under appropriate folders/groups exactly like how
|
||||
your source files are organized on disk.
|
||||
|
||||
The **mkb_generate** script does not do any other preprocessing of the
|
||||
MKB file template. It only scans for the %%SOURCE_FILES%% tag and
|
||||
replaces it. Every other line is copied to the output MKB file as-is.
|
||||
|
||||
**mkb_generate** will overwrite the existing MKB file if one is there.
|
||||
|
||||
# Configuration
|
||||
|
||||
At the top of the **mkb_generate** script there are some config
|
||||
variables that can and should be modified to your needs.
|
||||
|
||||
+ **DIR\_SOURCES** is a space-separated list of directories that are to be scanned for source files. All child directories of the directories specified here will also be scanned and do not need to be individually specified.
|
||||
+ **DIR\_SOURCES\_EXCLUDE** is a space-separated list of directories that are contained somewhere in DIR_SOURCES that should *not* be included in the output MKB file listing. Any child directories of these will also be excluded.
|
||||
+ **PROJECT\_NAME** is the name of the project. This will become the name of the output MKB file. For example, if this is set to "MyProject" the output MKB file will be MyProject.mkb. By default, PROJECT\_NAME will be automatically set based on a specific assumption about the way the project is structured. More on this below.
|
||||
|
||||
The rest of the config variables probably don't need to be modified.
|
||||
|
||||
# How PROJECT_NAME is Automatically Set
|
||||
|
||||
This is largely based on my own personal conventions and may not
|
||||
apply to everyone. If that is the case, you can just manually set
|
||||
the value to whatever you need.
|
||||
|
||||
By default, the **mkb_generate** script will automatically set the
|
||||
**PROJECT_NAME** value based on an assumed directory structure
|
||||
for your project, similar to the one shown below:
|
||||
|
||||
/some/directory/containing
|
||||
/ProjectName
|
||||
/src [all source files, cpp/c/h]
|
||||
/lib [third-party library source files, cpp/c/h]
|
||||
/assets [textures, audio, models, etc]
|
||||
/marmalade [marmalade stuff: mkb_generate, output MKB file, ICFs, build output, etc]
|
||||
|
||||
which would mean that the **mkb_generate** script is located at:
|
||||
|
||||
/some/directory/containing/ProjectName/marmalade/mkb_generate
|
||||
|
||||
In this kind of structure, **PROJECT_NAME** would be set to
|
||||
"ProjectName" because mkb_generate is located at
|
||||
ProjectName/marmalade/mkb_generate.
|
215
mkb_generate
Executable file
215
mkb_generate
Executable file
|
@ -0,0 +1,215 @@
|
|||
#!/bin/bash
|
||||
|
||||
#----- VARIABLES + CONFIG ------------------------------------------------------
|
||||
|
||||
# List of directories (relative to the directory this script is in) to include
|
||||
# in the MKB's source directory listing. Any subdirectories of the directories
|
||||
# listed will be included automatically as well.
|
||||
# NOTE: The "hasSources" function below is hardcoded to look for source files
|
||||
# with specific file extensions: .cpp, .cc, .c, .h, and .hpp
|
||||
DIR_SOURCES=( ../src )
|
||||
|
||||
# List of directories (relative to the directory this script is in) that are
|
||||
# contained in one of the directories listed in DIR_SOURCES (e.g. a subdirectory
|
||||
# somewhere in one of them) to be excluded from the MKB's source directory
|
||||
# listing. Any subdirectories under these excluded directories will also be
|
||||
# excluded.
|
||||
DIR_SOURCES_EXCLUDE=( )
|
||||
|
||||
# Automatically try to figure out a suitable project name value.
|
||||
# NOTE: PROJECT_NAME is set assuming that the parent directory to the one that
|
||||
# this script is contained in has a name that is suitable to be used for
|
||||
# this "project name" value.
|
||||
#
|
||||
# e.g. it assumes that this script is located at something like:
|
||||
#
|
||||
# /home/user/projects/PROJECT_NAME/marmalade/mkb_generate
|
||||
# ^^^^^^^^^^^^
|
||||
#
|
||||
# and so PROJECT_NAME will be set accordingly.
|
||||
#
|
||||
PROJECT_NAME=$(pushd . > /dev/null; cd ..; basename $(pwd); popd > /dev/null)
|
||||
|
||||
# Or, manually set it (comment above line and uncomment this next one)
|
||||
#PROJECT_NAME=MyProjectName
|
||||
|
||||
# You shouldn't normally need to change the rest of these ...
|
||||
MKB_TEMPLATE=./mkb_template.txt
|
||||
MKB_OUTPUT_FILE=./$PROJECT_NAME.mkb
|
||||
TEMP_SOURCE_DIR_LIST_FILE=./temp_sources_list
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
# when executed via the OS X Finder, the working directory will likely not be
|
||||
# correct -- this fixes that (working directory == directory this script is in)
|
||||
cd "$(dirname "$0")"
|
||||
|
||||
|
||||
|
||||
#----- FUNCTIONS ---------------------------------------------------------------
|
||||
|
||||
function isSourceDirExcluded()
|
||||
{
|
||||
check_dir=$1
|
||||
for i in "${DIR_SOURCES_EXCLUDE[@]}"
|
||||
do
|
||||
# check passed directory against each directory listed in the excludes list
|
||||
# this just makes sure the beginning is the same (so sub dirs, etc. will still match)
|
||||
if [[ $check_dir = $i* ]]; then
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
function hasSources()
|
||||
{
|
||||
check_dir=$1
|
||||
|
||||
# don't bother checking if the directory has sources if this directory
|
||||
# is to be excluded...
|
||||
if isSourceDirExcluded $check_dir; then
|
||||
return 1
|
||||
else
|
||||
# it's not excluded, now we can check for source files
|
||||
if [ `find $check_dir/*.cpp $check_dir/*.cc $check_dir/*.c $check_dir/*.h $check_dir/*.hpp -type f -mindepth 0 2> /dev/null | wc -l` != 0 ]; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function writeTempListOfSourceDirectories()
|
||||
{
|
||||
# for each of the root source directories specified ...
|
||||
for i in "${DIR_SOURCES[@]}"
|
||||
do
|
||||
# ... and then for each sub dir in this root source directory ...
|
||||
find $i -type d | while read -r dir
|
||||
do
|
||||
# ... check if this sub dir has cpp/c/h files in it ...
|
||||
if hasSources $dir; then
|
||||
# ... and if so, write a line for it out to the temp file
|
||||
# (this written line matches syntax appropriate for an MKB "files" section
|
||||
# directory wildcard)
|
||||
dir_name=${dir#../} # strip "../" from the beginning
|
||||
echo "($dir) [$dir_name] '*.*'" >> $TEMP_SOURCE_DIR_LIST_FILE
|
||||
fi
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
function writeOutMkb()
|
||||
{
|
||||
# this keeps tab characters in the lines we read
|
||||
oldifs="$IFS"
|
||||
IFS=""
|
||||
|
||||
# read each line from the MKB template and copy it to the output file
|
||||
cat $MKB_TEMPLATE | while read template_line; do
|
||||
|
||||
############################################
|
||||
# look for template placeholders
|
||||
# (right now, we assume the template placeholders occur on a line all by themselves)
|
||||
|
||||
# source directory list
|
||||
if [[ $template_line = *%%SOURCE_FILES%%* ]]; then
|
||||
# read the previous generated temp source dir list file and copy it
|
||||
# into the mkb output line by line as-is
|
||||
cat $TEMP_SOURCE_DIR_LIST_FILE | while read source_dir_list_line; do
|
||||
echo "$source_dir_list_line" >> $MKB_OUTPUT_FILE
|
||||
done
|
||||
|
||||
############################################
|
||||
|
||||
# nothing special on this line, just copy it to the output as-is...
|
||||
else
|
||||
echo "$template_line" >> $MKB_OUTPUT_FILE
|
||||
fi
|
||||
done
|
||||
|
||||
# reset this when we're done
|
||||
IFS="$oldifs"
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
# ----- CONFIG AND FILE STATE SANITY CHECKING ----------------------------------
|
||||
|
||||
# make sure some source directories were specified above
|
||||
if [ ${#DIR_SOURCES[@]} == 0 ]; then
|
||||
echo "ERROR: No source directories specified."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# make sure each source directory exists
|
||||
for source_dir in "${DIR_SOURCES[@]}"
|
||||
do
|
||||
if [ ! -d $source_dir ]; then
|
||||
echo "ERROR: Source directory \"$source_dir\" does not exist."
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
# make sure each excluded source directory exists
|
||||
for excluded_source_dir in "${DIR_SOURCES_EXCLUDE[@]}"
|
||||
do
|
||||
if [ ! -d $excluded_source_dir ]; then
|
||||
echo "ERROR: Excluded source directory \"$excluded_source_dir\" does not exist."
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
# make sure MKB input template file exists
|
||||
if [ ! -f $MKB_TEMPLATE ]; then
|
||||
echo "ERROR: MKB template file does not exist."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# if the temp source dir list file exists, delete it
|
||||
if [ -f $TEMP_SOURCE_DIR_LIST_FILE ]; then
|
||||
rm $TEMP_SOURCE_DIR_LIST_FILE
|
||||
fi
|
||||
|
||||
# if the output MKB file exists, delete it
|
||||
if [ -f $MKB_OUTPUT_FILE ]; then
|
||||
rm $MKB_OUTPUT_FILE
|
||||
fi
|
||||
|
||||
|
||||
|
||||
#----- MAIN SCRIPT PROCESSING --------------------------------------------------
|
||||
|
||||
writeTempListOfSourceDirectories
|
||||
|
||||
if [ ! -f $TEMP_SOURCE_DIR_LIST_FILE ]; then
|
||||
echo 'ERROR: Problem occurred while scanning for source file directories.'
|
||||
echo 'Make sure the directories listed in DIR_SOURCE have files in them and that they are not all being excluded by DIR_SOURCES_EXCLUDE.'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
writeOutMkb
|
||||
|
||||
if [ ! -f $MKB_OUTPUT_FILE ]; then
|
||||
echo 'ERROR: Problem occurred while writing out new MKB file.'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
#----- CLEANUP -----------------------------------------------------------------
|
||||
|
||||
# if the temp source dir list file exists, delete it
|
||||
if [ -f $TEMP_SOURCE_DIR_LIST_FILE ]; then
|
||||
rm $TEMP_SOURCE_DIR_LIST_FILE
|
||||
fi
|
||||
|
||||
#-------------------------------------------------------------------------------
|
18
mkb_template.txt
Normal file
18
mkb_template.txt
Normal file
|
@ -0,0 +1,18 @@
|
|||
debug_define DEBUG
|
||||
|
||||
files
|
||||
{
|
||||
%%SOURCE_FILES%%
|
||||
}
|
||||
|
||||
includepaths
|
||||
{
|
||||
}
|
||||
|
||||
assets
|
||||
{
|
||||
(../assets)
|
||||
.
|
||||
}
|
||||
|
||||
option s3e-data-dir=../assets
|
Reference in a new issue