HasFunction.js 948 B

1234567891011121314151617181920212223242526272829303132333435
  1. var nThen = require("nthen");
  2. var Fs = require("fs");
  3. module.exports.check = function (builder, func, ldflags, callback) {
  4. var file = builder.tmpFile();
  5. var outputFile = builder.tmpFile();
  6. nThen(function (waitFor) {
  7. Fs.writeFile(file, "int main() { " + func + "(); }", waitFor(function (err, ret) {
  8. if (err) {
  9. waitFor.abort();
  10. callback(err);
  11. }
  12. }));
  13. }).nThen(function (waitFor) {
  14. var flags = [];
  15. flags.push.apply(flags, ["-x", "c", "-o", outputFile, file]);
  16. flags.push.apply(flags, ldflags);
  17. builder.cc(flags, waitFor(function (ret, out, err) {
  18. if (ret && /undefined reference/.test(err)) {
  19. callback(undefined, false);
  20. } else if (ret) {
  21. callback(new Error(err));
  22. } else {
  23. callback(undefined, true);
  24. }
  25. }));
  26. });
  27. };