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