main_build.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include "aFun.hpp"
  2. #include "main_build.hpp"
  3. int buildFileOutput(FilePath out, FilePath in, bool force) {
  4. if (!force) {
  5. time_t time_1 = getFileMTime(in);
  6. time_t time_2 = getFileMTime(out);
  7. if (time_1 == 0 && time_2 == 0) {
  8. writeErrorLog(aFunlangLogger, "Source not exists: %s", in);
  9. printf_stderr(0, "%s [%s]\n", HT_aFunGetText(build_src_not_exists_e, "Source not exists"), in);
  10. return -1;
  11. }
  12. if (time_2 >= time_1) {
  13. writeWarningLog(aFunlangLogger, "Source already build %s", in);
  14. printf_stderr(0, "%s (%s), %s\n", HT_aFunGetText(build_src_already, "Source already build"), in, HT_aFunGetText(build_use_f, "use --force to build again"));
  15. return 0;
  16. }
  17. }
  18. writeInfoLog(aFunlangLogger, "Build %s, %s", in, out);
  19. printf_stdout(0, "%s (%s -> %s)\n", HT_aFunGetText(build_file, "Source will be build"), in, out);
  20. return buildFile(out, in);
  21. }
  22. int buildFileToPath(FilePath path, FilePath in, bool force) {
  23. char *name = getFileName(in);
  24. char *out = joinPath(path, name, ".aub");
  25. int res = buildFileOutput(out, in, force);
  26. free(name);
  27. free(out);
  28. return res;
  29. }
  30. int buildFileToSelf(FilePath in, bool force) {
  31. char *path = getFileNameWithPath(in);
  32. char *out = strJoin(path, ".aub", true, false);
  33. int res = buildFileOutput(out, in, force);
  34. free(out);
  35. return res;
  36. }