txlyre 2 gadi atpakaļ
vecāks
revīzija
f6196d45b1
3 mainītis faili ar 92 papildinājumiem un 15 dzēšanām
  1. 75 0
      makeshot/C
  2. 0 5
      makeshot/Config
  3. 17 10
      makeshot/Recipe

+ 75 - 0
makeshot/C

@@ -0,0 +1,75 @@
+$_CC = defined("CC")? CC: "cc";
+
+$_CFLAGS = array();
+$_LDFLAGS = array();
+
+$_SOURCES = array();
+$_OBJECTS = array();
+
+$_OUT = defined("OUT")? OUT: defined("OUTPUT")? OUTPUT: "out";
+
+if (defined("CFLAGS"))
+  $_CFLAGS = arrcat($_CFLAGS, words(CFLAGS));
+
+if (defined("LDFLAGS"))
+  $_LDFLAGS = arrcat($_LDFLAGS, words(LDFLAGS));
+
+function pkg_config() {
+  global $_CFLAGS, $_LDFLAGS;
+
+  foreach (getargs(), $name) {
+    $_CFLAGS = arrcat($_CFLAGS, words(rtrim(`pkg-config --cflags $name`)));
+    $_LDFLAGS = arrcat($_LDFLAGS, words(rtrim(`pkg-config --libs $name`)));
+  }
+}
+
+function sources() {
+  global $_SOURCES;
+
+  foreach (getargs(), $source) {
+    if (!isarray($source))
+      $source = words($source);
+
+    $_SOURCES = arrcat($_SOURCES, $source);  
+  }
+}
+
+function flags() {
+  global $_CFLAGS;
+
+  foreach (getargs(), $flag) {
+    if (!isarray($flag))
+      $flag = words($flag);
+
+    $_CFLAGS = arrcat($_CFLAGS, $flag);  
+  }
+}
+
+function compile() {
+  global $_CC, $_CFLAGS, $_SOURCES, $_OBJECTS;
+
+  foreach ($_SOURCES, $source) {
+    $object = replace($source, ".c", ".o");
+    $cflags = unwords($_CFLAGS);
+
+    if (!isfile($object) || mtime($source) > mtime($object))
+      `$_CC $cflags -c $source`;
+
+    push($_OBJECTS, $object);
+  }
+}
+
+function link() {
+  global $_CC, $_LDFLAGS, $_OBJECTS, $_OUT;
+
+  foreach ($_OBJECTS, $object) {
+    if (!isfile($_OUT) || mtime($_OUT) < mtime($object)) {
+      $objects = unwords($_OBJECTS);
+      $ldflags = unwords($_LDFLAGS);
+
+      `$_CC $ldflags $objects -o $_OUT`;
+
+      break;
+    }
+  }
+}

+ 0 - 5
makeshot/Config

@@ -1,5 +0,0 @@
-$CC = "clang";
-$CFLAGS = "-w -c -Os " . rtrim(`pkg-config --cflags pango`);
-$LDFLAGS = "-lcairo -lpangocairo-1.0 -lpango-1.0 -lgobject-2.0";
-$SOURCES = glob("*.c");
-$OUT = "makeshot";

+ 17 - 10
makeshot/Recipe

@@ -1,20 +1,27 @@
 <recipe>
-  <script src="Config"></script>
+  <script src="C">
+    define("OUTPUT", "makeshot");
+  </script>
 
-  <rule>
-    $objects = array();
-    foreach ($SOURCES, $k: $source) {
-      `$CC $CFLAGS $source`;
+  <rule name="debug">
+    flags("-ggdb -Wall");
+  </rule>
 
-      push($objects, replace($source, ".c", ".o"));
-    }
+  <rule name="release">
+    flags("-Os -w");
+  </rule>
 
-    $objects = unwords($objects);
+  <rule name="rebuild" requires="clear" then="build"/>
 
-    `$CC $LDFLAGS $objects -o $OUT`;
+  <rule name="build" then="link">
+    sources("makeshot.c");
+    pkg_config("cairo", "pangocairo");
   </rule>
 
+  <rule name="link" onentry="link()" requires="compile"/>
+  <rule name="compile" onentry="compile()"/>
+
   <rule name="clear">
-    `rm -rf *.o makeshot`;
+    `rm -rf *.o $_OUT`;
   </rule>
 </recipe>