Construct 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. # -*- mode: perl -*-
  2. # cons script for cgame game q3_ui ui .so and .qvm builds
  3. #
  4. # Oct. 2001 TTimo <ttimo@idsoftware.com>
  5. #
  6. # the top directory is
  7. # <config>-<cpu>-<OS>-<libc version>
  8. # where:
  9. # <config> is "debug" or "release"
  10. # <cpu> is "x86" or "ppc"
  11. # <OS> is "Linux" "BSD" "IRIX" etc.
  12. # <libc version> is major.minor of libc config
  13. # source the compiler version utility
  14. BEGIN {
  15. push @INC, './unix';
  16. }
  17. use Cons_gcc;
  18. # defaults
  19. $config = 'debug';
  20. $do_smp = 1;
  21. $do_masterserver = 0;
  22. $do_authserver = 0;
  23. $do_authport = 0;
  24. $do_setup = 0;
  25. $do_bspc = 0;
  26. $do_sdk = 0;
  27. $do_pk3 = 0;
  28. # those are exported
  29. $DO_WIN32 = 0;
  30. $NO_VM = 0;
  31. $NO_SO = 0;
  32. $CC='gcc';
  33. $CXX='g++';
  34. # detect an sdk build (don't attempt client build and other things)
  35. if ( -r 'unix/Conscript-client' )
  36. {
  37. $no_core = 0;
  38. }
  39. else
  40. {
  41. $no_core = 1;
  42. }
  43. # detection of CPU type
  44. $cpu = `uname -m`;
  45. chop ($cpu);
  46. if ($cpu +~ /i?86/)
  47. {
  48. $cpu = 'x86';
  49. }
  50. # OS
  51. $OS = `uname`;
  52. chop ($OS);
  53. # hacky win32 detection and win32 specifics code
  54. if ($OS =~ CYGWIN)
  55. {
  56. $DO_WIN32 = 1;
  57. }
  58. else
  59. {
  60. # libc .. do the little magic!
  61. $libc_cmd = '/lib/libc.so.6 |grep "GNU C "|grep version|awk -F "version " \'{ print $2 }\'|cut -b -3';
  62. $libc = `$libc_cmd`;
  63. chop ($libc);
  64. }
  65. if ($DO_WIN32 eq 1)
  66. {
  67. print("Win32 build\n");
  68. $config = $ARGV[0];
  69. # TODO: option to override $Q3BASE from command line
  70. $Q3BASE = $ENV{Q3BASE}; # FIXME: this doesn't play nice with cygwin path syntax
  71. print("\$Q3BASE: $Q3BASE\n");
  72. if($config eq 'debug')
  73. {
  74. $DIR = 'Debug';
  75. system("cp -v $DIR/quake3.exe \$Q3BASE");
  76. system("cp -v $DIR/cgamex86.dll $DIR/qagamex86.dll $DIR/uix86.dll \$Q3BASE/baseq3");
  77. }
  78. elsif ($config eq 'debug-TA')
  79. {
  80. $DIR = 'Debug_TA';
  81. system("cp -v $DIR/quake3.exe \$Q3BASE");
  82. system("cp -v $DIR/cgamex86.dll $DIR/qagamex86.dll $DIR/uix86.dll \$Q3BASE/missionpack");
  83. }
  84. elsif($config eq 'release-TA')
  85. {
  86. $DIR = 'Release_TA';
  87. # spank!
  88. system("./spank.sh");
  89. system("cp -v $DIR/quake3.exe \$Q3BASE");
  90. }
  91. else
  92. {
  93. printf("ERROR: no config option (debug debug-TA release-TA)");
  94. exit;
  95. }
  96. # copy selected stuff to shared media
  97. $DESTDIR='/cygdrive/e/incoming/Id/q3-1.32';
  98. system("cp -v $DIR/quake3.exe $DESTDIR");
  99. system("cp -v /cygdrive/e/Q3SetupMedia/quake3/CHANGES-1.32.txt $DESTDIR");
  100. exit;
  101. }
  102. if(@ARGV gt 0)
  103. {
  104. foreach $cmdopt (@ARGV)
  105. {
  106. if(lc($cmdopt) eq 'release')
  107. {
  108. $config = 'release';
  109. next;
  110. }
  111. elsif(lc($cmdopt) eq 'debug')
  112. {
  113. $config = 'debug';
  114. next;
  115. }
  116. elsif(lc($cmdopt) eq 'novm')
  117. {
  118. $NO_VM = 1;
  119. next;
  120. }
  121. elsif(lc($cmdopt) eq 'noso')
  122. {
  123. $NO_SO = 1;
  124. next;
  125. }
  126. elsif(lc($cmdopt) eq 'nosmp')
  127. {
  128. $do_smp = 0;
  129. next;
  130. }
  131. elsif(lc($cmdopt) =~ 'master_server=.*')
  132. {
  133. $do_masterserver = 1;
  134. $master_server = lc($cmdopt);
  135. $master_server =~ s/master_server=(.*)/\1/;
  136. next;
  137. }
  138. elsif(lc($cmdopt) =~ 'auth_server=.*')
  139. {
  140. $do_authserver = 1;
  141. $auth_server = lc($cmdopt);
  142. $auth_server =~ s/auth_server=(.*)/\1/;
  143. next;
  144. }
  145. elsif(lc($cmdopt) =~ 'auth_port=.*')
  146. {
  147. $do_authport = 1;
  148. $auth_port = lc($cmdopt);
  149. $auth_port =~ s/auth_port=(.*)/\1/;
  150. next;
  151. }
  152. elsif(lc($cmdopt) =~ 'setup')
  153. {
  154. $do_setup = 1;
  155. next;
  156. }
  157. elsif(lc($cmdopt) =~ 'bspc')
  158. {
  159. $do_bspc = 1;
  160. next;
  161. }
  162. elsif(lc($cmdopt) =~ 'sdk')
  163. {
  164. $do_sdk = 1;
  165. next;
  166. }
  167. elsif(lc($cmdopt) =~ 'pk3')
  168. {
  169. $do_pk3 = 1;
  170. next;
  171. }
  172. elsif(lc($cmdopt) =~ 'gcc=.*')
  173. {
  174. $CC=lc($cmdopt);
  175. $CC =~ s/gcc=(.*)/\1/;
  176. next;
  177. }
  178. elsif(lc($cmdopt) =~ 'g\+\+=.*')
  179. {
  180. $CXX=lc($cmdopt);
  181. $CXX=~s/g\+\+=(.*)/\1/;
  182. next;
  183. }
  184. else
  185. {
  186. # output an error & exit
  187. print("Error\n $0: Unknown command line option: [ $cmdopt ]\n");
  188. system("cons -h");
  189. exit;
  190. }
  191. }
  192. }
  193. if (($do_setup eq 1) && ($config ne 'release'))
  194. {
  195. print("Error\n $0: 'setup' requires 'release'\n");
  196. exit;
  197. }
  198. # sdk
  199. if ($do_sdk eq 1)
  200. {
  201. # extract the Q3 version from q_shared.h
  202. $line = `cat game/q_shared.h | grep Q3_VERSION`;
  203. chomp $line;
  204. $line =~ s/.*Q3\ (.*)\"/$1/;
  205. $Q3_VER = $line;
  206. $SDK_NAME = "linuxq3a-sdk-$Q3_VER.x86.run";
  207. Default "unix/$SDK_NAME";
  208. Export qw( SDK_NAME Q3_VER );
  209. Build 'unix/Conscript-sdk';
  210. return;
  211. }
  212. # build the config directory
  213. $CONFIG_DIR = $config . '-' . $cpu . '-' . $OS . '-' . $libc;
  214. $COMMON_CFLAGS = '-pipe -fsigned-char ';
  215. if ($config eq 'debug')
  216. {
  217. # use -Werror for better QA
  218. $BASE_CFLAGS = $COMMON_CFLAGS . '-g -Wall -Werror -O ';
  219. $BSPC_BASE_CFLAGS = $COMMON_CFLAGS . '-g -O -DLINUX -DBSPC -Dstricmp=strcasecmp ';
  220. }
  221. else
  222. {
  223. $BASE_CFLAGS = $COMMON_CFLAGS . '-DNDEBUG -O6 -mcpu=pentiumpro -march=pentium -fomit-frame-pointer -ffast-math -malign-loops=2 -malign-jumps=2 -malign-functions=2 -fno-strict-aliasing -fstrength-reduce ';
  224. $BSPC_BASE_CFLAGS = $BASE_CFLAGS . '-DLINUX -DBSPC -Dstricmp=strcasecmp ';
  225. }
  226. if ($do_masterserver eq 1)
  227. {
  228. $BASE_CFLAGS .= "-DMASTER_SERVER_NAME=\\\"$master_server\\\" ";
  229. }
  230. if ($do_authserver eq 1)
  231. {
  232. $BASE_CFLAGS .= "-DAUTHORIZE_SERVER_NAME=\\\"$auth_server\\\" ";
  233. }
  234. if ($do_authport eq 1)
  235. {
  236. $BASE_CFLAGS .= "-DPORT_AUTHORIZE=$auth_port ";
  237. }
  238. my @gcc_version = Cons_gcc::get_gcc_version($CC);
  239. print("GCC version: $gcc_version[1] - $gcc_version[2]\n");
  240. # with 2.95 you can link with gcc, this avoids nasty useless libstdc++ dependency
  241. if ($gcc_version[0] eq '2')
  242. {
  243. $LINK = $CC;
  244. } else {
  245. $LINK = $CXX;
  246. }
  247. my @ccache = Cons_gcc::get_ccache();
  248. if ($ccache[0] eq '1')
  249. {
  250. $CC = $ccache[1] . " " . $CC;
  251. $CXX = $ccache[1] . " " . $CXX;
  252. }
  253. print 'cpu : ' . $cpu . "\nOS : " . $OS . "\n";
  254. print "libc: " . $libc . "\n";
  255. print "configured for " . $config . " build\n";
  256. print 'CFLAGS: ' . $BASE_CFLAGS . "\n";
  257. # install config
  258. $INSTALL_BASEDIR='#install';
  259. Default $INSTALL_BASEDIR;
  260. sub build_tools {
  261. system("mkdir qvmtools 2>/dev/null");
  262. if (@_[0] eq 'q3lcc')
  263. {
  264. system("cd ../lcc ; make all ; cp /tmp/lcc ../code/qvmtools/q3lcc ; cp /tmp/rcc ../code/qvmtools/q3rcc ; cp /tmp/cpp ../code/qvmtools/q3cpp");
  265. }
  266. elsif (@_[0] eq 'q3asm')
  267. {
  268. system("cd ../q3asm ; make ; cp q3asm ../code/qvmtools");
  269. }
  270. else
  271. {
  272. printf("build_tools: @_[0] unrecognized command\n");
  273. die;
  274. }
  275. return 1;
  276. }
  277. # build tools
  278. $env_tools = new cons();
  279. Command $env_tools 'qvmtools/q3lcc', '[perl] &build_tools(\'q3lcc\')';
  280. Command $env_tools 'qvmtools/q3asm', '[perl] &build_tools(\'q3asm\')';
  281. if ($do_bspc eq 1)
  282. {
  283. # build bspc
  284. $BUILD_DIR = $CONFIG_DIR . '/bspc';
  285. Link $BUILD_DIR => '.';
  286. $INSTALL_DIR = $INSTALL_BASEDIR . '/utils';
  287. Export qw( BSPC_BASE_CFLAGS BUILD_DIR INSTALL_DIR CC CXX LINK );
  288. Build $BUILD_DIR . '/bspc/Conscript';
  289. }
  290. # build vanilla Q3
  291. $TARGET_DIR='Q3';
  292. $INSTALL_DIR = $INSTALL_BASEDIR . '/baseq3';
  293. $BUILD_DIR = $CONFIG_DIR . '/' . $TARGET_DIR . '/cgame';
  294. Link $BUILD_DIR => '.';
  295. Export qw( BASE_CFLAGS TARGET_DIR INSTALL_DIR NO_VM NO_SO CC CXX LINK );
  296. Build $BUILD_DIR . '/cgame/Conscript';
  297. $BUILD_DIR = $CONFIG_DIR . '/' . $TARGET_DIR . '/game';
  298. Link $BUILD_DIR => '.';
  299. Export qw( BASE_CFLAGS TARGET_DIR INSTALL_DIR NO_VM NO_SO CC CXX LINK );
  300. Build $BUILD_DIR . '/game/Conscript';
  301. $BUILD_DIR = $CONFIG_DIR . '/' . $TARGET_DIR . '/q3_ui';
  302. Link $BUILD_DIR => '.';
  303. Export qw( BASE_CFLAGS TARGET_DIR INSTALL_DIR NO_VM NO_SO CC CXX LINK );
  304. Build $BUILD_DIR . '/q3_ui/Conscript';
  305. # build TA
  306. $TARGET_DIR='TA';
  307. $INSTALL_DIR = $INSTALL_BASEDIR . '/missionpack';
  308. $BUILD_DIR = $CONFIG_DIR . "/" . $TARGET_DIR . '/cgame';
  309. Link $BUILD_DIR => '.';
  310. Export qw( BASE_CFLAGS TARGET_DIR INSTALL_DIR NO_VM NO_SO CC CXX LINK );
  311. Build $BUILD_DIR . '/cgame/Conscript';
  312. $BUILD_DIR = $CONFIG_DIR . "/" . $TARGET_DIR . '/game';
  313. Link $BUILD_DIR => '.';
  314. Export qw( BASE_CFLAGS TARGET_DIR INSTALL_DIR NO_VM NO_SO CC CXX LINK );
  315. Build $BUILD_DIR . '/game/Conscript';
  316. $BUILD_DIR = $CONFIG_DIR . '/' . $TARGET_DIR . '/ui';
  317. Link $BUILD_DIR => '.';
  318. Export qw( BASE_CFLAGS TARGET_DIR INSTALL_DIR NO_VM NO_SO CC CXX LINK );
  319. Build $BUILD_DIR . '/ui/Conscript';
  320. # core
  321. if ($no_core eq 1)
  322. {
  323. return;
  324. }
  325. $INSTALL_DIR = $INSTALL_BASEDIR;
  326. $BUILD_DIR = $CONFIG_DIR . '/core/dedicated';
  327. Link $BUILD_DIR => '.';
  328. $hack = $BASE_CFLAGS; # hit me!
  329. $BASE_CFLAGS .= '-DDEDICATED ';
  330. Export qw( BASE_CFLAGS BUILD_DIR INSTALL_DIR CC CXX LINK );
  331. Build $BUILD_DIR . '/unix/Conscript-dedicated';
  332. $BASE_CFLAGS = $hack;
  333. $TARGETNAME = 'linuxquake3';
  334. $BUILD_DIR = $CONFIG_DIR . '/core/client';
  335. $BASE_LDFLAGS = '';
  336. Link $BUILD_DIR => '.';
  337. Export qw( BASE_CFLAGS BASE_LDFLAGS BUILD_DIR INSTALL_DIR TARGETNAME CC CXX LINK );
  338. Build $BUILD_DIR . '/unix/Conscript-client';
  339. if ($do_smp eq 1)
  340. {
  341. $TARGETNAME = 'linuxquake3-smp';
  342. $BUILD_DIR = $CONFIG_DIR . '/core/client-smp';
  343. $BASE_CFLAGS .= '-DSMP ';
  344. $BASE_LDFLAGS = '-lpthread ';
  345. Link $BUILD_DIR => '.';
  346. Export qw( BASE_CFLAGS BASE_LDFLAGS BUILD_DIR INSTALL_DIR TARGETNAME CC CXX LINK );
  347. Build $BUILD_DIR . '/unix/Conscript-client';
  348. }
  349. if ($NO_VM eq 0 && $do_pk3 eq 1)
  350. {
  351. # build the PK3s
  352. $INSTALL_DIR = $INSTALL_BASEDIR;
  353. $BUILD_DIR = $CONFIG_DIR . '/pk3-builder';
  354. Link $BUILD_DIR => 'unix';
  355. Export qw( INSTALL_DIR BUILD_DIR CONFIG_DIR CC CXX LINK );
  356. Build $BUILD_DIR . '/Conscript-pk3';
  357. }
  358. if ($do_setup eq 1)
  359. {
  360. Link $CONFIG_DIR => '.';
  361. Export qw( INSTALL_BASEDIR );
  362. Build $CONFIG_DIR . '/unix/Conscript-setup';
  363. }
  364. Help
  365. "
  366. Usage: cons [-h] [ -- [release|debug] [novm] [noso] [nosmp] [master_server=<adr>] [auth_server=<adr>] [auth_port=<port>] [pk3] [bspc] [setup] [sdk]]
  367. Default build type is Debug, specifying '-- release' on the
  368. command line builds a Release version (NOTE that this option
  369. only affects the native libraries).
  370. novm: will not build the VMs
  371. noso: will not build the so
  372. below are for core builds only:
  373. nosmp : do not build the SMP-enabled version of the renderer
  374. pk3 : generate the pk3s on the fly (defined in unix/Conscript-pk3)
  375. bspc : build bspc
  376. setup : build setup
  377. sdk : build the mod sdk
  378. "
  379. ;