Some updates after having put more thought into it.
xmk should make use of a build directory. Invoking the program with -i
or --init
should build that directory structure (xmk.d
) based on the targets and platforms defined in the xmkfile.
The program should look for a file with the name xmkfile
in current directory by default. If it can't find the file it will look for it in ./xmk.d/
. But it's possible to invoke a specified xmkfile with the -f
option. e.g.
xmk -f xmk.d/my_target.xmk
It's proven useful having scripts that write header files. So I decided it would be neat for the build system to make that explicit (rather than have scripts do the writing to files internally).
The consideration that follows is that helper functions to write script output to source files (while backing them up) might be equally handy.
I realized that the current concept entirely lacks the recursive behavior that makes Make elegant.
All things considered I might be best off just writing a library in Ruby after all instead of implementing a parser for a custom language.
Anyways, here's the example xmkfile reflecting my current ideas
001 default(-t my_application -p linux -s debug)
002 list[] src = files(src/*.c, src/scene/*.c, src/engine/*.c)
003 src = filesr(src, *.c)
004 var obj_dir = obj/
005 var cc
006 var bin = bin/
007 list[] inc = -Iinclude
008 list[] lib
009 list[] cflag
010 list[] sflag
011 list[] dep
012
013 if debug
014 cflag << -g, -Wall, -Wno-switch, -Wno-unused-label
015 sflag << -DDEBUG
016 { echo Debug Mode! } print if verbose
017 { my_cmd }
018 end
019
020 @my_application(0.2.0)
021 hedr h = header_create(my_header.h, xmk.d/include/$@)
022 for (platforms($@))
023 process($1)
024 end
025 end
026
027 action linux
028 var v = version(-release)
029 lib << list({ `sdl2-config --libs` }, ), lSDL2_image, lSDL2_mixer
030 inc << -Imruby-2.1.0/include
031 obj_dir << linux
032 cc = gcc
033 bin << linux
034 if debug
035 h << #define VERSION $(version(-release))
036 v = version(-debug)
037 bin << -debug
038 else
039 h << #define VERSION $(version(-debug))
040 end
041 inc << headers() // expands to list of header files for this target-platform combination
042 // with -i prefix
043 bin << $@-$!-$(v)
044 list[] obj = objects(src, obj_dir)
045 for(src, obj)
046 dep = dependencies({ $(cc) -M $1 $(cflags) $(inc) })
047 if dep_failed($2, dep)
048 { $(cc) -c $1 -o $2 $(cflags) $(inc) } print if verbose
049 end
050 end
051 { $(cc) -o $(bin) $($obj, ) $(lib) } print if verbose
052
053 end
054