diff --git a/.gitingore b/.gitingore new file mode 100644 index 0000000..e660fd9 --- /dev/null +++ b/.gitingore @@ -0,0 +1 @@ +bin/ diff --git a/bin/echoserv b/bin/echoserv new file mode 100755 index 0000000..9e5154b Binary files /dev/null and b/bin/echoserv differ diff --git a/bin/echoserv.dSYM/Contents/Info.plist b/bin/echoserv.dSYM/Contents/Info.plist new file mode 100644 index 0000000..4531c23 --- /dev/null +++ b/bin/echoserv.dSYM/Contents/Info.plist @@ -0,0 +1,20 @@ + + + + + CFBundleDevelopmentRegion + English + CFBundleIdentifier + com.apple.xcode.dsym.echoserv + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + dSYM + CFBundleSignature + ???? + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + + diff --git a/bin/echoserv.dSYM/Contents/Resources/DWARF/echoserv b/bin/echoserv.dSYM/Contents/Resources/DWARF/echoserv new file mode 100644 index 0000000..be3f0c9 Binary files /dev/null and b/bin/echoserv.dSYM/Contents/Resources/DWARF/echoserv differ diff --git a/example/build.py b/example/build.py deleted file mode 100755 index 7a49e21..0000000 --- a/example/build.py +++ /dev/null @@ -1,65 +0,0 @@ -#!/usr/bin/python2.7 -import os, sys - -COMPILER = "gcc" -SRC_DIR = "../src" -INCLUDE_DIR = "../src" -BIN_DIR = "../bin" -BIN_NAME = False -CFLAGS = ["-O3", "-Wall", "-Wextra", "--std=c89", "-pedantic"] -DLIBS = ["ws2_32"] if os.name == "nt" else [] -DEFINES = [] - - -def strformat(fmt, var): - for k in var: - fmt = fmt.replace("{%s}" % str(k), var[k]) - return fmt - - -def listdir(path): - return [os.path.join(dp, f) for dp, dn, fn in os.walk(path) for f in fn] - - -def main(): - os.chdir(sys.path[0]) - - if len(sys.argv) < 2: - print "usage: build.py c_file" - sys.exit() - - global BIN_NAME - if not BIN_NAME: - BIN_NAME = sys.argv[1].replace(".c", ".exe" if os.name == "nt" else "") - - if not os.path.exists(BIN_DIR): - os.makedirs(BIN_DIR) - - cfiles = filter(lambda x:x.endswith((".c", ".C")), listdir(SRC_DIR)) - cfiles.append(sys.argv[1]) - - cmd = strformat( - "{compiler} {flags} {include} {def} -o {outfile} {srcfiles} {libs} {argv}", - { - "compiler" : COMPILER, - "flags" : " ".join(CFLAGS), - "include" : "-I" + INCLUDE_DIR, - "def" : " ".join(map(lambda x: "-D " + x, DEFINES)), - "outfile" : BIN_DIR + "/" + BIN_NAME, - "srcfiles" : " ".join(cfiles), - "libs" : " ".join(map(lambda x: "-l" + x, DLIBS)), - "argv" : " ".join(sys.argv[2:]) - }) - - print "compiling..." - res = os.system(cmd) - - if not res: - print(BIN_DIR + "/" + BIN_NAME) - - print("done" + (" with errors" if res else "")) - - - -if __name__ == "__main__": - main() diff --git a/example/build.rb b/example/build.rb new file mode 100755 index 0000000..0141d5a --- /dev/null +++ b/example/build.rb @@ -0,0 +1,60 @@ +#!/usr/local/bin/ruby + +require 'yaml' +include Gem + +def command_format(cmd, var) + var.each_pair do |key, value| + cmd = cmd.gsub! "{#{key.to_s}}", value + end + return cmd +end + +Dir.chdir __dir__ + +data = File.read 'config.yml' +config = YAML.load data, symbolize_names: true + +if ARGF.argv.count < 1 + puts "Usage: build.rb [file]" + exit +end + +program_ext = Platform.local.os == "mswin32" ? '.exe' : '' +program_name = ARGF.argv[0].gsub '.c', program_ext + +unless Dir.exist? config[:bin] + Dir.mkdir config[:bin] +end + +source_files = Dir.entries(config[:source]).select { |e| e.end_with?('.c', '.C') } +source_files.map! {|e| "#{config[:source]}/#{e}"} +source_files << ARGF.argv[0] + +libraries = config[:dlibs].select do |e| + e.keys.include?(Platform.local.os.to_sym) +end + +unless libraries.empty? + common = config[:dlibs].select { |e| e.keys.include?(:common)}.first + libraries << common + libraries.map! { |e| e.values }.flatten! +end + +command = command_format( + "{compiler} {flags} {include} -o {out} {source} {libs} {argv}", + { + compiler: config[:compiler], + flags: config[:cflags].map \ + { |e| !e.start_with?('-') ? e.prepend('-') : e }.join(' '), + include: "-I#{config[:include]}", + out: "#{config[:bin]}/#{program_name}", + source: source_files.join(' '), + libs: libraries.map {|e| "-l#{e}"}.join(' '), + argv: ARGF.argv.count > 1 ? ARGF.argv[1..ARGF.argv.count].join(' ') : "" + } +) + +puts "Compiling #{program_name}..." +`#{command}` +puts "Done" diff --git a/example/config.yml b/example/config.yml new file mode 100644 index 0000000..4bbf45a --- /dev/null +++ b/example/config.yml @@ -0,0 +1,15 @@ +compiler: clang + +source: ../src +include: ../src +bin: ../bin + +cflags: + - 'O1' + - Wall + - std=c99 + - -g + +dlibs: + - mswin32: + - ws2_32