You are a 42 network student and you are tired of typing your srcs manually ? This script will do it for you
- curl the script into a folder containing a Makefile with a line containing
$srcname
curl https://raw.githubusercontent.com/lorenuars19/makefile-src-updater/master/update_srcs.sh -o update_srcs.sh && chmod 775 update_srcs.sh
- curl this premade makefile
curl https://raw.githubusercontent.com/lorenuars19/makefile-template/master/Makefile -o Makefile
- run the script (it is interactive)
DO NOT REMOVE THE BACKUP FILE UNLESS YOU ARE SURE THAT YOU DON'T NEED IT ANYMORE, THIS SCRIPT REPLACES THE CONTENT OF YOUR FILE
I decline all responsibilities in case of any lose of any content.
Use these to tweak the script to your needs.
Variable | Usage |
---|---|
file='Makefile' | Makefile filename |
bkpfile='.'$file'.bkp.in.case.something.goes.wrong' | Backup filename |
SRCname='SRCS' | Pattern to look for in Makefile |
SRCdir='src' | Srcs directory name |
SRCfindptrn="**.c" | Find pattern |
HEADERname='HEADERS' | Pattern to look for |
HEADERdir='includes' | Headers directory name |
HEADERfindptrn="**.h" | Find pattern |
- Check
$file
exists and make a backup - Find the line containing the
$SRCname
withgrep
- Split the file into two files
$splitA
&$splitB
- Append result of find command within the
$SRCdir
matching$SRCfindptrn
- Append result of find command within the
$HEADERdir
matching$HEADERfindptrn
- Re-join the two splits into
$file
I am far from an expert in shell scripting, there's likely better ways to implement it. So feel free to pull request, to upgrade and improve this script.