HasFunction.js 940 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, ldflags);
  16. flags.push.apply(flags, ["-x", "c", "-o", outputFile, file]);
  17. builder.cc(flags, waitFor(function (err, ret) {
  18. if (err && /undefined reference/.test(err.message)) {
  19. callback(undefined, false);
  20. } else if (err) {
  21. callback(err);
  22. } else {
  23. callback(undefined, true);
  24. }
  25. }));
  26. });
  27. };