home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l455 / 1.ddi / MATBIN.DI$ / CMEX.BAT < prev    next >
Encoding:
DOS Batch File  |  1993-03-22  |  11.5 KB  |  391 lines

  1. @echo off
  2. rem     
  3. rem  CMEX.BAT - Batch file for building MATLAB V.4 MEX-files
  4. rem
  5. rem     Using:  Microsoft C/C++ V7.00           (DLL MEX-files)
  6. rem             Metaware High C/C++ V3.03       (REX MEX-files)
  7. rem             Watcom C V9.0                   (REX MEX-files)
  8. rem
  9. rem     USAGE:  cmex [source_files] [object_files] [libraries]
  10. rem
  11. rem             Mounil Patel  Setptember 30, 1992
  12. rem             Revised by: Marc Ullman   March 1, 1993
  13. rem             Copyright (C) 1992-1993 The MathWorks, Inc.
  14. rem             All Rights Reserved
  15.                 
  16. set ORIG_PATH=%PATH%
  17. if "%1"=="" goto USAGE
  18.  
  19. rem ********************************************************************
  20. rem Edit the following to reflect where you installed MATLAB
  21. rem ********************************************************************
  22. set MAT_ROOT=C:\MATLAB
  23.  
  24. rem ********************************************************************
  25. rem Set MEX_TYPE to one of the following:
  26. rem     DLLMEX  if using Microsoft C            (DLL MEX-files)
  27. rem     METMEX  if using Metaware High C        (REX MEX-files)
  28. rem     WATMEX  if using Watcom C               (REX MEX-files)
  29. rem
  30. rem     Make sure that you use all CAPITAL letters!
  31. rem ********************************************************************
  32. set MEX_TYPE=WATMEX
  33.  
  34. rem ********************************************************************
  35. rem Edit the following to reflect where you installed your compiler
  36. rem ********************************************************************
  37. set COMP_ROOT=C:\WATCOM
  38.  
  39. rem ********************************************************************
  40. rem Edit the following to reflect where you installed your Phar Lap
  41. rem linker if you are making REX MEX-Files with the METAWARE C Compiler
  42. rem ********************************************************************
  43. set PL_ROOT=C:\PHARLAP
  44.  
  45. rem ********************************************************************
  46. rem Edit the following to reflect where you installed your MS Windows
  47. rem SDK if you are making DLL MEX-Files
  48. rem ********************************************************************
  49. set SDK_ROOT=C:WINSDK
  50.  
  51.  
  52. rem Check to see if we're to make a stand-alone program for debugging
  53. rem and if we're compiling a V3.5 MEX-file
  54. set MEX_DBG=FALSE
  55. set DBG_OPT=
  56. set V35_FLAG=
  57. if "%1"=="-DEBUG" set MEX_DBG=TRUE
  58. if "%1"=="-debug" set MEX_DBG=TRUE
  59. if "%1"=="-V3.5" set V35_FLAG=-DOLDSTYLE
  60. if "%1"=="-v3.5" set V35_FLAG=-DOLDSTYLE
  61. if "%MEX_DBG%"=="TRUE" goto check_arg2
  62. if not "%V35_FLAG%"=="" goto check_arg2
  63. goto save_name 
  64. rem Do it all again so we can accept these options in either order
  65. :check_arg2
  66. if "%2"=="-DEBUG" set MEX_DBG=TRUE
  67. if "%2"=="-debug" set MEX_DBG=TRUE
  68. if "%2"=="-V3.5" set V35_FLAG=-DOLDSTYLE
  69. if "%2"=="-v3.5" set V35_FLAG=-DOLDSTYLE
  70. if "%MEX_DBG%"=="TRUE" shift
  71. if not "%V35_FLAG%"=="" shift     
  72.  
  73. :save_name
  74. rem Save the name of the first argument
  75. set MEXFILENAME=%1
  76.  
  77. if "%MEX_TYPE%"=="DLLMEX" goto CHECKDLL
  78. if "%MEX_TYPE%"=="METMEX" goto CHECKMET
  79. if "%MEX_TYPE%"=="WATMEX" goto CHECKWAT
  80.  
  81. echo    You must set MEX_TYPE to either DLLMEX, METMEX or WATMEX!
  82. echo    Make your corrections to cmex.bat and try again.
  83. goto EXIT
  84.  
  85. :CHECKDLL
  86. if not exist %COMP_ROOT%\bin\cl.exe goto SETUP1
  87. if not exist %COMP_ROOT%\bin\link.exe goto SETUP1
  88. if not exist %SDK_ROOT%\bin\rc.exe goto SETUP2
  89.  
  90. if not exist cmexdll.lnk goto COMPILE
  91. del cmexdll.lnk
  92. if not exist cmexdll.def goto COMPILE
  93. del cmexdll.def
  94.  
  95. goto COMPILE
  96.  
  97. :CHECKMET
  98. if not exist %COMP_ROOT%\bin\hc386.exe goto SETUP1
  99. if not exist %PL_ROOT%\bin\386link.exe goto SETUP3
  100.  
  101. set PATH=%COMP_ROOT%\bin
  102.  
  103. rem Create the link response file
  104. echo -twocase                            > hcmex.rsp
  105. echo -nomap                             >> hcmex.rsp
  106. if "%MEX_DBG%"=="TRUE" goto METEXE
  107. %MAT_ROOT%\bin\basename "-relexe %1"    >> hcmex.rsp
  108. echo .mex                               >> hcmex.rsp                      
  109. goto COMPILE
  110.  
  111. :METEXE
  112. %MAT_ROOT%\bin\basename "-exe %1"       >> hcmex.rsp
  113. echo .exe                               >> hcmex.rsp
  114. echo -attributes group CGROUP er        >> hcmex.rsp
  115. echo -attributes group DGROUP rw        >> hcmex.rsp
  116. echo -cvsymbols                         >> hcmex.rsp
  117. echo %PL_ROOT%\bin\stub386.exe          >> hcmex.rsp
  118. set DBG_OPT=-g
  119. goto COMPILE
  120.  
  121. :CHECKWAT
  122. if not exist %COMP_ROOT%\bin\wcc386.exe goto SETUP1
  123. if not exist %COMP_ROOT%\binb\wlink.exe goto SETUP1
  124.  
  125. rem Create the link response file
  126. echo option caseexact                            > wcmex.rsp
  127. %MAT_ROOT%\bin\basename "name %1"               >> wcmex.rsp
  128. if "%MEX_DBG%"=="TRUE" goto WATEXE
  129. echo .mex                                       >> wcmex.rsp                      
  130. echo format pharlap rex                         >> wcmex.rsp
  131. goto COMPILE
  132.  
  133. :WATEXE
  134. echo .exe                                       >> wcmex.rsp
  135. echo format os2 le                              >> wcmex.rsp
  136. echo debug all                                  >> wcmex.rsp
  137. echo option stub=%COMP_ROOT%\binb\wstub.exe     >> wcmex.rsp
  138. set DBG_OPT=-d2
  139. goto COMPILE
  140.  
  141. :COMPILE
  142.  
  143. if "%MEX_TYPE%"=="DLLMEX" goto PROC_DLL
  144. if "%MEX_TYPE%"=="METMEX" goto PROC_MET
  145. if "%MEX_TYPE%"=="WATMEX" goto PROC_WAT
  146.  
  147. :PROC_DLL
  148.  
  149. %MAT_ROOT%\bin\is_ext %1 .c
  150. if not errorlevel 1 goto COMPDLL
  151.  
  152. %MAT_ROOT%\bin\is_ext %1 .obj
  153. if not errorlevel 1 goto DLL_OBJ
  154.  
  155. %MAT_ROOT%\bin\is_ext %1 .lib
  156. if not errorlevel 1 goto DLL_LIBS
  157.  
  158. :COMPDLL
  159.  
  160. rem Set environment variable for INCLUDE
  161.  
  162. set INCLUDE=%SDK_ROOT%\include;%COMP_ROOT%\include;%MAT_ROOT%\extern\include
  163.  
  164. rem Compile the Mex file module
  165.  
  166. @echo on
  167. %COMP_ROOT%\bin\cl -c -ALw -Zip -FPi87 -G2D -Od -W3 -DDLLMEX %V35_FLAG% %1 
  168. @echo off
  169. if errorlevel 1 goto EXIT
  170.  
  171. :DLL_OBJ
  172. %MAT_ROOT%\bin\basename %1      >> cmexdll.lnk
  173. echo .obj +                     >> cmexdll.lnk
  174.  
  175. goto END_OF_LOOP
  176.  
  177. :PROC_MET
  178.  
  179. %MAT_ROOT%\bin\is_ext %1 .c
  180. if not errorlevel 1 goto COMPMET
  181.  
  182. %MAT_ROOT%\bin\is_ext %1 .obj
  183. if not errorlevel 1 goto MET_OBJ
  184.  
  185. %MAT_ROOT%\bin\is_ext %1 .lib
  186. if not errorlevel 1 goto MET_LIBS
  187.  
  188. :COMPMET
  189. @echo on
  190. %COMP_ROOT%\bin\hc386 -c -I%COMP_ROOT%\include -I%MAT_ROOT%\extern\include -f387 %1 %DBG_OPT% %V35_FLAG%
  191. @echo off
  192. if errorlevel 1 goto EXIT
  193.  
  194. :MET_OBJ
  195. %MAT_ROOT%\bin\basename %1      >> hcmex.rsp
  196. echo .obj                       >> hcmex.rsp
  197.  
  198. goto END_OF_LOOP
  199.  
  200. :PROC_WAT
  201.  
  202. %MAT_ROOT%\bin\is_ext %1 .c
  203. if not errorlevel 1 goto COMPWAT
  204.  
  205. %MAT_ROOT%\bin\is_ext %1 .obj
  206. if not errorlevel 1 goto WAT_OBJ
  207.  
  208. %MAT_ROOT%\bin\is_ext %1 .lib
  209. if not errorlevel 1 goto WAT_LIBS
  210.  
  211. :COMPWAT
  212. @echo on
  213. %COMP_ROOT%\bin\wcc386p -I%COMP_ROOT%\h -7 -3s -I%MAT_ROOT%\extern\include %1 %DBG_OPT% %V35_FLAG%
  214. @echo off
  215. if errorlevel 1 goto EXIT
  216.  
  217. :WAT_OBJ
  218. %MAT_ROOT%\bin\basename "file %1"       >> wcmex.rsp
  219. echo .obj                               >> wcmex.rsp
  220.  
  221. goto END_OF_LOOP
  222.  
  223. :END_OF_LOOP
  224. shift
  225. if not "%1" == "" goto COMPILE
  226. if not "%MEX_TYPE%"=="DLLMEX" goto LINK
  227.  
  228. :DLL_LIBS
  229. echo ,                                  >> cmexdll.lnk
  230. %MAT_ROOT%\bin\basename %MEXFILENAME%   >> cmexdll.lnk
  231. echo .dll                               >> cmexdll.lnk
  232. %MAT_ROOT%\bin\basename %MEXFILENAME%   >> cmexdll.lnk
  233. echo .map                               >> cmexdll.lnk
  234.  
  235. if "%1" == "" goto LINK
  236.  
  237. :DLL_LIB_LOOP
  238. %MAT_ROOT%\bin\is_ext %1 .lib
  239. if errorlevel 1 goto LIB_ERROR
  240. echo %1 +                               >> cmexdll.lnk
  241. shift
  242. if "%1" == "" goto LINK
  243. goto :DLL_LIB_LOOP
  244.  
  245. :MET_LIBS
  246. %MAT_ROOT%\bin\is_ext %1 .lib
  247. if errorlevel 1 goto LIB_ERROR
  248. echo -lib       >> hcmex.rsp          
  249. echo %1         >> hcmex.rsp
  250. shift
  251. if "%1" == "" goto LINK
  252. goto :MET_LIBS
  253.  
  254. :WAT_LIBS
  255. %MAT_ROOT%\bin\is_ext %1 .lib
  256. if errorlevel 1 goto LIB_ERROR
  257. echo library  %1  >> wcmex.rsp
  258. shift
  259. if "%1" == "" goto LINK
  260. goto :WAT_LIBS
  261.  
  262. :LINK
  263. if "%MEX_TYPE%"=="DLLMEX" goto LINKDLL
  264. if "%MEX_TYPE%"=="METMEX" goto LINKMET
  265. if "%MEX_TYPE%"=="WATMEX" goto LINKWAT
  266.  
  267. :LINKDLL
  268. rem Set enviroment variable for LIB
  269. set LIB=%SDK_ROOT%\lib;%COMP_ROOT%\lib
  270.  
  271. rem Create the module definition file
  272. %MAT_ROOT%\bin\basename "LIBRARY %MEXFILENAME%"  > cmexdll.def
  273. echo .dll                                       >> cmexdll.def
  274. echo EXETYPE   WINDOWS                          >> cmexdll.def
  275. echo STUB      '%COMP_ROOT%\BIN\WINSTUB.EXE'    >> cmexdll.def
  276. echo CODE      PRELOAD MOVEABLE DISCARDABLE     >> cmexdll.def
  277. echo DATA      PRELOAD MOVEABLE SINGLE          >> cmexdll.def
  278. echo HEAPSIZE  1024                             >> cmexdll.def  
  279. echo EXPORTS                                    >> cmexdll.def
  280. echo     WEP                @1 RESIDENTNAME     >> cmexdll.def
  281. echo     set_entry_point    @2                  >> cmexdll.def    
  282. echo     mexFunction            @3                  >> cmexdll.def 
  283. echo     mexAtExitFcn       @4                  >> cmexdll.def 
  284.  
  285. echo %MAT_ROOT%\extern\lib\libmexdl.lib +       >> cmexdll.lnk
  286. echo ldllcew.lib +                              >> cmexdll.lnk
  287. echo libw.lib                                   >> cmexdll.lnk
  288. echo cmexdll.def                                >> cmexdll.lnk
  289.  
  290. rem Link the Mex file
  291. rem
  292. @echo on
  293. %COMP_ROOT%\bin\link /align:32 /CO /NOD /NOE @cmexdll.lnk
  294. @echo off
  295. if errorlevel 1 goto EXIT
  296.  
  297. rem Resource compile the Mex file
  298. rem
  299. %MAT_ROOT%\bin\basename "%SDK_ROOT%\bin\rc %MEXFILENAME%" > cmexdll.bat
  300. echo .dll       >> cmexdll.bat
  301. call cmexdll.bat
  302.  
  303. rem Cleanup temporary files
  304. rem
  305. del cmexdll.lnk
  306. del cmexdll.def
  307. del cmexdll.bat
  308. goto EXIT
  309.  
  310. :LINKMET
  311.  
  312. rem Build remainder of link response file
  313.  
  314. set LIBNAME=libmexhc.lib
  315. if "%MEX_DBG%"=="TRUE" set LIBNAME=libdbghc.LIB
  316.  
  317. echo -lib                                       >> hcmex.rsp          
  318. echo %MAT_ROOT%\extern\lib\%LIBNAME%            >> hcmex.rsp
  319. echo %COMP_ROOT%\small\hc387.lib                >> hcmex.rsp
  320. echo %COMP_ROOT%\small\hc386.lib                >> hcmex.rsp
  321. echo %COMP_ROOT%\small\hcna.lib                 >> hcmex.rsp
  322.  
  323. @echo on
  324. %PL_ROOT%\bin\386link @hcmex.rsp
  325. @echo off
  326. del hcmex.rsp
  327. goto EXIT
  328.  
  329. :LINKWAT
  330.  
  331. rem Build remainder of link response file
  332.  
  333. if "%MEX_DBG%"=="TRUE" goto WAT_DBG
  334.  
  335. echo library %MAT_ROOT%\extern\lib\libmexwc.lib         >> wcmex.rsp
  336. echo library %COMP_ROOT%\lib386\math387s.lib            >> wcmex.rsp
  337. echo library %COMP_ROOT%\lib386\dos\clib3s.lib          >> wcmex.rsp
  338. goto DO_WAT_LINK
  339.  
  340. :WAT_DBG
  341. echo library %MAT_ROOT%\extern\lib\libdbgwc.lib         >> wcmex.rsp
  342. echo libpath %COMP_ROOT%\lib386                         >> wcmex.rsp
  343. echo libpath %COMP_ROOT%\lib386\dos                     >> wcmex.rsp
  344.  
  345. :DO_WAT_LINK
  346. @echo on
  347. %COMP_ROOT%\binb\wlink @wcmex.rsp
  348. @echo off
  349. del wcmex.rsp
  350. goto EXIT
  351.  
  352. :USAGE
  353. echo    Usage: cmex [source_files] [object_files] [libaries]
  354. goto EXIT
  355.  
  356. :LIB_ERROR
  357. echo    All libraries must be placed at the end of the cmex command line
  358. goto EXIT
  359.                                     
  360. :SETUP1
  361. echo    You must edit this batch file to set the environment variable COMP_ROOT
  362. echo    equal to the path where you installed your compiler before you can use 
  363. echo    it to create MEX files.
  364. goto EXIT
  365.  
  366. :SETUP2
  367. echo    You must edit this batch file to set the environment variable SDK_ROOT
  368. echo    equal to the path where you installed the Microsoft Windows SDK 3.x
  369. echo    before you can use it to create MEX files.
  370. goto EXIT
  371.  
  372. :SETUP3
  373. echo    You must edit this batch file to set the environment variable PL_ROOT
  374. echo    equal to the path where you installed the PharLap linker before you
  375. echo    can use it to create MEX files.
  376. goto EXIT
  377.  
  378. :EXIT
  379. set PATH=%ORIG_PATH%
  380. set ORIG_PATH=
  381. set MEX_TYPE=
  382. set MEX_DBG=
  383. set DBG_OPT=
  384. set MAT_ROOT=
  385. set COMP_ROOT=
  386. set PL_ROOT=
  387. set SDK_ROOT=
  388. set MEXFILENAME=
  389. set LIBNAME=
  390.  
  391.