LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Making a project distribution folder (https://www.linuxquestions.org/questions/programming-9/making-a-project-distribution-folder-816443/)

Mitchell314 06-25-2010 09:44 PM

Making a project distribution folder
 
(Newb question alert)

I'm trying to make my first c project (a simple tic tac toe console game), and I am wondering how to make a final product (copy all source code files to a distribution folder upon compilation). Should I use a bash script or should I use a makefile to make the distribution folder? I'm not terrible familiar with either; I have a basic makefile to make an executable, and that's about all I know of make.

And if I do use a bash script, how do I copy over source code files? I tried cp ./*.c and cp ./*.h, but I think the script read it literally as moving a file named ./*.c (and ./*.h), and couldn't find it.

My makefile is pretty much this:
Code:

objectFiles = main.o io.o board.o game.o

ttt : $(objectFiles)
        cc -o ttt $(objectFiles)


kbp 06-26-2010 01:24 AM

1 Attachment(s)
I wrote a script to do that exact thing, I like to keep things simple rather than use a full IDE ... rename to .sh

cheers

Attachment 3986

Mitchell314 06-26-2010 08:55 AM

Thanks for the script. Though, I already have an existing project with code, except the folder is cluttered with object files and editor backups. So I'm trying to copy all *.h and *.c files to a clean subdirectory (/distr), then zip it upon compiling. Though I don't know how to copy files just based on having a .c or .h. I can do it in the terminal no problem, cp ./*.c ./distr and cp ./*.h ./distr, but that same code wouldn't work in the script.

So pretty much, how do I copy source files in a shell script?


So far this is what I have (and it doesn't work):
Code:

#!/bin/bash

# Remove old source-distribution directory
if [ -e ./distr ]; then
  rm -r ./distr
fi

# Make a clean source-distribution directory
mkdir ./distr

# Move source code to distribution directory
cFiles=ls "./*.c"
for i in $cFiles; do
        cp $i ./distr
done

hFiles=ls "./*.h"
for i in $hFiles; do
        cp $i ./distr
done


ETA: Found out how to do that. Had to feed ls output to grep. Ye gads I'm horrible with shell scripting.

Code:

!/bin/bash

# Distribution folder name
distrFolder="./distr"

# Source code file extension expression (for grep)
extension="\.[ch]$"


# Remove old source-distribution directory
if [ -e "$distrFolder" ]; then
  rm -r "$distrFolder"
fi

# Make a clean source-distribution directory
mkdir "./$distrFolder"

# Get source code files from current directory
srcFiles=$(ls | grep "$extension")

# Move source code files to distribution directory
for file in $srcFiles; do
    cp "./$file" "$distrFolder"
done



All times are GMT -5. The time now is 12:02 AM.