Like Tree4Likes
  • 4 Post By anduril462

gcc question on converting files.

This is a discussion on gcc question on converting files. within the C Programming forums, part of the General Programming Boards category; For my next assignment we are learning how to incude different files in our directories. My professor gave us one ...

  1. #1
    Registered User
    Join Date
    Feb 2012
    Posts
    117

    gcc question on converting files.

    For my next assignment we are learning how to incude different files in our directories. My professor gave us one example file and said to modify it where need be. When I download the file off of the website it is in the form of "file". I'm thinking I need to get this in the form of .C or something so I can read the code inside. Not very good with gcc thoroughly.

    So my question is how do I change this file to where I can read what is inside it? Thanks

  2. #2
    Registered User
    Join Date
    Feb 2012
    Posts
    117
    better detail is that it's a "Makefile"

    I'm confused with what exactly this is for. I'm trying to see what the file actually consists of so I can understand this better

  3. #3
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,457
    Can you copy the fully assignment requirements, or post a link to the web site. I'm quite confused by your description.

    Also, post the contents of the make file here in code tags.

  4. #4
    Registered User
    Join Date
    Feb 2012
    Posts
    117
    Here is the full assignment

    http://omega.uta.edu/~darin/CSE1320/1320-hw10.pdf

    On the next page I'm going to link is the website where the Makefile is at. It's on the left hand side under homework 10.

    CSE 1320


    I'm not really understanding what the Makefile is. So I'm wondering how to read what's in it after I download it.
    Sorry that I can't be too clear on this.
    The first link has his directions concerning the Makefile towards the middle/bottom of the 2nd page.

    Thanks in advance

  5. #5
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,457
    A Makefile is just a text file that contains definitions and rules for building your programs. It's like source code for a special scripting language. They look a bit scary at first, but they're not too bad. Here's the makefile from your project:
    Code:
    # based on http://www.cs.colby.edu/maxwell/courses/tutorials/maketutor/
    # Sat Apr 14 11:01:20 CDT 2012
    
    CC=gcc 
    SRC=hw10-brezeale.c
    BINLIB=binary-lib.c
    DEPS=binary-lib.h
    
    # type 
    #   make
    # to build
    a.out: ${SRC} ${BINLIB} ${DEPS}
        ${CC} -std=c89 -pedantic ${SRC} ${BINLIB}
    
    # type 
    #   make clean
    # to remove a.out
    clean:
        rm a.out
    The lines that start with # are comments. A comment can start anywhere, on any line, and everything from the # to the end of the line is ignored, like a // comment in C/C++/Java (though your prof looks to make you use pedantic C89 rules for C, which doesn't support that style comment).


    • Those things are variables. Simply put, wherever you use $(VARIABLE) later on, it gets replaced by whatever is on the right side of the = sign.
    • Those things are called targets. They are the different things you can make. You can type "make a.out", or "make clean" from the command line. clean is a conventional name that gets rid of stuff created by the build process itself (i.e. it leaves your source code, but removes executables, temporary files, etc). If you type "make" without specifying a target, it uses the first one in the file, so "make" would be equivalent to "make a.out" in this case.
    • Those things are the commands to run when making the target. a.out runs $(CC) -std=c89 -pedantic $(SRC) $(BINLIB), which gets translated (by substituting the variable's values) to gcc -std=c89 -pedantic hw10-brezeale.c binary-lib.c as though you typed it from the command line yourself.
    • Those things are called dependencies. They are what are required when you make a target. Thus, a.out requires $(SRC), $(BINLIB) and $(DEPS). By "requires", it really checks when the file was modified. That is, any of the dependencies have a more recent timestamp than the target, Make will re-run the commands for the target, to bring the target "up to date" with your latest version of the source code. That is, if you do "make a.out", then go change something in binary-lib.c, and retype "make a.out", make will look at the dependencies for a.out. It will see that the binary-lib.c file is more recent than the a.out file, and re-run all the commands for that target. If you don't change binary-lib, make will tell you something like "target 'a.out' is up to date". Notice that clean has no dependencies. That means it always performs the commands, no matter what.


    The whole combination of target, dependencies and commands form a rule in Make terminology.

    Note, I used parentheses for the variables instead of curly braces because the forum software only lets you put curly braces inside code tags. However, Make allows you to use either form, and (AFAIK) they both behave the same way.

    Make is much more powerful and complex than just what you see, and what I explained. Where I used words like "always", "never", etc, there are most likely exceptions to many/all of those "absolutes", but they're not relevant here and will probably just confuse you right now, so I left them out.

    Now for the good part: it looks like all you have to do is change the definition of SRC, to match whatever files you use, i.e. hw10-LastnameFirstname.c for your last and first name.
    Last edited by anduril462; 04-19-2012 at 07:28 PM. Reason: typo

  6. #6
    Registered User
    Join Date
    Feb 2012
    Posts
    117
    Ok thanks a lot! I also was researching it some while I was waiting. Makes sense to me. Thanks for your in depth answer. Really helped out

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Converting RAW AVI files to compressed format
    By Zeeshan in forum Tech Board
    Replies: 0
    Last Post: 09-15-2009, 12:14 PM
  2. Converting xml to csv files....
    By manny in forum Tech Board
    Replies: 9
    Last Post: 09-03-2007, 09:47 AM
  3. converting audio and video files in C++
    By andy2885 in forum C++ Programming
    Replies: 2
    Last Post: 05-30-2006, 04:29 PM
  4. Converting blender files to .X
    By lightatdawn in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 06-28-2002, 01:54 PM
  5. Replies: 3
    Last Post: 05-03-2002, 05:18 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21