Skip to content

Instantly share code, notes, and snippets.

@fstanley
Last active December 17, 2015 13:59
Show Gist options
  • Save fstanley/5621593 to your computer and use it in GitHub Desktop.
Save fstanley/5621593 to your computer and use it in GitHub Desktop.
Create a NetBurner command line makefile in powershell. Call from the folder you wish to build a makefile in.
# Author: Forrest Stanley <[email protected]>
#
# This script generates a makefile in the current folder. It automatically adds
# required cpp files and html files/folder.
#
# Usage nb_makefileBuilder
# -Platform [PLATFORM] - optional. Adds Platform = PLATFORM to makefile
#
#
param(
[Parameter(
Mandatory = $false,
Position = 0)]
[string]$Platform
)
$dateYear = Get-Date -Format yyyy
$copyrightText = @"
# Copyright 1998-$dateYear NetBurner, Inc. ALL RIGHTS RESERVED
# Permission is hereby granted to purchasers of NetBurner Hardware
# to use or modify this computer program for any use as long as the
# resultant program is only executed on NetBurner provided hardware.
#
# No other rights to use this program or it's derivitives in part or
# in whole are granted.
#
# It may be possible to license this or other NetBurner software for
# use on non NetBurner Hardware. Please contact [email protected]
# for more information.
#
# NetBurner makes no representation or warranties with respect to the
# performance of this computer program, and specifically disclaims any
# responsibility for any damages, special or consequential, connected
# with the use of this program.
#
# NetBurner, Inc
# http://www.netburner.com
"@
# Adding Copyright Text
$makefile = $copyrightText
# Setting the Name of your makefile to be the directory name you are in
$path = (Get-Location).Path
$myIndex = $path.LastIndexOf("\") + 1
$AppName = $path.Substring($myIndex)
$makefile += "NAME = $AppName`r`n"
if ($Platform -ne "") {
$makefile += "PLATFORM = $Platform`r`n"
}
$makefile += "`r`n"
# Adding c++ source files
dir *.cpp -recurse | ForEach-Object -begin { $makefile += "CXXSRCS = \`r`n" } `
-process { `
if (($_).Name -ne "htmldata.cpp") { `
$makefile += "`t" + ($_).Name + " \`r`n" `
} `
} `
-end { $makefile += "`r`n" }
# Adding C Source files
dir *.c -recurse | ForEach-Object -begin { $makefile += "CSRCS = \`r`n" } `
-process { $makefile += "`t" + ($_).Name + " \`r`n" } `
-end { $makefile += "`r`n" }
# Adding htmldata.cpp to the build list if an html directory exists
if (Test-Path html) { $makefile += @"
CXXSRCS += htmldata.cpp
CREATEDTARGS = htmldata.cpp
"@ }
# Adding includes to the nburn make system
$makefile += "include `$(NBROOT)/make/main.mak`r`n`r`n"
# Add special rule to build html, if we find an html folder
if (Test-Path html) { $makefile += @"
htmldata.cpp : `$(wildcard html/*.*)
comphtml html -ohtmldata.cpp
"@ }
$makefile += "`r`n`r`n"
# Output the generated makefile to the local directory as makefile
$makefile | Out-File -Encoding ascii -FilePath makefile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment