I'm writing an application in C++ for a university assignment and I need to compress the source files in a zip file and email them to my supervisor for assessment. The problem is I have a 'toolbox' in a separate directory that contains a custom namespace that contains a lot of functions and classes I've found myself rewriting for every assignment, such as error/sanity checking a user's input.
Is there a tool that will create a compressed file containing all the source files that are stored in different locations? My compiler is able to follow the directories specified in my preamble, so I imagine there would be a tool out there that could to this. I'm writing this app on Linux, in C++, and would prefer a CLI开发者_如何学Python tool but will settle for a GUI if that's what there is.
There probably is, but the easiest thing to do is write a short script that copies everything into a temporary directory, then zips that directory.
The zip command takes multiple files as input. So you could do
zip project.zip my_project_dir my_toolbox_dir
If you want just source files, you can do
zip project.zip my_project_dir my_toolbpx_dir/*.cpp
You can use gcc
or cpp
in dependency mode. For example cpp -MM
produces Makefile rules for C files:
$ cpp -MM abstract.c
abstract.o: abstract.c differ.h overrides.h debug.h settings.h abstract.h \
abstract/posix.h abstract/linux.h misc.h command.h queue.h list.h \
storage.h sqlite3.h
You can parse this output to get a list of the included files. cpp
works fine with C++ source files, as well, so you should have no problems in that front.
You should take care to provide the same preprocessor options as when compiling normally, however.
EDIT:
Since zip
updates files with the same name within an archive, you could use something like this:
$ for i in *.c *.cc; do cpp -MM "$i"; done | tr ' ' '\n' | sort -u | grep -v ':$' | xargs -r zip test.zip
updating: test2.cc (deflated 61%)
adding: greater.c (deflated 38%)
adding: test.cc (deflated 61%)
adding: yyy.h (stored 0%)
adding: zzz.h (stored 0%)
$ for i in *.c *.cc; do cpp -MM "$i"; done | tr ' ' '\n' | sort -u | grep -v ':$' | xargs -r zip test.zip
updating: test2.cc (deflated 61%)
updating: greater.c (deflated 38%)
updating: test.cc (deflated 61%)
updating: yyy.h (stored 0%)
updating: zzz.h (stored 0%)
This stores the files that are included in the specified source files, along with the source files themselves, in a zip
archive. Note that you have to take care, so that each source file is processed with the correct cpp
options.
精彩评论