Sublime Text 2 project default file(s) for building - settings

I am a beginner user of Sublime Text 2, but I was trying to set up project specific default file(s) to build from. I'll explain myself:
When writing in LaTeX, I tend to separate the sections or chapters in different .tex files. When I build, I would like the main file to be the one passed to the compiler no matter what file has focus (a section/chapter .tex or the .log file or any other file for that matter).
Similarly, when writing C++ code, I would like to be able to specify a list of files to pass to the compiler.
Right now I am using a copy of the C++ build-system with *.cpp instead of the current file in the "cmd" line, but not always I want to build every cpp file in the folder. A similar modification on the LaTeX builder would be possible changing the file to build to something like main.tex and using main.tex for the main file every time.
Even though these are workarounds, I was wondering if there was a way of defining the default file(s) to the be passed to the compiler (or to a batch file if necessary) from the project specific files.

Related

How to compile a lex file on windows?

I have correctly downloaded and installed flex, bison and Dev C++ in C:\ . Then I tried to compile myfile.l in command prompt, but it gives the error:
flex: can't open myfile.l.
What is the problem?
I can see from your question that you are a beginner in need of some instruction, so what follows is in tutorial style. I hope you don't mind the tone. Many of my students encounter the same problem as you did when first starting.
The files containing the code for flex, bison or the compiler gcc (or g++) are just text files, and not some specially encoded form of file. They are only named something.l, something.y and something.c (or something.cpp) by convention. We could just call them something.txt or even something.l.txt if we wanted to. The reason they are named the way they are is to enable all the different components of one program to be distinguished without cluttering up the name space. So, if we have a project, such as some homework done in flex and bison, we can use the word homework as the base name and have the following file set:
homework.l <-- The lexer source file for flex created for the homework
homework.y <-- The parser source file for bison created for the homework
homework.cpp <-- The C++ source file for g++ created for the homework
homework.obj <-- The object file created by g++
homework.exe <-- The final windows executable created by g++
(There will be many other files as well, but I'll skip over that for now).
As the source files are just forms of a text file they can be created by a text editor. You indicated you are using Dev C++ which is an IDE (Integrated Development Environment) which combines a text editor, a compiler and a debugger into one package. The text editor part works just like any other text editor, such as Notepad, NotePad++, vim, emacs or one of the myriad of other editor tools.
Commonly, by default, a text editor tool on Windows will save a text file with the postfix language code of .txt. Here is an example dialogue of saving such a file:
You can see that if I saved my file, which I called SOlexer.l by pressing the Save button, I would get a file called SOlexer.l.txt because the default is to always make a file withe the suffix of .txt.
Now this does not need to be a problem. If I tried to invoke flex, as you did:
$ flex SOlexer.l
flex: can't open SOlexer.l
I would get the same error message. However I can just call flex with the actual file name used and it would work:
$ flex SOlexer.l.txt
$
Alternatively, I could rename the file, and then use it:
$ rename SOlexer.l.txt SOlexer.l
$ flex SOlexer.l
$
Problem solved!
However, as you have discovered, it is best to just create the file with the desired (and more convenient) name in the first place. To do this one has to just make a different selection from the menu when saving the file, like this:
If we click on All types (*.*) we can create the file without the .txt suffix. This should work for most similar tools also.
To help my students who had difficulty using flex and bison on Windows I made a series of video tutorials. You are welcome to use them also.
In conclusion, although you had trouble getting your flex file to build, your problem is nothing to do with flex or bison, but a simple beginners problem with learning how to create and edit files on a Windows system.

How to read a text file in NMAKE

I am new to scripting language.
I would like to read contents of a text file using NMAKE and display it. Text file contains only single line of data.
I have referred the following links, but its not working for me:
Can't figure out how to read file from nmake
Create a variable in a makefile by reading contents of another file
Here is the code snippet:
all :
.copy File1.txt
.copy File2.txt
.exec AddtnlInfo.bat #This batch file generates INFO.TXT file
#TODO - Read INFO.TXT file, display its contents and perform copy operation
Thanks,
Raja
To properly answer the question we really need to know more, such as when you want to display the contents of the file. A Makefile is not the same as writing in a scripting language - It does contain scripting language statements, but that is not the same as the purpose of a Makefile. A Makefile is to sequence the execution of statements written in another scripting language. The sequencing is to create files based on the dates and times of other files. Further Microsoft NMAKE is not the same as Make in various detailed ways (but in concept it is the same).
If the display of the contents of the file is linked to the creation of some file, then the answer is easy. If you want to display the text file every time the Makefile is executed then the solution might be very difficult. To just say Welcome to my Makefile from a file is harder than it seems. We have to know why you want to do this, so we can see if there is an alternate solution.
To display a text file is easy, as the commands in a an NMAKE script are Windows batch file commands. To display a file one uses the type filename command:
all:
echo The file contains:
type filename
But this is probably not what you want.
Your second link to another article is not useful as this is about generic Makefiles in a linux context and not about NMAKE on a Windows platform, and thus would be no help to you.

Making single executable includes all program file and folders with nsis?

I have zip file containing my installation files. I'm extracting this zip and copying these files into installation directory with the script shown below:
ZipDLL::extractall "$OUTDIR\demo.zip" "C:\myapp\demo\"
if I remove zip file from $OUTDIR than installer is not able to find zip file as expected. What I want to do is embedding this zip or its extracted folders into exe itself. I added
File -r "$OUTDIR/demo"
but this script didn't worked as well.
When you use the ZipDll plugin, you are referring to the file you want to process (demo.zip) by using its place at run time: along the installer.exe.
When you use the File statement to embed some files into the produced installer, you need to refer to the files by using their place at compile time.
Replace the $OUTDIR in the File statement by the path relative to the .nsi script.
BTW, you should take the habit to check at the compilation log, NSIS probably tells you about that kind of problem when paths are incorrect at compile-time.

How to have make build from one directory if the source file exists, otherwise build from another?

I'm working on modifying a huge recursive makefile project that has 6000+ source files. All of which are clearcase controlled. Since I don't want to copy the whole source tree, I'm trying to create a new project only containing the modified source files and thus pull the source from the original tree if they don't exist in my modified tree.
I have already modified the makefile in ModDir to check if each folder exists locally and execute make in that folder if it does. Otherwise it executes make in the sourceDir. My issue lies in the subdir makefiles.
Each subdir makefile contains a list of all of the source files needed for that module. I need to find a way to build the file locally if it exists, else build the file from SourceDir/subdir.
I.e. in my image, the Dir1 makefile needs to build F1 from ModDir/Dir1/F1, and build the other files from SourceDir/Dir1/F2-F3.
I tried to use VPATH to tell make to locate the source files in both locations (ModDir first of course) which works beautifully. However, since make assumes the object files are in the ModDir, it can't find any of the object files built in SourceDir.
I also tried making a pre-build rule to modify the make file list with bash, but I don't know if that's even possible.
How do I use make to build from one directory if the source file exists (ModDir), otherwise build from another (SourceDir)?
The easiest way will be to put your "if ... then ... else" logic in an external bash or batch (whichever OS you use) script and swap makefiles before calling make

How to force the build to be out of date, when a text file is modified?

The Scenario
My project has a post-build phase set up to run a batch file, which reads a text file "version.txt". The batch file uses the information in version.txt to inject the DLL with a version block using this tool.
The version.txt is included in my project to make it easy to modify. It looks a bit like this:
#set #Description="TankFace Utility Library"
#set #FileVersion="0.1.2.0"
#set #Comments=""
Basically the batch file renames this file to version.bat, calls it, then renames it back to version.txt afterwards.
The Problem
When I modify version.txt (e.g. to increment the file version), and then press F7, the build is not seen as out-of-date, so the post-build step is not executed, so the DLL's version doesn't get updated.
I really want to include the .txt file as an input to the build, but without anything actually trying to use it.
If I #include the .txt file from a CPP file in the project, the compiler fails because it obviously doesn't understand what "#set" means.
If I add /* ... */ comments around the #set commands, then the batch file has some syntax errors but eventually succeeds. But this is a poor solution I think.
So... how would you do it?
This works in VS2005. If you're not using that, some of the settings may be in different places or with different names.
Add the text file to your project, right click on it in the Solution Explorer and select 'Properties'. Under Configuration Properties > General make sure that the file is not excluded from the build. Under Custom Build Step > General, put your existing post-build command as the Command Line setting. Make sure you specify your .txt file as the output file. Now F7 should spot changes to the text file and run your batch file.
This may be too "hacky" but this might work:
Write a quick Perl (etc.) script to check version.txt has been updated.
If the file has been modified, have this script update a dummy source file that is compiled with your project.
Run the script as a pre-build event.
This way if the script sees that the file has changed, it will change the other one, which will force a re-build.
Hacky, but try it if you're scraping the bottom of the barrel.

Resources