| 1 | /*
|
|---|
| 2 | -----BEGIN QCMOD-----
|
|---|
| 3 | name: the XScreenSaver extension
|
|---|
| 4 | -----END QCMOD-----
|
|---|
| 5 | */
|
|---|
| 6 |
|
|---|
| 7 | //----------------------------------------------------------------------------
|
|---|
| 8 | // qc_xss
|
|---|
| 9 | //----------------------------------------------------------------------------
|
|---|
| 10 | class qc_xss : public ConfObj
|
|---|
| 11 | {
|
|---|
| 12 | public:
|
|---|
| 13 | enum { OK, NEEDLIB, FAIL };
|
|---|
| 14 | qc_xss(Conf *c) : ConfObj(c)
|
|---|
| 15 | {
|
|---|
| 16 | }
|
|---|
| 17 |
|
|---|
| 18 | ~qc_xss()
|
|---|
| 19 | {
|
|---|
| 20 | remove("xssprobe_test.c");
|
|---|
| 21 | remove("xssprobe_test.o");
|
|---|
| 22 | remove("xssprobe_test");
|
|---|
| 23 | }
|
|---|
| 24 |
|
|---|
| 25 | QString name() const
|
|---|
| 26 | {
|
|---|
| 27 | return "the XScreenSaver extension";
|
|---|
| 28 | }
|
|---|
| 29 |
|
|---|
| 30 | QString shortname() const { return "xss"; }
|
|---|
| 31 |
|
|---|
| 32 | int do_write()
|
|---|
| 33 | {
|
|---|
| 34 | char *xsstest =
|
|---|
| 35 | "#include<X11/Xlib.h>\n"
|
|---|
| 36 | "#include<X11/Xutil.h>\n"
|
|---|
| 37 | "#include<X11/extensions/scrnsaver.h>\n"
|
|---|
| 38 | "\n"
|
|---|
| 39 | "int main()\n"
|
|---|
| 40 | "{\n"
|
|---|
| 41 | " XScreenSaverQueryExtension(NULL, NULL, NULL);\n"
|
|---|
| 42 | " return 0;\n"
|
|---|
| 43 | "}\n";
|
|---|
| 44 |
|
|---|
| 45 | FILE *f;
|
|---|
| 46 | f = fopen("xssprobe_test.c", "w");
|
|---|
| 47 | if(!f)
|
|---|
| 48 | return 0;
|
|---|
| 49 | fwrite(xsstest, strlen(xsstest), 1, f);
|
|---|
| 50 | fclose(f);
|
|---|
| 51 |
|
|---|
| 52 | return 1;
|
|---|
| 53 | }
|
|---|
| 54 |
|
|---|
| 55 | int do_compile()
|
|---|
| 56 | {
|
|---|
| 57 | QString inc = conf->expandIncludes(conf->qvar("QMAKE_INCDIR_X11"));
|
|---|
| 58 | QString str = conf->qvar("QMAKE_CC") + " -c " + inc + " xssprobe_test.c -o xssprobe_test.o";
|
|---|
| 59 | int r = conf->doCommand(str);
|
|---|
| 60 | if(r == 0)
|
|---|
| 61 | return 1;
|
|---|
| 62 | else
|
|---|
| 63 | return 0;
|
|---|
| 64 | }
|
|---|
| 65 |
|
|---|
| 66 | int do_link()
|
|---|
| 67 | {
|
|---|
| 68 | QString lib = conf->expandLibs(conf->qvar("QMAKE_LIBDIR_X11"));
|
|---|
| 69 | QString inc = conf->expandIncludes(conf->qvar("QMAKE_INCDIR_X11"));
|
|---|
| 70 | QString str = conf->qvar("QMAKE_CC") + " xssprobe_test.o -o xssprobe_test " + lib + ' ' + conf->qvar("QMAKE_LIBS_X11");
|
|---|
| 71 | int r = conf->doCommand(str);
|
|---|
| 72 | if(r == 0)
|
|---|
| 73 | return 1;
|
|---|
| 74 | else
|
|---|
| 75 | return 0;
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | int do_linkLib()
|
|---|
| 79 | {
|
|---|
| 80 | QString lib = conf->expandLibs(conf->qvar("QMAKE_LIBDIR_X11"));
|
|---|
| 81 | QString inc = conf->expandIncludes(conf->qvar("QMAKE_INCDIR_X11"));
|
|---|
| 82 | QString str = conf->qvar("QMAKE_CC") + " xssprobe_test.o -o xssprobe_test " + lib + ' ' + conf->qvar("QMAKE_LIBS_X11") + " -lXss";
|
|---|
| 83 | int r = conf->doCommand(str);
|
|---|
| 84 | if(r == 0)
|
|---|
| 85 | return 1;
|
|---|
| 86 | else
|
|---|
| 87 | return 0;
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | int do_all()
|
|---|
| 91 | {
|
|---|
| 92 | if(!do_write())
|
|---|
| 93 | return FAIL;
|
|---|
| 94 | if(!do_compile())
|
|---|
| 95 | return FAIL;
|
|---|
| 96 | if(do_link())
|
|---|
| 97 | return OK;
|
|---|
| 98 | if(do_linkLib())
|
|---|
| 99 | return NEEDLIB;
|
|---|
| 100 | return FAIL;
|
|---|
| 101 | }
|
|---|
| 102 |
|
|---|
| 103 | bool exec()
|
|---|
| 104 | {
|
|---|
| 105 | int r = do_all();
|
|---|
| 106 | if(r == OK) {
|
|---|
| 107 | conf->addDefine("HAVE_XSS");
|
|---|
| 108 | return true;
|
|---|
| 109 | }
|
|---|
| 110 | else if(r == NEEDLIB) {
|
|---|
| 111 | conf->addDefine("HAVE_XSS");
|
|---|
| 112 | conf->addLib("-lXss");
|
|---|
| 113 | return true;
|
|---|
| 114 | }
|
|---|
| 115 | }
|
|---|
| 116 | };
|
|---|