… with the hope that this post will make it into a how to:
General idea, and a good start -- one page read about FreeBSD and in particular leading to “Introduction to Programming”:
https://www.freebsd.org/doc/en_US.ISO8859-1/books/developers-handbook/tools-programming.html
However, a quick summary:
1. interpreters: BASIC, Lisp, Perl, Scheme, Icon, Logo, Python, Ruby, Tcl and Tk (sh, csh)
2. compilers: edit-compile-run-debug cycle -- expected as common procedures when coding
FreeBSD does not include an IDE in the base system, (but devel/kdevelop is available (favoritism))
Using Emacs as an IDE is discussed in Section 2.7, “Using Emacs as a Development Environment”.
AHR opinion is that any form of IDE requires additional knowledge and as such many quit before touching C language. Nevertheless, ambiguity is created even for those with some experience but new to FreeBSD.
...
Compiling with cc
https://www.freebsd.org/doc/en_US.ISO8859-1/books/developers-handbook/tools-compiling.html
Although this section was the question in my post but not enough to figure things out:
https://forums.freebsd.org/threads/55776/
...
1. Make -- make reads in a file, called a makefile
2. Makefiles are
typically kept in the same directory as the source they apply to
3. Standards: Most programmers use the name Makefile (note uppercase M -- aka Title case)
REM: mkdir /path/home/code; ee /path/home/code/Makefile
*** Standards: /usr/ports/category/portname
Note: I used ee in the example but Nano, Vim or any other text editor can be employed to create the file/s.
- Makefile contains dependencies and commands:
- The dependency line in this example consists of the name of the program (known as the target)
Simple content of Makefile (consists of two lines, a dependency line and a creation line)
Code:
foo: foo.c
cc -o foo foo.c
Syntax of dependency line is:
foo: (is the name of the program/code aka “the target” (you execute this file))
foo.c (is the raw code file (you write this file))
REM: target followed by colons, and by whitespace, then C lang. code file
Syntax of creation line is: (command)
cc (is the compiler used (but you may call gcc))
-o (switch used for CC)
foo (is the dependency (exe))
foo.c (is the code to be compiled)
REM: command line starts with a TAB (5 characters exact -- I guess, “make” will not know otherwise how to interpret the cmd line)
…
Create the raw C programing with any editor
ee foo.c
…
Compile the raw code
make foo
…
Execute the code
./foo
*** The install: part is not covered as it is not the purpose of this tutorial. However, install is the easier part.
Practical step by step example:
1. create a location for your project and cd into it
mkdir /xample
cd /xample
2. create the Makefile for such project
ee Makefile
Code:
# mine looks like this and the target is "welcome"
echo "welcome: welcome.c" > Makefile && \
printf "\tcc -o welcome welcome.c" >> Makefile && \
echo ""; echo ""; && \
cat Makefile
3. Create the raw C program "welcome.c"
ee welcome.c
Code:
# mine looks like this
echo "#include <stdio.h>" > welcome.c && \
echo "" >> welcome.c && \
echo "int main(void) {" >> welcome.c && \
printf '\tprintf("Welcome to C programming!\\n");\n\treturn 0;\n}\n' >> welcome.c && \
echo ""; echo ""; && \
cat welcome.c
4. compile the raw code "welcome" (make target)
make welcome
5. Execute the program/code
./welcome