Skip to content

Instantly share code, notes, and snippets.

@arbalest
Created April 20, 2016 21:55
Show Gist options
  • Save arbalest/01c45e4a8c5d4780adc220c0667f9663 to your computer and use it in GitHub Desktop.
Save arbalest/01c45e4a8c5d4780adc220c0667f9663 to your computer and use it in GitHub Desktop.
Quick python script for compiling all .cpp files in a folder and subfolders with G++ (A simple, lazy makefile in Python)
# Recursively finds all .cpp files within the current directory,
# and compiles them, printing any messages generated by g++ and writing the
# output to the bin folder.
from pathlib import Path
import os
import subprocess
bin_path = 'bin/output'
file_list = [] # The list of .cpp files to be compiled
for a_file in Path('.').glob('**/*.cpp'):
file_list.append(str(a_file))
cpp_file_sep = ' '
command = 'g++ -I./ ' + cpp_file_sep.join(file_list) + ' -o ' + bin_path
print(subprocess.getoutput(command))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment